zdravko/internal/workflows/healthcheck.go

39 lines
897 B
Go
Raw Normal View History

package workflows
import (
"fmt"
"time"
"code.tjo.space/mentos1386/zdravko/internal/activities"
"go.temporal.io/sdk/workflow"
)
type HealthcheckHttpWorkflowParam struct {
Url string
Method string
}
func HealthcheckHttpWorkflowDefinition(ctx workflow.Context, param HealthcheckHttpWorkflowParam) error {
options := workflow.ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, options)
2024-02-17 19:19:18 +00:00
activityParam := activities.HealtcheckHttpParam{
Url: param.Url,
Method: param.Method,
}
2024-02-17 19:19:18 +00:00
var result *activities.HealthcheckHttpResult
err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttp, activityParam).Get(ctx, &result)
if err != nil {
return err
}
if result.StatusCode != 200 {
return fmt.Errorf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", result.StatusCode, param.Url)
}
return nil
}