implement scheduler #30
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
start from development_kristof branch
make sure we have all newest changes
then create branch development_cron to further work on
see scheduling capabilities in the schema's
use https://docs.rs/cron_tab/latest/cron_tab/ to do the execution
Implementation Spec for Issue #30: Implement Scheduler
Objective
Implement a scheduler component in zinit_server that reads
SchedulePolicyfromActionSpecdefinitions and automatically creates jobs based on cron expressions and/or interval timers, using thecron_tabcrate.Requirements
schedule_policycontaining a cron expression trigger job creation at specified timesinterval_mstrigger job creation at the specified intervalstart_timeandend_timerespected as scheduling windowsnr_of_instanceslimits concurrent running jobs from the same actionschedule.list,schedule.statuszinit schedulesaddedExisting Data Model (Already Present)
SchedulePolicyatcrates/zinit_lib/src/db/actions/model.rs:336:nr_of_instances: Option<u8>— max concurrent instancescron: String— cron expressioninterval_ms: u32— interval-based schedulingstart_time: u32— window start (Unix epoch, 0=always)end_time: u32— window end (Unix epoch, 0=forever)Files to Modify/Create
crates/zinit_lib/Cargo.tomlcron_tab+chronodepscrates/zinit_server/Cargo.tomlcron_tab+chronodepscrates/zinit_server/src/scheduler.rscrates/zinit_server/src/lib.rscrates/zinit_server/src/main.rscrates/zinit_server/src/rpc/schedule.rscrates/zinit_server/src/rpc/mod.rscrates/zinit_server/src/web.rscrates/zinit_server/openrpc.jsoncrates/zinit_lib/src/db/actions/model.rscrates/zinit/src/cli/args.rscrates/zinit/src/cli/commands.rsImplementation Plan
Step 1: Add
cron_tab+chronodependenciesDependencies: none
Step 2: Add cron validation to
SchedulePolicyDependencies: Step 1
Step 3: Create Scheduler module (
scheduler.rs)Schedulerstruct withArc<ZinitDb>ScheduleEntrytracking structcron_tabnr_of_instancescapDependencies: Step 2
Step 4: Register and spawn scheduler in server
pub mod scheduler;to lib.rsDependencies: Step 3
Step 5: Add RPC handlers (
schedule.list,schedule.status)rpc/schedule.rswith handlersrpc/mod.rsdispatchpositional_to_namedin web.rsDependencies: Step 4
Step 6: Update OpenRPC specification
schedule.listandschedule.statusmethodsScheduleInfoandScheduleStatusschemasDependencies: Step 5
Step 7: Add integration tests
nr_of_instancescap worksDependencies: Step 4
Step 8: Add CLI command
zinit schedulesSchedulesvariant to CLI argsschedule.listRPCDependencies: Step 5
Acceptance Criteria
nr_of_instanceslimits concurrent jobsstart_time/end_time) respectedschedule.listRPC returns all scheduled actionsschedule.statusRPC returns detailed infozinit schedulesCLI displays scheduled actionsNotes
cron_tabcrate as requestedSchedulePolicyalready inActionSpecJSONTest Results
New Scheduler Tests (9)
test_normalize_cron_5_field— 5-field cron normalizationtest_normalize_cron_6_field— 6-field cron normalizationtest_normalize_cron_7_field— 7-field cron passthroughtest_cron_parsing_valid— valid cron parsingtest_cron_parsing_every_5_minutes— every-5-minutes crontest_cron_parsing_invalid— invalid cron rejectiontest_schedule_policy_cron_set— cron policy creationtest_schedule_policy_interval_set— interval policy creationtest_cron_next_from— next cron execution time calculationImplementation Summary
Files Created (3)
crates/zinit_server/src/scheduler.rs— Core scheduler module with 1-second tick loopcrates/zinit_server/src/rpc/schedule.rs— RPC handlers forschedule.listandschedule.statusFiles Modified (10)
Cargo.toml— Addedcron_tab,cron,chronoworkspace depscrates/zinit_server/Cargo.toml— Added scheduler depscrates/zinit_lib/src/db/actions/model.rs— Addedlist_actions_with_context()crates/zinit_lib/src/db/factory.rs— AddedActionsApi::list_with_context()crates/zinit_server/src/lib.rs— Registeredpub mod schedulercrates/zinit_server/src/main.rs— Spawns scheduler alongside supervisorcrates/zinit_server/src/rpc/mod.rs— Addedschedule.*dispatch routescrates/zinit_server/src/web.rs— Added positional-to-named param mappingscrates/zinit_server/openrpc.json— Addedschedule.list,schedule.statusmethods + schemascrates/zinit/src/cli/args.rs+commands.rs+main.rs— Addedzinit schedulesCLI command