Example #1
0
        /// <summary>
        /// See <see cref="MiniBatchProcessorClient.Submit(Job)"/>.
        /// </summary>
        public override object Submit(Job myJob)
        {
            string FullName    = GetFullJobName(myJob);
            var    AllProblems = FilterJobData(myJob);
            //if (AllProblems.Length > 0) {
            //    throw new ApplicationException("There are already " + AllProblems.Length + " jobs with the name '" + FullName + "' in the MiniBatchProcessor. Since the job name must be unique, we cannot submit - try another project name.");
            //}

            var JD = new MiniBatchProcessor.JobData()
            {
                Name      = FullName,
                NoOfProcs = myJob.NumberOfMPIProcs,
                ExeDir    = myJob.DeploymentDirectory,
                exefile   = Path.GetFileName(myJob.EntryAssembly.Location),
                Arguments = myJob.CommandLineArguments,
                EnvVars   = myJob.EnvironmentVars.Select(kv => new Tuple <string, string>(kv.Key, kv.Value)).ToArray()
            };

            int id = MiniBatchProcessor.Client.SubmitJob(JD);

            return(id);
        }
        /// <summary>
        /// See <see cref="BatchProcessorClient.EvaluateStatus(Job, out int, out bool, out bool, out bool, out string)"/>.
        /// </summary>
        public override void EvaluateStatus(Job myJob, out int SubmitCount, out bool isRunning, out bool wasSuccessful, out bool isFailed, out string DeployDir)
        {
            if (!object.ReferenceEquals(this, myJob.AssignedBatchProc))
            {
                throw new ArgumentException("Why you ask me?");
            }
            string FullName = GetFullJobName(myJob);

            MiniBatchProcessor.JobData[] AllProblems = FilterJobData(myJob);
            MiniBatchProcessor.JobData   JD          = null;
            if (AllProblems.Length > 0)
            {
                if (myJob.BatchProcessorIdentifierToken == null)
                {
                    JD = AllProblems.ElementAtMax(jd => jd.SubmitTime);
                }
                else
                {
                    int idSearch = (int)(myJob.BatchProcessorIdentifierToken);
                    JD = AllProblems.SingleOrDefault(jobDat => jobDat.ID == idSearch);
                }
            }
            SubmitCount = AllProblems.Length;
            if (AllProblems.Length <= 0 || JD == null)
            {
                // we know nothing
                isRunning     = false;
                isFailed      = false;
                wasSuccessful = false;
                DeployDir     = null;
                return;
            }

            int ExitCode;
            var mbpStatus = MiniBatchProcessor.ClientAndServer.GetStatusFromID(JD.ID, out ExitCode);

            DeployDir = JD.ExeDir;

            switch (mbpStatus)
            {
            case MiniBatchProcessor.JobStatus.Queued:
                // we know nothing
                isRunning     = false;
                isFailed      = false;
                wasSuccessful = false;
                return;

            case MiniBatchProcessor.JobStatus.Finished:
                // we know nothing
                isRunning     = false;
                wasSuccessful = (ExitCode == 0);
                isFailed      = !wasSuccessful;
                return;

            case MiniBatchProcessor.JobStatus.Working:
                // we know nothing
                isRunning     = true;
                isFailed      = false;
                wasSuccessful = false;
                return;

            case MiniBatchProcessor.JobStatus.Undefined:
                // we know nothing
                isRunning     = false;
                isFailed      = false;
                wasSuccessful = false;
                return;

            default:
                throw new NotImplementedException();
            }
        }