'How to get RecurringJob from ElectStateContext?

I try to implement IElectStateFilter and get RecurringJobId for current job from context.

Is it there a way to get RecurringJobId for BackgroundJob.Id from context?

        public void OnStateElection(ElectStateContext context)
        {
            if (context.CandidateState.Name == FailedState.StateName)
            {
                var data = context.Connection
                    .GetRecurringJobs()
                    .Where(x=>x.Removed is false);
                
                // How to map current job from context to recurringJob?
                
            }
        }

enter image description here



Solution 1:[1]

This will get you the string name you gave your recurring job:

var mon = JobStorage.Current.GetMonitoringApi();
var job = mon.JobDetails(context.BackgroundJob.Id);
var recurringJobId = job.Properties["RecurringJobId"];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2141945