Skip to content

Commit

Permalink
feat: add cron go+java examples
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed Oct 1, 2024
1 parent e018a6c commit e42d625
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 2 deletions.
19 changes: 19 additions & 0 deletions examples/go/cron/cron.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cron

import (
"context"

"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
)

//ftl:cron 10s
func TenSeconds(ctx context.Context) error {
ftl.LoggerFromContext(ctx).Infof("Frequent cron job triggered.")
return nil
}

//ftl:cron 0 * * * *
func Hourly(ctx context.Context) error {
ftl.LoggerFromContext(ctx).Infof("Hourly cron job triggered.")
return nil
}
2 changes: 2 additions & 0 deletions examples/go/cron/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "cron"
language = "go"
49 changes: 49 additions & 0 deletions examples/go/cron/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module ftl/cron

go 1.23.1

require github.com/TBD54566975/ftl v1.1.5

require (
connectrpc.com/connect v1.16.2 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/hashicorp/cronexpr v1.1.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/swaggest/jsonschema-go v0.3.72 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.5 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/TBD54566975/ftl => /Users/safeer/dev/ftl
224 changes: 224 additions & 0 deletions examples/go/cron/go.sum

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions examples/go/cron/types.ftl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/go/echo/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ftl/echo

go 1.23.0
go 1.23.1

replace github.com/TBD54566975/ftl => ../../..

Expand Down
2 changes: 1 addition & 1 deletion examples/go/time/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ftl/time

go 1.23.0
go 1.23.1

replace github.com/TBD54566975/ftl => ../../..

Expand Down
2 changes: 2 additions & 0 deletions examples/java/cron/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "cron"
language = "java"
14 changes: 14 additions & 0 deletions examples/java/cron/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ftl.com.example</groupId>
<artifactId>cron</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-build-parent-java</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

</project>
17 changes: 17 additions & 0 deletions examples/java/cron/src/main/java/com/example/CronSink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example;

import io.quarkus.logging.Log;
import xyz.block.ftl.Cron;

public class CronSink {

@Cron("10s")
public void cron10s() {
Log.infof("Frequent cron job triggered");
}

@Cron("0 * * * * ")
public void cronHourly() {
Log.infof("Hourly cron job triggered");
}
}

0 comments on commit e42d625

Please sign in to comment.