mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-22 15:53:45 +00:00
38 lines
931 B
Go
38 lines
931 B
Go
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)
|
|
|
|
activityParam := activities.HealtcheckHttpActivityParam{
|
|
Url: param.Url,
|
|
Method: param.Method,
|
|
}
|
|
|
|
var result *activities.HealthcheckHttpActivityResult
|
|
err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttpActivityDefinition, 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
|
|
}
|