Unifying job trigger data for a manual run#176
Merged
maikebing merged 1 commit intoIoTSharp:masterfrom Feb 7, 2026
Merged
Conversation
AT-WH
commented
Feb 6, 2026
Comment on lines
+21
to
+36
| public static ITrigger CreateAdHocTrigger(string username, JobKey jobKey, JobDataMap jobData) | ||
| { | ||
| var dt = DateTime.UtcNow; | ||
| var truncatedUsername = username.Length > 30 ? username.Substring(0, 30) : username; | ||
| var triggerName = $"{truncatedUsername}-{dt.ToString("ddMMHHmmss")}"; | ||
| if (!jobData.ContainsKey(USERNAME_KEY)) | ||
| jobData.Put(USERNAME_KEY, truncatedUsername); | ||
| return | ||
| TriggerBuilder.Create() | ||
| .WithIdentity(triggerName, "MT") | ||
| .UsingJobData(jobData) | ||
| .StartNow() | ||
| .ForJob(jobKey) | ||
| .Build(); | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This function was extracted from PostTrigger Action so that it could be reused in Save as well.
@maikebing I'm not sure what's your convention for placing this sort of per-Controller-Utils. I put it here, but I'm happy to move it somewhere else if needed.
AT-WH
commented
Feb 6, 2026
| } | ||
| else | ||
| { | ||
| await Scheduler.TriggerJob(jobKey); |
Contributor
Author
There was a problem hiding this comment.
If username is not defined then it defaults to the previous functionality.
AT-WH
commented
Feb 6, 2026
Comment on lines
+26
to
+27
| if (!jobData.ContainsKey(USERNAME_KEY)) | ||
| jobData.Put(USERNAME_KEY, truncatedUsername); |
Contributor
Author
There was a problem hiding this comment.
I tried using a quite unusual, yet still understandable key name for this, but in case a job had alread had a parameter __USERNAME defined, I don't want to overwrite it.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello again o/
I've noticed that the way Trigger-related data for manually triggered jobs provides different values depending on the MVC Action used for triggering jobs.
I actually think that this feature could have been introduced by me long time ago :).
Anyway, in this PR I suggest unifying the two. Also, I've extended the JobDataMap to include the username (under a key
__USERNAME) in case a consumer needed this piece of info.