/// <inheritdoc /> public string Create(Job job, IState state) { if (job == null) { throw new ArgumentNullException("job"); } if (state == null) { throw new ArgumentNullException("state"); } try { using (var connection = _storage.GetConnection()) { var context = new CreateContext(connection, _stateMachineFactory, job, state); _process.Run(context); return(context.JobId); } } catch (Exception ex) { throw new CreateJobFailedException("Job creation process has bee failed. See inner exception for details", ex); } }
/// <summary> /// Initializes a new instance of the <see cref="BackgroundJobClient"/> class /// with a specified job storage and job creation process. /// </summary> /// /// <exception cref="ArgumentNullException"><paramref name="storage"/> argument is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="process"/> argument is null.</exception> public BackgroundJobClient(JobStorage storage, IJobCreationProcess process) { if (storage == null) throw new ArgumentNullException("storage"); if (process == null) throw new ArgumentNullException("process"); _connection = storage.GetConnection(); _process = process; }
public void AddOrUpdate( [NotNull] string recurringJobId, [NotNull] Job job, [NotNull] string cronExpression) { if (recurringJobId == null) { throw new ArgumentNullException("recurringJobId"); } if (job == null) { throw new ArgumentNullException("job"); } if (cronExpression == null) { throw new ArgumentNullException("cronExpression"); } CrontabSchedule.Parse(cronExpression); using (var connection = _storage.GetConnection()) { var recurringJob = new Dictionary <string, string>(); var invocationData = InvocationData.Serialize(job); recurringJob["Job"] = JobHelper.ToJson(invocationData); recurringJob["Cron"] = cronExpression; using (var transaction = connection.CreateWriteTransaction()) { transaction.SetRangeInHash( String.Format("recurring-job:{0}", recurringJobId), recurringJob); transaction.AddToSet("recurring-jobs", recurringJobId); transaction.Commit(); } } }
/// <summary> /// Initializes a new instance of the <see cref="BackgroundJobClient"/> class /// with a specified job storage and job creation process. /// </summary> /// /// <exception cref="ArgumentNullException"><paramref name="storage"/> argument is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="process"/> argument is null.</exception> public BackgroundJobClient( JobStorage storage, IStateMachineFactory stateMachineFactory, IJobCreationProcess process) { if (storage == null) { throw new ArgumentNullException("storage"); } if (stateMachineFactory == null) { throw new ArgumentNullException("stateMachineFactory"); } if (process == null) { throw new ArgumentNullException("process"); } _connection = storage.GetConnection(); _stateMachineFactory = stateMachineFactory; _process = process; }