From 1b45cdccf9a03df318af09dedced4516fc43b3f9 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Tue, 16 Apr 2024 14:41:05 +1000 Subject: [PATCH] feat: add cronjobs go module (#29) --- go/cronjobs/cronjobs.go | 34 ++++++++++++++++++++++++++++++++++ go/cronjobs/ftl.toml | 2 ++ go/cronjobs/go.mod | 5 +++++ go/cronjobs/go.sum | 0 4 files changed, 41 insertions(+) create mode 100644 go/cronjobs/cronjobs.go create mode 100644 go/cronjobs/ftl.toml create mode 100644 go/cronjobs/go.mod create mode 100644 go/cronjobs/go.sum diff --git a/go/cronjobs/cronjobs.go b/go/cronjobs/cronjobs.go new file mode 100644 index 00000000..40df989c --- /dev/null +++ b/go/cronjobs/cronjobs.go @@ -0,0 +1,34 @@ +//ftl:module cronjobs +package cronjobs + +import ( + "context" + "fmt" + "time" +) + +//ftl:cron */10 * * * * * * +func EveryTenSeconds(ctx context.Context) error { + fmt.Printf("Every ten seconds: %d\n", time.Now().Second()) + return nil +} + +//ftl:cron 0 * * * * * * +func EveryMinute(ctx context.Context) error { + fmt.Printf("Every minute %v\n", time.Now().Minute()) + return nil +} + +//ftl:cron 0 0 0 * * * * +func EveryDay(ctx context.Context) error { + fmt.Printf("Every day\n") + return nil +} + +//ftl:cron */3 * * * * * * +func LongAndFrequentCronJob(ctx context.Context) error { + fmt.Printf("Long and frequent: Started\n") + time.Sleep(time.Second * 30) + fmt.Printf("Long and frequent: Ended\n") + return nil +} diff --git a/go/cronjobs/ftl.toml b/go/cronjobs/ftl.toml new file mode 100644 index 00000000..77c815f7 --- /dev/null +++ b/go/cronjobs/ftl.toml @@ -0,0 +1,2 @@ +module = "cronjobs" +language = "go" diff --git a/go/cronjobs/go.mod b/go/cronjobs/go.mod new file mode 100644 index 00000000..1c549a8d --- /dev/null +++ b/go/cronjobs/go.mod @@ -0,0 +1,5 @@ +module ftl/cronjobs + +go 1.22.2 + +replace github.com/TBD54566975/ftl => ../../../ftl diff --git a/go/cronjobs/go.sum b/go/cronjobs/go.sum new file mode 100644 index 00000000..e69de29b