Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel or Delete Scheduled Job - HangFire

I have scheduled a Job via using Hangfire library. My scheduled Code like below.

BackgroundJob.Schedule(() => MyRepository.SomeMethod(2),TimeSpan.FromDays(7));

public static bool DownGradeUserPlan(int userId)
    {
        //Write logic here
    }

Now I want to Delete this Scheduled Job later on some event.

like image 377
Vijjendra Avatar asked Aug 08 '18 21:08

Vijjendra


People also ask

Is Hangfire Russian?

Starting from Mar 8, 2022 Hangfire is owned by Hangfire OÜ (private limited), an Estonian company.

What is Hangfire used for?

Hangfire is an open-source framework that can be used to perform background processing in . Net and . Net Core applications. It is mainly used to perform background tasks such as batch/email notification, batch import of files, video/image processing, database maintaining, file purging, etc.


Video Answer


1 Answers

BackgroundJob.Schedule returns you an id of that job, you can use it to delete this job:

var jobId = BackgroundJob.Schedule(() =>  MyRepository.SomeMethod(2),TimeSpan.FromDays(7));

BackgroundJob.Delete(jobId);
like image 101
Alex Riabov Avatar answered Sep 23 '22 21:09

Alex Riabov