Пример #1
0
        public HttpOutgoingQueueProcessorTests()
        {
            MockLogger    = new Mock <ILogger <HttpPushOutgoingQueueProcessor> >();
            MockMessageDa = new Mock <IMessageLogDa>();
            NebulaContext = new NebulaContext();
            NebulaContext.RegisterJobQueue(typeof(MockDelayedQueue), QueueType.Delayed);
            Interlocked.Increment(ref _portNumber);
            var baseAddress = $"http://localhost:{_portNumber}";

            Parameters = new HttpPushOutgoingQueueParameters
            {
                TargetUrl = $"{baseAddress}/endpoint"
            };
            StubHttp         = HttpMockRepository.At(baseAddress);
            JobConfiguration = new JobConfigurationData
            {
                MaxBatchSize = 1,
                MaxConcurrentBatchesPerWorker = 5,
                IdleSecondsToCompletion       = 30,
                MaxBlockedSecondsPerCycle     = 60,
                MaxTargetQueueLength          = 100000,
                QueueTypeName = QueueType.Redis,
                Parameters    = JsonConvert.SerializeObject(Parameters)
            };

            JobData = new JobData
            {
                JobId         = "test_job_id",
                Configuration = JobConfiguration,
                TenantId      = TenantId
            };
        }
Пример #2
0
        private void ValidateAndFixConfiguration(JobConfigurationData configuration)
        {
            configuration.MaxBatchSize = Math.Max(1, Math.Min(1000, configuration.MaxBatchSize));
            configuration.MaxConcurrentBatchesPerWorker =
                Math.Max(1, Math.Min(10000, configuration.MaxConcurrentBatchesPerWorker));

            if (configuration.ThrottledItemsPerSecond.HasValue && configuration.ThrottledItemsPerSecond <= 0d)
            {
                throw new ArgumentException("Throttle speed cannot be zero or negative");
            }
            if (configuration.ThrottledItemsPerSecond.HasValue)
            {
                configuration.ThrottledItemsPerSecond = Math.Max(0.001d, configuration.ThrottledItemsPerSecond.Value);
            }

            if (configuration.ThrottledMaxBurstSize.HasValue && configuration.ThrottledMaxBurstSize <= 0)
            {
                throw new ArgumentException("Throttle burst size cannot be zero or negative");
            }
            if (configuration.ThrottledMaxBurstSize.HasValue)
            {
                configuration.ThrottledMaxBurstSize = Math.Max(1, configuration.ThrottledMaxBurstSize.Value);
            }

            if (configuration.ExpiresAt.HasValue && configuration.ExpiresAt < DateTime.Now)
            {
                throw new ArgumentException("Job is already expired and cannot be added");
            }

            if (configuration.QueueTypeName == null)
            {
                throw new ArgumentException("QueueTypeName must be specified in job configuration");
            }

            if (configuration.IdleSecondsToCompletion.HasValue)
            {
                configuration.IdleSecondsToCompletion = Math.Max(10, configuration.IdleSecondsToCompletion.Value);
            }

            if (configuration.MaxBlockedSecondsPerCycle.HasValue)
            {
                configuration.MaxBlockedSecondsPerCycle = Math.Max(30, configuration.MaxBlockedSecondsPerCycle.Value);
            }

            if (configuration.MaxTargetQueueLength.HasValue)
            {
                configuration.MaxTargetQueueLength = Math.Max(1, configuration.MaxTargetQueueLength.Value);
            }
        }
Пример #3
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());
            }

            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 jobStepSource = Composer.GetComponent <IJobStepSource <TJobStep> >(job.Configuration.QueueTypeName);

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

            await jobStepSource.EnsureJobSourceExists();

            return(jobId);
        }