/// <summary> /// Creates a new background job based on a specified lambda expression and schedules /// it to be enqueued at the specified moment. /// </summary> /// <typeparam name="T">Type whose method will be invoked during job processing.</typeparam> /// <param name="client">A job client instance.</param> /// <param name="methodCall">Method call expression that will be marshalled to the Server.</param> /// <param name="enqueueAt">Moment at which the job will be enqueued.</param> /// <param name="queueName">The name of the queue to place the job in. This value overrides <see cref="QueueAttribute"/>.</param> /// <returns>Unique identifier of a created job.</returns> public static string Schedule <T>( [NotNull] this IBackgroundJobClient client, [NotNull, InstantHandle] Expression <Func <T, Task> > methodCall, DateTimeOffset enqueueAt, string queueName = null) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (queueName != null) { return(client.Create(methodCall, new ScheduledState(enqueueAt.UtcDateTime, queueName))); } var job = Job.FromExpression(methodCall); return(client.Create(methodCall, new ScheduledState(enqueueAt.UtcDateTime, job.QueueName))); }
/// <summary> /// Creates a new background job that will wait for another background job to be triggered. /// </summary> /// <param name="client">A job client instance.</param> /// <param name="parentId">Identifier of a background job to wait completion for.</param> /// <param name="methodCall">Method call expression that will be marshalled to a server.</param> /// <param name="nextState">Next state for a job, when continuation is triggered. /// If null, then <see cref="EnqueuedState"/> is used.</param> /// <param name="options">Continuation options. By default, /// <see cref="JobContinuationOptions.OnlyOnSucceededState"/> is used.</param> /// <param name="continuationQueueName">The name of the queue to place the continuation job in. /// This value overrides <see cref="QueueAttribute"/>.</param> /// <returns>Unique identifier of a created job.</returns> public static string ContinueWith <T>( [NotNull] this IBackgroundJobClient client, [NotNull] string parentId, [NotNull, InstantHandle] Expression <Func <T, Task> > methodCall, [CanBeNull] IState nextState = null, JobContinuationOptions options = JobContinuationOptions.OnlyOnSucceededState, [CanBeNull] string continuationQueueName = null) { if (client == null) { throw new ArgumentNullException(nameof(client)); } var continuationState = nextState ?? new EnqueuedState(continuationQueueName ?? Job.FromExpression(methodCall).QueueName); var state = new AwaitingState(parentId, continuationState, options); return(client.Create(Job.FromExpression(methodCall), state)); }
/// <summary> /// Creates a new background job based on a specified instance method /// call expression and schedules it to be enqueued after a given delay. /// </summary> /// /// <typeparam name="T">Type whose method will be invoked during job processing.</typeparam> /// <param name="client">A job client instance.</param> /// <param name="methodCall">Instance method call expression that will be marshalled to the Server.</param> /// <param name="delay">Delay, after which the job will be enqueued.</param> /// <param name="queueName">The name of the queue to place the job in. This value overrides <see cref="QueueAttribute"/>.</param> /// <returns>Unique identifier of the created job.</returns> public static string Schedule <T>( [NotNull] this IBackgroundJobClient client, [NotNull, InstantHandle] Expression <Action <T> > methodCall, TimeSpan delay, string queueName = null) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (queueName != null) { return(client.Create(methodCall, new ScheduledState(delay, queueName))); } var job = Job.FromExpression(methodCall); return(client.Create(job, new ScheduledState(delay, job.QueueName))); }