[go: up one dir, main page]

Tezt/Cloud: introduce Chronos, a cron-like scheduler

What

This MR introduces a new cron-like scheduler implementation in OCaml that allows scheduling tasks using a simplified cron syntax. The scheduler supports basic time-based task execution with single values and wildcards for minute, hour, day, month, and day of week specifications.

Why

A scheduler is essential for executing periodic tasks in a predictable manner. This implementation provides a lightweight alternative to system cron for scheduling needs UTC-based scheduling.

How

A simple polling mechanism that checks tasks to be performed every minute.

Manually testing the MR

Integration will be done a later MR, once it is actually used.

In the meantime, one can try the implementation using the following code in a separate project.

let scheduler = Chronos.zero ()

let () =
  Chronos.register scheduler ~tm:"* * * * *" ~action:(fun () ->
         let now = Unix.gmtime (Unix.time ())  in
         let min = now.tm_min in
         let hour = now.tm_hour in
         Lwt_io.printlf "[%d %d]: task executed" min hour)

let () = 
    Lwt_main.run (
        let () = Lwt.async (fun () ->
            Lwt_unix.sleep 300. >>= fun () ->
            Chronos.shutdown scheduler;
            Lwt.return_unit
        ) in
        Chronos.start scheduler
    )

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Paul Laforgue

Merge request reports

Loading