Example #1
0
        /// <summary>
        /// Activates the job; can only be called once in this objects lifetime.
        /// </summary>
        /// <remarks>
        /// The job is submitted to the batch processor if no
        /// By using a unique name, see <see cref="Name"/>, the job becomes persistent: e.g., assume
        /// that this method is called within a worksheet. Later, the worksheet is restarted, or closed and reopened,
        /// thus this method is called a second time. By identifying the job in the batch processor with a unique name and
        /// by tagging sessions with the job name, it is ensured that the job is _not_ submitted a second time,
        /// resp. every time the worksheet is restarted.
        /// </remarks>
        public void Activate(BatchProcessorClient bpc)
        {
            // ============================================
            // ensure that this method is only called once.
            // ============================================
            if (this.AssignedBatchProc != null)
            {
                throw new NotSupportedException("Job can only be activated once.");
            }
            AssignedBatchProc = bpc;

            if (this.Name == "J2560_k2_exp_softpcg_mg")
            {
                Console.WriteLine();
            }

            // ================
            // check job status
            // ================
            string DeployDir;
            int    SubmitCount;
            var    status = GetStatus(out SubmitCount, out DeployDir);

            this.DeploymentDirectory = DeployDir;

            // ==============
            // check Database
            // ==============
            var RR = this.AllSessions;

            // =================
            // decide what to do
            // =================
            switch (status)
            {
            case JobStatus.PreActivation:
                DeployDir = null;
                this.DeploymentDirectory = null;
                Console.WriteLine("Job not submitted yet, or no result session is known - starting submission.");
                break;

            case JobStatus.Failed:
                if (RR.Length <= 0)
                {
                    DeployDir = null;
                    this.DeploymentDirectory = null;
                    Console.WriteLine("Job is marked as failed by job manager, no database entry is found; performing new deployment and submission.");
                    break;
                }
                if (RetryCount <= SubmitCount)
                {
                    Console.WriteLine("Job is failed {0} times, maximum number of tries reached, no further action.", SubmitCount);
                    return;
                }
                else
                {
                    DeployDir = null;
                    this.DeploymentDirectory = null;
                    Console.WriteLine("Job is failed, retrying (Submitted {0} times so far); performing new deployment and submission.", SubmitCount);
                    break;
                }

            case JobStatus.PendingInExecutionQueue:
                Console.WriteLine("Job submitted, waiting for launch - no further action.");
                return;

            case JobStatus.FinishedSuccessful:
                if (RR.Length <= 0)
                {
                    DeployDir = null;
                    this.DeploymentDirectory = null;
                    Console.WriteLine("Job is marked as success by job manager, but no session info in database is found; performing new deployment and submission.");
                    break;
                }
                ISessionInfo LatestSession = RR.OrderBy(sinf => sinf.CreationTime).Last();
                Console.WriteLine("Job was successful (according to job manager), latest session related to job is:");
                Console.WriteLine(LatestSession.ToString());
                Console.WriteLine("No further action.");
                return;

            case JobStatus.InProgress:
                Console.Write("Job has been started (according to job manager), ");
                if (RR.Length > 0)
                {
                    Console.WriteLine("latest known session is:");
                    ISessionInfo LatestSession2 = RR.OrderBy(sinf => sinf.CreationTime).Last();
                    Console.WriteLine(LatestSession2.ToString());
                }
                else
                {
                    Console.WriteLine("no session information available at this point.");
                }
                Console.WriteLine("No further action.");
                return;

            default:
                throw new NotImplementedException();
            }


            // ========================================================================
            // finally, it might be necessary to submit the job to the batch processor.
            // ========================================================================

            // deploy executables:
            bool RequiresDeploy = false;

            if (DeployDir == null)
            {
                if (!Directory.Exists(this.DeploymentDirectory) ||
                    !File.Exists(Path.Combine(DeployDir, Path.GetFileName(this.EntryAssembly.Location))))
                {
                    RequiresDeploy = true;
                }
            }
            else
            {
                RequiresDeploy = false;
            }


            if (RequiresDeploy)
            {
                this.DeploymentDirectory = bpc.GetNewDeploymentDir(this);
                bpc.DeployExecuteables(this, AdditionalDeploymentFiles);
            }

            // submit job
            this.BatchProcessorIdentifierToken = bpc.Submit(this);
        }
Example #2
0
 /// <summary>
 /// See <see cref="SessionInfo.ToString"/>
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(RealSessionInfo.ToString());
 }