Job cancellation

My humble opinion for example, is to create an Attributes like below [JobCancellation] here we add overload method to the job class with boolean return, if the return is false then job is cancelled automatically.

Example:

[JobCancellation]
public class SomeJob
{
    public void SomeMethod()
    {
        //some programming logic
    }

    public override bool Cancellation()
    {
        if (user==null) { return false; }
    }
}
  • [JobCancellation(max number of retries)] – if the number of retires for this job reaches the max number then job is cancelled automatically.
  • [JobCancellation(Date)] – if the job execution passes certain date then job is cancelled automatically.
  • [JobCancellation(IJobCancellationToken token)] – if the token is canceled somewhere in the application then job is cancelled automatically.

@devmondo, I’ve already answered this question here.