Exemple #1
0
        protected override async Task ExecuteAsync(CancellationToken appStoppingToken)
        {
            // Exactly the same as TestJobMonitoring except the job is JobFac-aware and needs a payload

            try
            {
                Console.WriteLine("Getting job factory proxy.");
                var factory = jobFacServices.GetJobFactory();

                var options = new FactoryStartOptions
                {
                    DefinitionId = "Sample.JobFac.aware"
                                   // we could add the payload here but it's easier to use the StartJob overload
                                   // since FactoryStartOptions stores alternate argument lists and startup
                                   // payloads in a dictionary (which is useful for multi-job sequences)
                };

                string payload = "35,Hello world!";

                Console.WriteLine($"Starting sample job Sample.JobFac.aware with payload: {payload}");
                var jobKey = await factory.StartJob(options, startupPayload : payload);

                // Everything below is identical to TestJobMonitoring
                Console.WriteLine($"Job instance key: {jobKey}");

                var  timeout            = DateTimeOffset.UtcNow.AddSeconds(90);
                bool done               = false;
                IJobExternalProcess job = null;
                while (!done && DateTimeOffset.UtcNow < timeout)
                {
                    appStoppingToken.ThrowIfCancellationRequested();
                    Console.WriteLine("Pausing 10 seconds then reading status.");
                    await Task.Delay(10000);

                    if (job == null)
                    {
                        job = jobFacServices.GetExternalProcessJob(jobKey);
                    }
                    if (job == null)
                    {
                        Console.WriteLine("Failed to obtain job proxy.");
                        done = true;
                        break;
                    }

                    var status = await job.GetStatus();

                    Console.WriteLine($"Status {status.RunStatus} last updated {status.LastUpdated.ToLocalTime()}");
                    done = status.HasExited;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\n\nException:\n{ex}");
            }
            finally
            {
                appLifetime.StopApplication();
            }
        }
Exemple #2
0
        // TODO respond to appStoppingToken cancellation
        protected override async Task ExecuteAsync(CancellationToken appStoppingToken)
        {
            IJobExternalProcess jobService = null;

            try
            {
                logger.LogTrace($"Runner starting, job instance {Program.JobInstanceKey}");
                jobService = jobFacServices.GetExternalProcessJob(Program.JobInstanceKey);
                if (jobService == null)
                {
                    logger.LogError("Runner was unable to obtain a reference to the Job service");
                    return;
                }

                await jobService.UpdateRunStatus(RunStatus.StartRequested);

                var jobDef = await jobService.GetDefinition();
                await RunJob(jobService, jobDef);
            }
            catch (Exception ex)
            {
                logger.LogError($"ExecuteAsync {ex}");
                await jobService.UpdateExitMessage(RunStatus.Unknown, -1, $"JobFac.Services.Runner exception {ex}");
            }
            finally
            {
                logger.LogInformation($"Runner ending, calling StopApplication after log-flush delay");
                await Task.Delay(10000);

                appLifetime.StopApplication();
            }
        }
Exemple #3
0
        protected override async Task ExecuteAsync(CancellationToken appStoppingToken)
        {
            // Exactly the same as TestJobPayload except the job isn't JobFac-aware

            try
            {
                Console.WriteLine("Getting job factory proxy.");
                var factory = jobFacServices.GetJobFactory();

                var options = new FactoryStartOptions
                {
                    DefinitionId = "Sample.JobFac.unaware"
                };

                Console.WriteLine("Starting sample job: Sample.JobFac.unaware");
                var jobKey = await factory.StartJob(options);

                Console.WriteLine($"Job instance key: {jobKey}");

                var  timeout            = DateTimeOffset.UtcNow.AddSeconds(90);
                bool done               = false;
                IJobExternalProcess job = null;
                while (!done && DateTimeOffset.UtcNow < timeout)
                {
                    appStoppingToken.ThrowIfCancellationRequested();
                    Console.WriteLine("Pausing 10 seconds then reading status.");
                    await Task.Delay(10000);

                    if (job == null)
                    {
                        job = jobFacServices.GetExternalProcessJob(jobKey);
                    }
                    if (job == null)
                    {
                        Console.WriteLine("Failed to obtain job proxy.");
                        done = true;
                        break;
                    }

                    var status = await job.GetStatus();

                    Console.WriteLine($"Status {status.RunStatus} last updated {status.LastUpdated.ToLocalTime()}");
                    done = status.HasExited;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\n\nException:\n{ex}");
            }
            finally
            {
                appLifetime.StopApplication();
            }
        }
Exemple #4
0
        protected override async Task ExecuteAsync(CancellationToken appStoppingToken)
        {
            try
            {
                Console.WriteLine("Getting job factory proxy.");
                var factory = jobFacServices.GetJobFactory();

                var options = new FactoryStartOptions
                {
                    DefinitionId = "Sample.JobFac.unaware"
                };

                Console.WriteLine("Starting sample job: Sample.JobFac.unaware");
                var jobKey = await factory.StartJob(options);

                Console.WriteLine($"Job instance key: {jobKey}");

                Console.WriteLine("Waiting 15 seconds then will kill job.");
                await Task.Delay(15000);

                var job = jobFacServices.GetExternalProcessJob(jobKey);
                if (job != null)
                {
                    var status = await job.GetStatus();

                    Console.WriteLine($"Status {status.RunStatus} last updated {status.LastUpdated.ToLocalTime()}");
                    Console.WriteLine("Killing job then sleeping for 5 seconds.");
                    await job.Stop();

                    await Task.Delay(5000);

                    status = await job.GetStatus();

                    Console.WriteLine($"Status {status.RunStatus} last updated {status.LastUpdated.ToLocalTime()}");
                }
                else
                {
                    Console.WriteLine("Failed to obtain job proxy.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\n\nException:\n{ex}");
            }
            finally
            {
                appLifetime.StopApplication();
            }
        }