-
Notifications
You must be signed in to change notification settings - Fork 73
Including user's login in the trigger's name #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
new Claim(ClaimTypes.Name, string.IsNullOrEmpty(password) | ||
? "SilkierQuartzPassword" | ||
: authenticationOptions.Password), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After analyzing this carefuly, I'm not sure if including user's password in Claims is needed anywhere, but it might be the case that I'm not aware of a place where it's needed in the project.
else | ||
{ | ||
await Scheduler.TriggerJob(jobKey, jobData); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else
contains the current master
code, which is used if the username
can't be retrieved for whatever reason.
{ | ||
var dt = DateTime.UtcNow; | ||
var truncatedUsername = username.Length > 30 ? username.Substring(0, 30) : username; | ||
var triggerName = $"{truncatedUsername}-{dt.ToString("ddMMHHmmss")}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I searched for a naming convention that includes username
as well as prevents conflicts if the same user triggers multiple Jobs. Also, I didn't want to make the name too long, so that the UI doesn't break.
As a result I came up with the following:
- take up to 30 characters of the username
- append a number constructed by concatenating
monthDayHourMinuteSecond
- I doubt that any user is able to trigger a job more frequently than once a second - for every time component always print it using two digits (that means: use leading zeros if needed).
var trigger = | ||
TriggerBuilder.Create() | ||
.WithIdentity(triggerName, "MT") | ||
.UsingJobData(jobData) | ||
.StartNow() | ||
.ForJob(jobKey) | ||
.Build(); | ||
await Scheduler.ScheduleJob(trigger); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to kick off a job with a trigger's name manually set, I define a trigger for the job which starts immediately and then use it to schedule a job.
var history = hsl!=null? await hsl.FilterLastOfEveryJob(10):null; | ||
var history = hsl != null ? await hsl.FilterLastOfEveryJob(10) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My VS must have changed this formatting automatically. I can revert this if it breaks your code convention.
After allowing multiple users by providing custom authentication mechanism, I found it difficult to find out who triggered jobs. I think that it is possible to easily include this information in the trigger's name. E.g.
(In the session presented in the screen above, I'm logged in as "MyUser123")
I've come up with a suggestion for a naming convention for such triggers, but I don't insist on it.