Activities
Activities are implemented as methods on a Go struct
that satisfies the generated <Service>Activities
interface type generated by this plugin
- Go
- Schema
main.go
package main
import (
"context"
examplev1 "path/to/gen/example/v1"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
)
type Activities struct {}
func (a *Activities) Hello(ctx context.Context, input *examplev1.HelloInput) (*examplev1.HelloOutput, error) {
return &examplev1.HelloOutput{}, nil
}
func main() {
c, _ := client.Dial(client.Options{})
w := worker.New(c, examplev1.ExampleTaskQueue, worker.Options{})
// Register all example.v1.Example activities with the worker
examplev1.RegisterExampleActivities(w, &Activities{})
w.Run(worker.InterruptCh())
}
example.proto
syntax="proto3";
package example.v1;
import "temporal/v1/temporal.proto";
service Example {
option (temporal.v1.service).task_queue = "example-v1";
// Hello returns a friendly greeting
rpc Hello(HelloInput) returns (HelloOutput) {
option (temporal.v1.activity) = {
start_to_close_timeout: { seconds: 60 }
};
}
}