Thin, easy-to-use API wrappers for Temporal workflows that use Timpani.
This package is not required in order to use Timpani. However, it saves time, simplifies code, minimizes duplication, and prevents mistakes.
Timpani is a Temporal worker that sends API calls and receives asynchronous event notifications to/from various well-known third-party services.
First, when your Temporal worker starts, initialize the activity options for all Timpani activities.
import (
"github.com/tzrikka/timpani-api/pkg/temporal"
"go.temporal.io/sdk/workflow"
)
temporal.ActivityOptions = temporal.DefaultActivityOptions("timpani")
// Or:
temporal.ActivityOptions = &workflow.ActivityOptions{ /* ... */ }This is especially important if you changed your Timpani worker's task queue name to something other than the default "timpani".
Note that the package's defaults are DefaultActivityOptions("timpani"), i.e.:
workflow.ActivityOptions{
TaskQueue: "timpani",
StartToCloseTimeout: 5 * time.Second,
RetryPolicy: &temporal.RetryPolicy{
MaximumAttempts: 5,
},
}Now you can call any *Activity() function from any timpani-api subpackage, for example:
import "github.com/tzrikka/timpani-api/pkg/slack"
bot, err := slack.BotsInfoActivity(ctx, botID)You may also call Temporal's workflow.ExecuteActivity() function directly, and just use the following from any timpani-api subpackage:
*ActivityNamestring as theactivityparameter*Requeststruct as theargsparameter- Reference to an empty
*Responsestruct as thevaluePtrparameter inworkflow.Future.Get()calls
Example:
import (
"github.com/tzrikka/timpani-api/pkg/slack"
"go.temporal.io/sdk/workflow"
)
func SlackBotInfo(ctx workflow.Context, botID string) (*slack.Bot, error) {
req := slack.BotsInfoRequest{Bot: botID}
opts := workflow.ActivityOptions{ /* ... */ }
actx := workflow.WithActivityOptions(ctx, opts)
fut := workflow.ExecuteActivity(actx, slack.BotsInfoActivityName, req)
resp := new(slack.BotsInfoResponse)
if err := fut.Get(ctx, resp); err != nil {
return nil, err
}
return resp.Bot, nil
}