generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: exemplar scaffolding and integration test 1/3 (#2763)
Exemplar scaffolding with three modules that tests the features: config, ingress, verb calls, pubsub, fsm, cron (java)
- Loading branch information
Showing
14 changed files
with
743 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module = "origin" | ||
language = "go" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module ftl/origin | ||
|
||
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/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-20240808152545-0cdaa3abc0fa // 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package origin | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"ftl/builtin" | ||
|
||
"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK. | ||
) | ||
|
||
var nonce = ftl.Config[string]("nonce") | ||
|
||
//ftl:export | ||
var AgentBroadcast = ftl.Topic[Agent]("agentBroadcast") | ||
|
||
type Agent struct { | ||
ID int `json:"id"` | ||
Alias string `json:"alias"` | ||
LicenseToKill bool `json:"license_to_kill"` | ||
HiredAt time.Time `json:"hired_at"` | ||
BriefedAt ftl.Option[time.Time] `json:"briefed_at"` | ||
} | ||
|
||
type PostAgentResponse struct { | ||
ID int `json:"id"` | ||
} | ||
|
||
type PostAgentErrorResponse string | ||
|
||
//ftl:ingress POST /http/agent | ||
func PostAgent(ctx context.Context, req builtin.HttpRequest[Agent, ftl.Unit, ftl.Unit]) (builtin.HttpResponse[PostAgentResponse, PostAgentErrorResponse], error) { | ||
agent := Agent{ | ||
ID: req.Body.ID, | ||
Alias: req.Body.Alias, | ||
LicenseToKill: req.Body.LicenseToKill, | ||
HiredAt: req.Body.HiredAt, | ||
} | ||
AgentBroadcast.Publish(ctx, agent) | ||
return builtin.HttpResponse[PostAgentResponse, PostAgentErrorResponse]{ | ||
Status: 201, | ||
Body: ftl.Some(PostAgentResponse{ID: agent.ID}), | ||
}, nil | ||
} | ||
|
||
// Exported verb | ||
|
||
type GetNonceRequest struct{} | ||
type GetNonceResponse struct{ Nonce string } | ||
|
||
//ftl:verb export | ||
func GetNonce(ctx context.Context, req GetNonceRequest) (GetNonceResponse, error) { | ||
return GetNonceResponse{Nonce: nonce.Get(ctx)}, nil | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module = "pulse" | ||
language = "java" |
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
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>pulse</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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.example; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import ftl.origin.GetNonceClient; | ||
import ftl.origin.GetNonceRequest; | ||
import ftl.origin.GetNonceResponse; | ||
import ftl.relay.GetLogFileClient; | ||
import ftl.relay.GetLogFileRequest; | ||
import ftl.relay.GetLogFileResponse; | ||
import io.quarkus.logging.Log; | ||
import xyz.block.ftl.Cron; | ||
|
||
public class Pulse { | ||
|
||
@Cron("1s") | ||
public void cron10s(GetNonceClient getNonceClient, GetLogFileClient getLogFileClient) throws Exception { | ||
GetNonceResponse nr = getNonceClient.call(new GetNonceRequest()); | ||
GetLogFileResponse lfr = getLogFileClient.call(new GetLogFileRequest()); | ||
Log.infof("Cron job triggered, nonce %s, log file: %s", nr.getNonce(), lfr.getPath()); | ||
appendLog(lfr.getPath(), "cron %s", nr.getNonce()); | ||
} | ||
|
||
public static void appendLog(String path, String msg, Object... args) { | ||
try (FileWriter writer = new FileWriter(path, true)) { | ||
writer.write(String.format(msg + "%n", args)); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error writing to log file", e); | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module = "relay" | ||
language = "go" |
Oops, something went wrong.