-
-
Save anonymous/caeb25f3e7e4430d94b353ebea82e3e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class UseTenantNameAsQueueAttribute : JobFilterAttribute, IElectStateFilter | |
{ | |
public string TenantName; | |
public UseTenantNameAsQueueAttribute() | |
{ | |
this.TenantName = Settings.Default.TenantName.ToLower(); | |
} | |
public void OnStateElection(ElectStateContext context) | |
{ | |
if (context.CandidateState is ScheduledState s) | |
{ | |
try | |
{ | |
var jobid = context.BackgroundJob.Id; | |
Storage.SaveJobQueue(jobid, TenantName) | |
} | |
catch (Exception ex) | |
{ | |
//logging | |
} | |
} | |
else if (context.CandidateState is EnqueuedState e) | |
{ | |
try | |
{ | |
var jobid = context.BackgroundJob.Id; | |
e.Queue = Storage.LoadJobQueue(jobid) ?? TenantName | |
} | |
catch (Exception ex) | |
{ | |
e.Queue = TenantName; | |
//logging | |
} | |
} | |
} | |
} |
Storage.SaveJobQueue(jobid, TenantName) ?
SaveJobQueue is not Hangfire API
how to implement SaveJobQueue ?
I was able to do this:
context.Connection.SetJobParameter(context.BackgroundJob.Id, "QueueName", TenantName)
and
e.Queue = context.Connection.GetJobParameter(context.BackgroundJob.Id, "QueueName") ?? TenantName
I tried it both with Hangfire.MemoryStorage
and the regular Sql Storage.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Storage.SaveJobQueue(jobid, TenantName) ?
SaveJobQueue is not Hangfire API
how to implement SaveJobQueue ?