Created
August 13, 2023 03:32
-
-
Save FCO/ab69aec57d9d733c0d55dd07a8769a2c to your computer and use it in GitHub Desktop.
This file contains 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
use App::RakuCron::Configuration; | |
use App::RakuCron::Rule; | |
use Lumberjack; | |
sub print-example(Str $msg = "Generic message", :$rule, +@params, :$time, :$delta-secs = "None", :$something-else = "") { | |
$rule.log-warn: "$msg (@params[]) ({ $something-else }): ", $time.hh-mm-ss, " -> { $delta-secs }" | |
} | |
Lumberjack.dispatchers = [ | |
Lumberjack::Dispatcher::Console.new: :colour | |
]; | |
config { | |
.log-level = Lumberjack::Level::Debug; | |
# every Mon/Web/Fri at 10:00:00 | |
.run-at: :10hours, :wday<Mon Wed Fri>, { shell "ls -la" } | |
# every work day at every hour | |
.run-at: :wday(2..6), :hours(*), { say "running!" } | |
# every even day at 00:00 and 00:30 | |
.run-at: :day(* %% 2), :0hours, :minutes[0, 30], { say "running!" } | |
# half in half hour in August | |
.run-at: :month<Aug>, :minutes[0, 30], -> :$rule { $rule.log-warn: "running!" } | |
# run every minute | |
.run-at: :name("every minute"), :min(*), :capture(\("every minute", :something-else(42))), &print-example; | |
# Every other hour | |
.run-at: :name("every other hour"), :2delta-hours, :capture("every other hour", "bla", "ble"), &print-example; | |
# It can create multiple rules on a single call using arrays of captures | |
.run-at: | |
:name("one each 5 secs"), | |
[ | |
\( :secs(* %% 10) ), # Every second divisible by 10 | |
\( :secs((* + 5) %% 10), :capture("between 10") ), # Every second divisible by 10 (5 secs after the other one) | |
], &print-example | |
; | |
# .run-at: :2delta-secs, { die "something went wrong (as expected)" }; | |
# Or call it a single time passing a single array | |
.run-at: [ | |
\( :10hours, :wday<Mon Wed Fri>, { shell "ls -la" } ), | |
\( :wday(2..6), :hours(*), { say "running!" } ), | |
\( :day(* %% 2), :0hours, :minutes[0, 30], { say "running!" } ), | |
\( :month<Jan>, :minutes[0, 30], { say "running!" } ), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment