private void Schedule(Func <IJobDetail> jobFactory, DateTime runAt, ScheduleKey key) { try { _logger.Debug("Scheduling job {Task}", key); var job = jobFactory(); var trigger = TriggerBuilder.Create() .WithIdentity(job.Key.Name, job.Key.Group) .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionFireNow() .WithRepeatCount(0)) .StartAt(runAt) .Build(); var fireTime = _scheduler.ScheduleJob(job, trigger); _logger.Debug("Scheduled job {Task} at {Time}", key, fireTime); Sender.Tell(new Scheduled(fireTime.UtcDateTime)); } catch (JobPersistenceException e) { _logger.Error(e, "Error while scheduled job {Task}", key); if (e.InnerException?.GetType() == typeof(ObjectAlreadyExistsException)) { Sender.Tell(new AlreadyScheduled(key)); } } catch (Exception e) { _logger.Error(e, "Error while scheduled job {Task}", key); Sender.Tell(new Failure { Exception = e, Timestamp = BusinessDateTime.UtcNow }); } }
//post to keys public void Test(ScheduleKey value) { using (var conn = new SqlConnection(this.connString)) { string sQuery = "INSERT INTO ScheduleKeys (ScheduleID, KeyID)" + " VALUES(@ScheduleID,@KeyID)"; conn.Open(); conn.Execute(sQuery, value); } }
public static IJobDetail CreateJob(ScheduleKey key, JobDataMap jobDataMap) { var jobKey = new JobKey(key.Name, key.Group); return(JobBuilder.Create <QuartzJob>() .WithIdentity(jobKey) .WithDescription(key.Description) .UsingJobData(jobDataMap) .RequestRecovery(true) .Build()); }
public static IJobDetail Create(ScheduleKey key, DomainEvent eventToSchedule, IMessageMetadata metadata) { var serializedEvent = Serialize(eventToSchedule); var serializedKey = Serialize(key); var serializedMetadata = Serialize(metadata); var jobDataMap = new JobDataMap { { EventKey, serializedEvent }, { ScheduleKey, serializedKey }, { MetadataKey, serializedMetadata } }; return(CreateJob(key, jobDataMap)); }
public static IJobDetail Create(ScheduleKey key, Command command, IMessageMetadata metadata, ExecutionOptions executionOptions) { var serializedCommand = Serialize(command); var serializedKey = Serialize(key); var serializedOptions = Serialize(executionOptions); var serializedMetadata = Serialize(metadata); var jobDataMap = new JobDataMap { { CommandKey, serializedCommand }, { ScheduleKey, serializedKey }, { ExecutionOptionsKey, serializedOptions }, { MetadataKey, serializedMetadata } }; return(CreateJob(key, jobDataMap)); }
public void QuartzJob_should_be_deserialized_from_new_wire_format() { var cmd = new ChangeSampleAggregateCommand(1, Guid.NewGuid()); var evt = new SampleAggregateCreatedEvent("1", cmd.AggregateId); var scheduleKey = ScheduleKey.For(cmd); var oldSerializer = new Serializer(new SerializerOptions(true, true, null, null)); var streamEvent = new MemoryStream(); oldSerializer.Serialize(evt, streamEvent); var serializedEvent = streamEvent.ToArray(); var streamKey = new MemoryStream(); oldSerializer.Serialize(scheduleKey, streamKey); var serializedKey = streamKey.ToArray(); var jobDataMap = new JobDataMap { { "EventKey", serializedEvent }, { "ScheduleKey", serializedKey } }; var job = QuartzJob.CreateJob(scheduleKey, jobDataMap); var trigger = TriggerBuilder.Create() .WithIdentity(job.Key.Name, job.Key.Group) .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionFireNow() .WithRepeatCount(0)) .StartAt(BusinessDateTime.Now.AddSeconds(1)) .Build(); var scheduler = GridNode.Container.Resolve <IScheduler>(); scheduler.ScheduleJob(job, trigger); var waiter = GridNode.NewWaiter(Timeout) .Expect <SampleAggregateCreatedEvent>(e => e.SourceId == evt.SourceId) .Create(); waiter.Wait(); }
public void Legacy_wire_data_can_run_with_latest_job_code() { ScheduleKey key = new ScheduleKey(Guid.NewGuid(), Name, Group); Command command = new SuccessCommand("1232"); ExecutionOptions executionOptions = new ExecutionOptions(DateTime.Now.AddSeconds(1), typeof(ScheduledCommandSuccessfullyProcessed)); var serializedCommand = SerializeAsLegacy(command); var serializedKey = SerializeAsLegacy(key); var serializedOptions = SerializeAsLegacy(executionOptions); var jobDataMap = new JobDataMap { { QuartzJob.CommandKey, serializedCommand }, { QuartzJob.ScheduleKey, serializedKey }, { QuartzJob.ExecutionOptionsKey, serializedOptions } }; var legacyJob = QuartzJob.CreateJob(key, jobDataMap); var listener = new CallbackJobListener(); _quartzScheduler.ListenerManager.AddJobListener(listener, KeyMatcher <JobKey> .KeyEquals(legacyJob.Key)); var task = listener.TaskFinish.Task; var trigger = TriggerBuilder.Create() .WithIdentity(legacyJob.Key.Name, legacyJob.Key.Group) .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionFireNow() .WithRepeatCount(0)) .StartAt(DateTimeOffset.Now.AddMilliseconds(200)) .Build(); _quartzScheduler.ScheduleJob(legacyJob, trigger); if (!task.Wait(TimeSpan.FromSeconds(10000))) { Assert.Fail("Job execution timed out"); } if (task.Result.Item2 != null) { Assert.Fail("Job threw an exception", task.Result.Item2); } }
private async Task Schedule(ScheduleCommandExecution message) { ScheduleKey key = message.Key; try { _logger.Debug($"Scheduling job {key} for {message.Options.RunAt}"); var job = QuartzJob.Create(message.Key, message.Command, message.CommandMetadata, message.Options); var trigger = TriggerBuilder.Create() .WithIdentity(job.Key.Name, job.Key.Group) .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionFireNow().WithRepeatCount(0)) .StartAt(message.Options.RunAt) .Build(); var fireTime = await _scheduler.ScheduleJob(job, trigger); var scheduleConfirmation = new CommandExecutionScheduled(message.Command.Id, fireTime.UtcDateTime); Sender.Tell(scheduleConfirmation); _publisher.Publish(scheduleConfirmation, message.CommandMetadata); } catch (Exception e) { _logger.Error(e, "Error while scheduled job {Task}", key); if (e is JobPersistenceException && e.InnerException?.GetType() == typeof(ObjectAlreadyExistsException)) { Sender.Tell(new AlreadyScheduled(key)); } else { Sender.Tell(new Status.Failure(e)); } var fault = Fault.New(message, e, message.Command.ProcessId, typeof(SchedulingActor)); _publisher.Publish(fault, message.CommandMetadata); } }
public AlreadyScheduled(ScheduleKey key) { Key = key; }
public SagaReceivedCommandEvent(Command command, ScheduleKey key, Type successEventType) { Command = command; Key = key; SuccessEventType = successEventType; }
public void Post([FromBody] ScheduleKey value) { scheduleKeyDataRepository.Test(value); }
public static JobKey ToJobKey(this ScheduleKey key) { return(new JobKey(key.Name, key.Group)); }
public ScheduledCommandProcessingSagaState(Guid id, ScheduledCommandProcessingSaga.States state, Command command, ScheduleKey key, Type successEventType) : base(id, state) { var sagaReceivedCommandEvent = new SagaReceivedCommandEvent(command, key, successEventType); RaiseEvent(sagaReceivedCommandEvent); }
public Unscheduled(ScheduleKey key) { Key = key; }
public static ScheduledCommandProcessingStarted Create <TSuccessEvent>(Command command, ScheduleKey key) where TSuccessEvent : DomainEvent { return(new ScheduledCommandProcessingStarted(command, key, typeof(TSuccessEvent))); }
private ScheduledCommandProcessingStarted(Command command, ScheduleKey key, Type successEventType) : base(key.Id, DateTime.UtcNow, key.Id) { Command = command; Key = key; SuccessEventType = successEventType; }