BackgroundJobManagerExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526
  1. using System;
  2. using Abp.Threading;
  3. namespace Abp.BackgroundJobs
  4. {
  5. /// <summary>
  6. /// Some extension methods for <see cref="IBackgroundJobManager"/>.
  7. /// </summary>
  8. public static class BackgroundJobManagerExtensions
  9. {
  10. /// <summary>
  11. /// Enqueues a job to be executed.
  12. /// </summary>
  13. /// <typeparam name="TJob">Type of the job.</typeparam>
  14. /// <typeparam name="TArgs">Type of the arguments of job.</typeparam>
  15. /// <param name="backgroundJobManager">Background job manager reference</param>
  16. /// <param name="args">Job arguments.</param>
  17. /// <param name="priority">Job priority.</param>
  18. /// <param name="delay">Job delay (wait duration before first try).</param>
  19. public static void Enqueue<TJob, TArgs>(this IBackgroundJobManager backgroundJobManager, TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null)
  20. where TJob : IBackgroundJob<TArgs>
  21. {
  22. AsyncHelper.RunSync(() => backgroundJobManager.EnqueueAsync<TJob, TArgs>(args, priority, delay));
  23. }
  24. }
  25. }