Exemplo n.º 1
0
        public async Task SendScheduledMessageAsync(int messageId, CancellationToken cancellationToken = default(CancellationToken))
        {
            LogHelper.GetLogger().Debug($"Sending scheduled Message ID {messageId}");

            var message = await _messagingQueries.GetByIdAsync(messageId, cancellationToken);

            if (message.Status == MessageStatus.Scheduled)
            {
                await SendMessageAsync(message, cancellationToken);
            }
        }
        public async Task <Message> ScheduleMessageAsync(Message message, CancellationToken cancellationToken)
        {
            var id = await _messagingRepository.AddAsync(message, cancellationToken);

            message = await _messagingQueries.GetByIdAsync(id);

            IJobDetail job = JobBuilder.Create <ProcessMessageJob>()
                             .WithIdentity(Guid.NewGuid().ToString())
                             .UsingJobData(ProcessMessageJob.JobDataKey, message.Id)
                             .Build();

            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity(Guid.NewGuid().ToString())
                               .StartAt(message.ScheduledTime ?? DateTime.Now.AddSeconds(30))
                               .Build();

            await _scheduler.ScheduleJob(job, trigger, cancellationToken);

            return(message);
        }