Querying, Cancelling, and Adhoc
Sometimes it is necessary to cancel job functionality. We don't generally recommend doing this. It is better to check criteria in your job thus allowing the operating system to keep your job relevant in the scheduling process.
However, some may want jobs to start/stop running in certain circumstances (ie. User logs in/out).
IJobManager manager; // inject // Cancelling A Job manager.Cancel("YourJobName"); // Cancelling All Jobs manager.CancelAll();
Running Jobs Adhoc/OnDemand
There will be cases where you want to manually run a job. An example of this is a story like the following:
- User logs in
- Background data sync logic is within a job
- Don't want to wait for a job to run just to sync data the first time
Thus, we can run a specific job and wait for it to complete
IJobManager manager; // inject // Run All Jobs On-Demand var results = await manager.RunAll(); // Run A Specific Job On-Demand var result = await manager.Run("YourJobName");
The job manager allows you to query registered jobs. This is useful for debugging and testing.
IJobManager manager; // inject // get a list of jobs var jobs = await manager.GetJobs(); var job = await manager.GetJob("YourJobName"); // returns null if not found