mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-22 15:53:45 +00:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package workflows
|
|
|
|
import (
|
|
"time"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/activities"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
type HealthcheckWorkflowParam struct {
|
|
Script string
|
|
Slug string
|
|
}
|
|
|
|
func (w *Workflows) HealthcheckWorkflowDefinition(ctx workflow.Context, param HealthcheckWorkflowParam) error {
|
|
options := workflow.ActivityOptions{
|
|
StartToCloseTimeout: 10 * time.Second,
|
|
}
|
|
ctx = workflow.WithActivityOptions(ctx, options)
|
|
|
|
heatlcheckParam := activities.HealtcheckParam{
|
|
Script: param.Script,
|
|
}
|
|
|
|
var healthcheckResult *activities.HealthcheckResult
|
|
err := workflow.ExecuteActivity(ctx, w.activities.Healthcheck, heatlcheckParam).Get(ctx, &healthcheckResult)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
status := "failure"
|
|
if healthcheckResult.Success {
|
|
status = "success"
|
|
}
|
|
|
|
historyParam := activities.HealtcheckAddToHistoryParam{
|
|
Slug: param.Slug,
|
|
Status: status,
|
|
Note: healthcheckResult.Note,
|
|
}
|
|
|
|
var historyResult *activities.HealthcheckAddToHistoryResult
|
|
err = workflow.ExecuteActivity(ctx, w.activities.HealthcheckAddToHistory, historyParam).Get(ctx, &historyResult)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|