Skip to content

Comments

Unifying job trigger data for a manual run#176

Merged
maikebing merged 1 commit intoIoTSharp:masterfrom
AT-WH:master
Feb 7, 2026
Merged

Unifying job trigger data for a manual run#176
maikebing merged 1 commit intoIoTSharp:masterfrom
AT-WH:master

Conversation

@AT-WH
Copy link
Contributor

@AT-WH AT-WH commented Feb 6, 2026

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.

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();
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}
else
{
await Scheduler.TriggerJob(jobKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If username is not defined then it defaults to the previous functionality.

Comment on lines +26 to +27
if (!jobData.ContainsKey(USERNAME_KEY))
jobData.Put(USERNAME_KEY, truncatedUsername);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@maikebing maikebing merged commit bb050d3 into IoTSharp:master Feb 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants