Esempio n. 1
0
        public async Task <string> CreateNewJobOrUpdateDefinition <TJobStep>(string tenantId,
                                                                             string jobDisplayName = null, string jobId = null, JobConfigurationData configuration = null)
            where TJobStep : IJobStep
        {
            if (string.IsNullOrWhiteSpace(jobId))
            {
                jobId = Base32Url.ToBase32String(Guid.NewGuid().ToByteArray());
            }
            configuration = configuration ?? new JobConfigurationData();

            ValidateAndFixConfiguration(configuration);

            var job = new JobData
            {
                JobId          = jobId,
                TenantId       = tenantId,
                JobDisplayName = jobDisplayName ?? typeof(TJobStep).Name,
                JobStepType    = typeof(TJobStep).AssemblyQualifiedName,
                CreationTime   = DateTime.UtcNow,
                CreatedBy      = "unknown",
                Configuration  = configuration,
                Status         = new JobStatusData
                {
                    State     = JobState.Initializing,
                    StateTime = DateTime.UtcNow,
                    LastIterationStartTime       = DateTime.UtcNow,
                    LastDequeueAttemptTime       = DateTime.UtcNow,
                    LastProcessStartTime         = DateTime.UtcNow,
                    LastProcessFinishTime        = DateTime.UtcNow,
                    LastHealthCheckTime          = DateTime.UtcNow,
                    ItemsProcessed               = 0,
                    ItemsRequeued                = 0,
                    ItemsGeneratedForTargetQueue = 0,
                    EstimatedTotalItems          = -1,
                    ProcessingTimeTakenMillis    = 0,
                    ItemsFailed       = 0,
                    LastFailTime      = null,
                    LastFailures      = new JobStatusErrorData[0],
                    ExceptionCount    = 0,
                    LastExceptionTime = null,
                    LastExceptions    = new JobStatusErrorData[0]
                }
            };

            await JobStore.AddOrUpdateDefinition(job);

            var queue = Composer.GetComponent <IJobQueue <TJobStep> >(job.Configuration.QueueTypeName);

            if (queue == null)
            {
                throw new CompositionException("JobQueue should be registered");
            }

            await queue.EnsureJobQueueExists(jobId);

            return(jobId);
        }