Ejemplo n.º 1
0
        public void ToJobDb()
        {
            var job = new JobMetadata()
            {
                JobType  = typeof(TestJob),
                JobParam = "test"
            };

            var jobDb = JobDb.CreatedJobDb(job, new JsonSerializerSettings());

            Assert.Equal(jobDb.JobType, _strJobType);
            Assert.Equal(jobDb.JobParamType, _strJobParamType);
            Assert.Equal(jobDb.JobParam, _strJobParam);
        }
Ejemplo n.º 2
0
        private async Task ExecuteJob(JobMetadata jobMetadata)
        {
            dynamic jobImplementation = null;

            try
            {
                using (var scope = _settings.JobScopeFactory.Create())
                {
                    try
                    {
                        jobImplementation = scope.CreateJob(jobMetadata.JobType);
                    }
                    catch (Exception ex)
                    {
                        //Дополнительное логирование ошибки, когда джоб не может быть создан
                        _settings.Logger.Error($"Ошибка создания джоба {jobMetadata.JobType}", ex);
                        throw;
                    }

                    _settings.Logger.Debug("got jobImplementation -" + jobImplementation.GetType());
                    _settings.Logger.Debug("got JobParam -" + jobMetadata.JobParam.GetType());
                    await jobImplementation.Execute((dynamic)jobMetadata.JobParam);

                    _settings.Logger.Debug("jobMetadata excecuted");

                    if (jobMetadata.NextJob != null)
                    {
                        jobMetadata.NextJob.StartAt = DateTime.UtcNow + jobMetadata.NextJob.Delay.GetValueOrDefault();

                        await _jobRepository.AddJob(JobDb.CreatedJobDb(jobMetadata.NextJob,
                                                                       _settings.JsonSerializerSettings));

                        _settings.Logger.Debug("next jobMetadata added");
                    }

                    await _jobRepository.RemoveJob(jobMetadata.JobId);

                    _settings.Logger.Debug("jobMetadata saved success");
                }
            }
            catch (Exception ex)
            {
                await HandleFailed(jobMetadata, ex, jobImplementation);
            }
        }
Ejemplo n.º 3
0
        public async Task AddRecurrentJob(JobMetadata jobMetadata)
        {
            await _recurrentJobSettingsAdder.Add(jobMetadata.Cron, jobMetadata.JobType, jobMetadata.JobKey);

            await _jobRepository.AddRecurrentJob(JobDb.CreatedJobDb(jobMetadata, _jsonSerializerSettings));
        }
Ejemplo n.º 4
0
        public Task AddEnqueueJob(JobMetadata jobMetadata)
        {
            var job = JobDb.CreatedJobDb(jobMetadata, _jsonSerializerSettings);

            return(_jobRepository.AddJob(job));
        }