We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

BackgroundJob.Enqueue returning null

we have a one time job that gets enqueued on startup, we need to track the job id, but we are seeing multiple occasions where the BackgroundJob.Enqueue is returning null, but the job does get enqueued, here is our code:

private void EnqueueJobCountryUpdateService()
        {
            var jobName = nameof(CountryUpdateService);

            // A one-off job updating countries
            var jobIdCountryUpdateService = BackgroundJob.Enqueue(
                () => _countryUpdateService.UpdateIfNeeded(CancellationToken.None));
            if (jobIdCountryUpdateService != null)
            {
                _logger.LogInformation("{CountryUpdateService} job {jobId} enqueued.", jobName,
                    jobIdCountryUpdateService);
                _jobIdDictionary.TryAdd(jobIdCountryUpdateService, 0);
            }
            else
            {
                _logger.LogError("Job {jobname} did not return an Id when Enqueue was called. Run '{jobName}' job manually from hangfire jobs",jobName, jobName);
            }

            //Add disabled recurring job, so that it can be run manually if needed.
            RecurringJob.AddOrUpdate(jobName, () => _countryUpdateService.UpdateIfNeeded(CancellationToken.None), Cron.Never());
        }

ive tried following the hangfire code but cant see where or why its returning null, does anyone have an idea why this might be?

thanks

Looks like there’s a client filter (implements IClientFilter) that cancels background job creation. In this case a bill value is returned.

1 Like

Why do you not enqueue a regular, non-recurring job?