Can someone suggest how to set custom name to JobId rather than sequential 1,2,3…
You can’t. JobID is provided by the storage engine and cannot be changed.
You can implement your own storage provider from scratch, so you will be responsible for generating job identifiers and keeping them unique.
Thanks a lot for the reply.
Could you please suggest which all hangfire classes need to be overridden?
I have another query:
Scenario: I already have few set of jobs in SQL Server database and a separate batch server has been scheduled to execute them. I want to schedule these jobs from hangfire and let batch server execute them. Latest Job status should be displayed on the hangfire dashboard.
Please suggest if this scenario is achievable through Hangfire?
I dont know if this is irrelevant for you or not. but…
you can give the recurring job a name (using DispalyNameAttribute) that can be used as an id.
RecurringJob.AddOrUpdate(package.PackageName,
() => RecurringWorker.RunWithThreeRetries(package.PackageName, package.PackageID),
package.Cron, TimeZoneInfo.Local);
public static class RecurringWorker
{
[DisplayName("{0}")]
[AutomaticRetry(Attempts = 3)]
public static void RunWithThreeRetries(string name, int packageId)
the resulting job still get the incremental int as JobId but you can get the recurring job using the name ( p => p.Id == name)
using (var connection = JobStorage.Current.GetConnection())
{
var recurringJobs = connection.GetRecurringJobs();
var recurring = recurringJobs.FirstOrDefault(p => p.Id.Equals(package.PackageName, StringComparison.InvariantCultureIgnoreCase));
// do stuff
}
this is how it looks in the web
ps.
I am aware there is some superflous code in here, but its just cut from my own code
ds.