Conversation
Allows to add the new job of any type to the scheduler
| } | ||
|
|
||
| addJob(job: Job): void { | ||
| if (job instanceof SimpleIntervalJob || job instanceof LongIntervalJob) { |
There was a problem hiding this comment.
instanceof check is notoriously unrealiable and will not work correctly when comparing instances created in a different realm (e. g. if you are using a job created inside a shared library in an app that depends both on a shared library and on toad-scheduler). I would recommend introducing some id field on the job, and using it for a proper type guard
|
I think this problem implementation is beyond my skills just yet, thanks for reviewing it |
|
@jakmaz I can guide you through it, if you want! You have 90% of the solution there, it just needs some small tweaks |
|
Okay! I suppose I get the point of adding the id field more now. I also thought of another solution, that is adding the abstract method |
Description:
This pull request simplifies the
ToadSchedulerby introducing a unifiedaddJobmethod for job addition, deprecating the specific methods likeaddIntervalJobandaddCronJob.Rationale:
I chose this simple, single-method design over a polymorphic approach to maintain ease of use and understandability. The alternative considered was a more polymorphic design, where each job type would know how to add itself to the scheduler:
Instead, I used a straightforward approach where the
addJobmethod internally determines the job type and delegates to the appropriate method:This approach would follow the Open/Closed Principle more closely but was not adopted due to the stability and limited extension expected in our job types.
Impact:
The update simplifies adding jobs to the scheduler, making the codebase easier to maintain and understand while still allowing for internal specialization for different job types.