2024-02-16 12:07:29 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
2024-02-16 12:41:18 +00:00
|
|
|
"fmt"
|
2024-02-16 12:07:29 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/activities"
|
|
|
|
"go.temporal.io/sdk/workflow"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HealthcheckHttpWorkflowParam struct {
|
2024-02-16 12:41:18 +00:00
|
|
|
Url string
|
|
|
|
Method string
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2024-02-16 12:41:18 +00:00
|
|
|
Url: param.Url,
|
|
|
|
Method: param.Method,
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 19:19:18 +00:00
|
|
|
var result *activities.HealthcheckHttpResult
|
|
|
|
err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttp, activityParam).Get(ctx, &result)
|
2024-02-16 12:41:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.StatusCode != 200 {
|
|
|
|
return fmt.Errorf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", result.StatusCode, param.Url)
|
|
|
|
}
|
2024-02-16 12:07:29 +00:00
|
|
|
|
2024-02-16 12:41:18 +00:00
|
|
|
return nil
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|