ScheduleJob shorthand: Job name should match trigger name by default
See original GitHub issueDescribe the bug
ScheduleJob is documented as a shorthand for AddJob
plus AddTrigger
, and it is wonderful.
Configuring the trigger is mandatory. Configuring the job is optional. It is, by far, the most readable to omit the job configuration - even the example in the docs omits it.
However, if no job name is explicitly specified, a UUID is generated for it. This seems like a poor default. Consider the example from the docs:
q.ScheduleJob<ExampleJob>(trigger => trigger
.WithIdentity("Combined Configuration Trigger")
.StartAt(DateBuilder.EvenSecondDate(DateTimeOffset.UtcNow.AddSeconds(7)))
.WithDailyTimeIntervalSchedule(x => x.WithInterval(10, IntervalUnit.Second))
.WithDescription("my awesome trigger configured for a job with single call")
);
The trigger name will be “Combined Configuration Trigger”. What should the job name be? I would infer that, considering what the shorthand was designed for in the first place, the job name should match the trigger name by default.
Version used
3.3.2.
To Reproduce
Simply implement the example from the docs.
Expected behavior
The job name (in the backing store) should equal the trigger name.
Additional Context
The only workaround we currently have is significantly uglier than the example, and seems to somewhat cancel out the benefits of the shorthand:
q.ScheduleJob<ExampleJob>(trigger => trigger
.WithIdentity("Combined Configuration Trigger")
.StartAt(DateBuilder.EvenSecondDate(DateTimeOffset.UtcNow.AddSeconds(7)))
.WithDailyTimeIntervalSchedule(x => x.WithInterval(10, IntervalUnit.Second))
.WithDescription("my awesome trigger configured for a job with single call"),
job => job.WithIdentity("Combined Configuration Trigger")
);
More importantly, it violates the DRY (Don’t Repeat Yourself) principle. We could store the job name in a variable or constant, but that would require even more code.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (10 by maintainers)
Top GitHub Comments
Thanks for the discussion and a great PR to improve things!
@Timovzl please use a fork, it’s quite standard way as I cannot allow full write access to this repo for everyone. Using a PR allows us to discuss the implementation.