feat(scheduler): add Scheduler for centralized cron job management#1066
Open
Lucasjapa wants to merge 1 commit into
Open
feat(scheduler): add Scheduler for centralized cron job management#1066Lucasjapa wants to merge 1 commit into
Lucasjapa wants to merge 1 commit into
Conversation
Introduce opt-in job registration via schedule() and register(). Each Scheduler instance owns an isolated JobRegistry for lifecycle control, status queries and graceful shutdown. - add JobRegistry for per-instance job storage and execution counting - add Scheduler with schedule, register, lifecycle and query methods - export Scheduler singleton, ScheduleParams and RegistryEntry types - add Jest tests and runnable examples under examples/scheduler/ - document Scheduler API in README
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.
Introduce opt-in job registration via schedule() and register(). Each Scheduler instance owns an isolated JobRegistry for lifecycle control, status queries and graceful shutdown.
Description
Introduce opt-in job registration via
schedule()andregister(). EachSchedulerinstance owns an isolatedJobRegistryfor lifecycle control, status queries and graceful shutdown.JobRegistryfor per-instance job storage and execution countingSchedulerwithschedule,register, lifecycle and query methodsSchedulersingleton,ScheduleParamsandRegistryEntrytypesexamples/scheduler/New API
Scheduler/schedulerschedule(params)— creates aCronJob, registers it, then appliesrunOnInitandstartregister(name, job)— registers an existingCronJob(opt-in, never automatic)start,stop,startAll,stopAll,remove,unregister,cleargetJobNames,getJob,getJobInfo,getActiveJobs,getInactiveJobs,getPending,nextJobsDesign decisions
nametoCronJobalone does not register the jobSchedulerinstance has its own registry (isolated for tests and workers)lastExecutionis derived fromjob.lastDate()to avoid duplicated metadataremove()stops and unregisters;unregister()only removes from the registryRelated Issue
N/A — feature extension discussed and implemented locally. Happy to open a feature request issue if maintainers prefer tracking before merge.
URL: #871
Motivation and Context
The
node-cronlibrary is intentionally low-level: eachCronJobis managed individually. In real applications with multiple scheduled tasks, developers typically reinvent aMapto track jobs, handle graceful shutdown, and expose health-check information.This PR adds an optional management layer on top of the existing
CronJobAPI without changing its behavior. Apps that only need a single job can continue usingCronJobdirectly; apps with multiple jobs gain centralized lifecycle and query capabilities.How Has This Been Tested?
Environment: Node.js v20.12.2, Linux,
TZ=Europe/Paris(Jest default for this repo)Unit tests (
tests/scheduler.test.ts— 14 cases):npm run test -- tests/scheduler.test.ts
Screenshots (if appropriate):
N/A — backend/library change, no UI.
Types of changes
Checklist:
!after the type/scope in the title (see the Conventional Commits standard).