public async Task Handle(JobRunnerStateMachine jobRunnerStateMachine)
        {
            Console.WriteLine($"Problem encountered: '{_failureReason}'");

            await Task.Delay(RetryDelayMs);

            jobRunnerStateMachine.State = new RegistrationState();
        }
Beispiel #2
0
        public async Task Handle(JobRunnerStateMachine jobRunnerStateMachine)
        {
            foreach (var job in _jobs)
            {
                switch (job.JobName)
                {
                case "Count":
                    _ = Task.Run(() => new CountJobRunner(job).Run());
                    break;

                default:
                    _ = Task.Run(() => new JobRunnerBase(job).FailJob($"No job named {job.JobName}"));
                    return;
                }
            }

            jobRunnerStateMachine.State = new GetJobsState();
        }
Beispiel #3
0
        public async Task Handle(JobRunnerStateMachine jobRunnerStateMachine)
        {
            Console.WriteLine("Getting jobs");

            _jobRunnerStateMachine = jobRunnerStateMachine;
            try
            {
                var getJobAddressSuffix = Consts.GetJobAddressSuffix.Replace("WORKER_ID", jobRunnerStateMachine.WorkerId.ToString());
                var requestUri          = $"{Program.UrlBase}{getJobAddressSuffix}";
                using (var client = new HttpClient())
                    using (var response = await client.GetAsync(requestUri))
                    {
                        await HandleResponse(response);
                    }
            }
            catch (Exception e)
            {
                jobRunnerStateMachine.State = new FailedState(e.Message);
            }
        }
        public async Task Handle(JobRunnerStateMachine jobRunnerStateMachine)
        {
            try
            {
                switch (_job.JobName)
                {
                case "Count":
                    await new CountJobRunner(_job).Run();
                    break;

                default:
                    await new JobRunnerBase(_job).FailJob($"No job named {_job.JobName}");
                    return;
                }
            }
            catch (Exception e)
            {
                await new JobRunnerBase(_job).FailJob(e.Message);
            }

            jobRunnerStateMachine.State = new GetJobsState();
        }
Beispiel #5
0
        public async Task Handle(JobRunnerStateMachine jobRunnerStateMachine)
        {
            Console.WriteLine("Registering worker");

            _jobRunnerStateMachine = jobRunnerStateMachine;
            try
            {
                var requestUri = $"{Program.UrlBase}{Consts.RegisterAddressSuffix}";
                using (var client = new HttpClient())
                    using (var response = await client.PostAsync(requestUri, new StringContent(
                                                                     JsonConvert.SerializeObject(new RegistrationModel()),
                                                                     Encoding.UTF8,
                                                                     "application/json")))
                    {
                        await HandleResponse(response);
                    }
            }
            catch (Exception e)
            {
                jobRunnerStateMachine.State = new FailedState(e.Message);
            }
        }