feat(scheduler): implement P3 S-SCHEDULER-01..04 Scheduler engine, calendar/DST, and SchedulerStorage durable store
This commit is contained in:
1 parent
ec8c0bd40a
commit
aaeab50758
15 files changed
+4694
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#include <Void/Scheduler/Scheduler.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
int main()
|
||||
{
|
||||
Void::Time::ManualClock mono{};
|
||||
auto sched = Void::Scheduler::Scheduler::create(
|
||||
Void::Scheduler::SchedulerOptions{.monotonic_clock = &mono});
|
||||
if (!sched.has_value()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int ran = 0;
|
||||
if (!sched->register_handler(
|
||||
"ping",
|
||||
[&](const Void::Scheduler::OccurrenceContext&,
|
||||
std::span<const std::byte>,
|
||||
Void::Async::OperationOptions)
|
||||
-> Void::Scheduler::Result<void> {
|
||||
++ran;
|
||||
return {};
|
||||
})
|
||||
.has_value()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
Void::Scheduler::JobSpec spec{};
|
||||
spec.id = "j1";
|
||||
spec.handler_id = "ping";
|
||||
spec.schedule = Void::Scheduler::Schedule::one_shot_monotonic(mono.now());
|
||||
if (!sched->add_job(spec).has_value()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto count = sched->tick();
|
||||
if (!count.has_value() || *count != 1U || ran != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!sched->close_and_join().has_value()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user