Esempio n. 1
0
        public async Task SaveTask(AdHocScheduleRequest request)
        {
            if (request == null)
            {
                this._logger?.LogInformation("request to save task is null");
                return;
            }

            var dto = new TaskSchedulerDto(request);

            try
            {
                this._logger?.LogInformation("saving ad hod schedule request");

                using (var dbConnection = this._dbConnectionFactory.BuildConn())
                    using (var conn = dbConnection.ExecuteAsync(SaveTaskScheduler, dto))
                    {
                        await conn;
                        this._logger.LogInformation("saving ad hoc schedule request completed");
                    }
            }
            catch (Exception e)
            {
                this._logger.LogError(e, $"SaveTask encountered error");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The publish.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task Publish(AdHocScheduleRequest request)
        {
            if (request == null || string.IsNullOrWhiteSpace(request.JsonSqsMessage))
            {
                this.logger?.LogInformation("asked to publish a null or empty request message");
                return;
            }

            var cancellationToken = new CancellationTokenSource();

            try
            {
                this.logger.LogInformation(
                    $"publishing message to {this.awsConfiguration.ScheduleRuleDistributedWorkQueueName}");

                await this.awsQueueClient
                .SendToQueue(
                    this.awsConfiguration.ScheduleRuleDistributedWorkQueueName,
                    request.JsonSqsMessage,
                    cancellationToken.Token)
                ;

                this.logger.LogInformation(
                    $"published message to {this.awsConfiguration.ScheduleRuleDistributedWorkQueueName}");
            }
            catch (Exception e)
            {
                this.logger.LogError(
                    $"exception when publishing '{request.JsonSqsMessage}' to queue {this.awsConfiguration.ScheduleRuleDistributedWorkQueueName} {e.Message} {e.InnerException?.Message}",
                    e);
            }
        }
        /// <summary>
        /// The publish.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task Publish(AdHocScheduleRequest request)
        {
            if (request == null || string.IsNullOrWhiteSpace(request.JsonSqsMessage))
            {
                this.logger.LogInformation("asked to publish a rescheduled request that was null or empty");
                return;
            }

            var messageBusCts = new CancellationTokenSource();

            try
            {
                this.logger.LogInformation($"dispatching to {this.awsConfiguration.ScheduledRuleQueueName}");

                await this.awsQueueClient
                .SendToQueue(
                    this.awsConfiguration.ScheduledRuleQueueName,
                    request.JsonSqsMessage,
                    messageBusCts.Token)
                ;

                this.logger.LogInformation($"finished dispatching to {this.awsConfiguration.ScheduledRuleQueueName}");
            }
            catch (Exception e)
            {
                this.logger.LogError(e, $"exception sending message '{request.JsonSqsMessage}' to queue '{this.awsConfiguration.ScheduledRuleQueueName}'.");
            }
        }
Esempio n. 4
0
 public TaskSchedulerDto(AdHocScheduleRequest request)
 {
     this.Id                 = request.Id;
     this.ScheduleFor        = request.ScheduleFor;
     this.QueueId            = (int)request.Queue;
     this.JsonSqsMessage     = request.JsonSqsMessage;
     this.OriginatingService = request.OriginatingService;
 }
        public async Task Create_CreatesARow()
        {
            var connectionStringFactory = new ConnectionStringFactory(this._configuration);
            var repo         = new TaskSchedulerRepository(connectionStringFactory, this._logger);
            var adhocRequest = new AdHocScheduleRequest
            {
                JsonSqsMessage     = "abc",
                OriginatingService = "surv-main",
                Processed          = false,
                Queue       = SurveillanceSqsQueue.CaseMessage,
                ScheduleFor = DateTime.UtcNow
            };

            await repo.SaveTask(adhocRequest);
        }
        /// <summary>
        /// The schedule.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task ScheduleAsync(AdHocScheduleRequest request)
        {
            switch (request.Queue)
            {
            case SurveillanceSqsQueue.CaseMessage:
                this.logger.LogError("schedule due tasks found a case message reschedule which is not supported");
                break;

            case SurveillanceSqsQueue.DataImportS3Upload:
                this.logger.LogError(
                    "schedule due tasks found a data import s3 upload reschedule which is not supported");
                break;

            case SurveillanceSqsQueue.DataSynchroniserRequest:
                this.logger.LogError(
                    "schedule due tasks found a data synchroniser request reschedule which is not supported");
                break;

            case SurveillanceSqsQueue.DistributedRule:
                await this.RescheduleDistributedRule(request);

                break;

            case SurveillanceSqsQueue.ScheduleRuleCancellation:
                this.logger.LogError(
                    "schedule due tasks found schedule rule cancellation reschedule which is not supported");
                break;

            case SurveillanceSqsQueue.ScheduledRule:
                await this.RescheduleScheduledRule(request);

                break;

            case SurveillanceSqsQueue.TestRuleRunUpdate:
                this.logger.LogError(
                    "schedule due tasks found a test rule run update reschedule which is not supported");
                break;

            case SurveillanceSqsQueue.UploadCoordinator:
                this.logger.LogError(
                    "schedule due tasks found a upload coordinator reschedule which is not supported");
                break;
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Ensures that the rescheduled execution is also in the future as an additional layer
        ///     of business logic guards
        /// </summary>
        /// <param name="execution"></param>
        public async Task RescheduleFutureExecution(ScheduledExecution execution)
        {
            this._logger?.LogInformation("Beginning reschedule execution");

            if (execution == null)
            {
                this._logger?.LogInformation("Received null execution. Exiting");
                return;
            }

            if (execution.IsBackTest)
            {
                this._logger?.LogInformation("We don't reschedule back tests");
                return;
            }

            if (execution.IsForceRerun)
            {
                this._logger?.LogInformation("We don't reschedule re runs to prevent exponential growth in rule runs");
                return;
            }

            this._logger?.LogInformation("Serialising execution");
            var sqsMessage = JsonConvert.SerializeObject(execution);

            var projectedExecution = new AdHocScheduleRequest
            {
                OriginatingService = "Surveillance Engine",
                ScheduleFor        = DateTime.UtcNow.AddDays(1),                       // re-run this tomorrow
                Queue =
                    SurveillanceSqsQueue
                    .DistributedRule,                       // avoids being re-distributed through the distributor
                JsonSqsMessage =
                    sqsMessage                              // message to rerun - must be what the json deserialiser is expecting!
            };

            this._logger?.LogInformation(
                $"About to save projected execution {nameof(AdHocScheduleRequest)} to the task scheduler repository");
            await this._taskSchedulerRepository.SaveTask(projectedExecution);
        }
 /// <summary>
 /// The reschedule scheduled rule.
 /// </summary>
 /// <param name="request">
 /// The request.
 /// </param>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 private async Task RescheduleScheduledRule(AdHocScheduleRequest request)
 {
     await this.scheduledRulePublisher.Publish(request);
 }