Hello all,
I can’t find solution how to populate scheduled task… Only recurring task you can find or update by custom unique identifier but my task are’nt recurring…
This is the way How I starting my jobs:
BackgroundJob.Schedule(() => new DeadlineJobService().HandleDeadline(...
Can anyone help me?
All that Schedule does is create a standard background job but starts it in the scheduled state rather than the enqueued state. The method returns the job ID of this scheduled job:
}
/// <summary>
/// Creates a new background job based on a specified static method
/// call expression and schedules it to be enqueued after a given delay.
/// </summary>
/// <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>
/// <returns>Unique identifier of the created job.</returns>
public static string Schedule([NotNull] this IBackgroundJobClient client, [InstantHandle] Expression<Action> methodCall, TimeSpan delay)
{
if (client == null) throw new ArgumentNullException("client");
return client.Create(methodCall, new ScheduledState(delay));
}
/// <summary>
/// Creates a new background job based on a specified method call expression
/// and schedules it to be enqueued at the specified moment of time.
/// </summary>
So to cancel it you can just delete the job. If you only want to cancel scheduled jobs which have not yet started, you can use the overload which takes a state predicate:
///
/// The method returns result of a state transition. It can be false
/// if a job was expired, its method does not exist or there was an
/// exception during the state change process.
/// </remarks>
///
/// <param name="client">An instance of <see cref="IBackgroundJobClient"/> implementation.</param>
/// <param name="jobId">Identifier of job, whose state is being changed.</param>
/// <param name="fromState">Current state assertion, or null if unneeded.</param>
/// <returns>True, if state change succeeded, otherwise false.</returns>
public static bool Delete([NotNull] this IBackgroundJobClient client, string jobId, string fromState)
{
if (client == null) throw new ArgumentNullException("client");
var state = new DeletedState();
return client.ChangeState(jobId, state, fromState);
}
/// <summary>
/// Changes state of a job with the specified <paramref name="jobId"/>
/// to the <see cref="EnqueuedState"/>.