2024-05-23 16:33:30 +00:00
|
|
|
package activities
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log/slog"
|
|
|
|
|
|
|
|
"github.com/mentos1386/zdravko/internal/temporal"
|
|
|
|
"github.com/mentos1386/zdravko/pkg/k6"
|
2024-05-24 20:22:19 +00:00
|
|
|
"github.com/mentos1386/zdravko/pkg/k6/zdravko"
|
2024-05-23 16:33:30 +00:00
|
|
|
"github.com/mentos1386/zdravko/pkg/script"
|
2024-05-25 08:24:05 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2024-05-23 16:33:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *Activities) Check(ctx context.Context, param temporal.ActivityCheckParam) (*temporal.ActivityCheckResult, error) {
|
|
|
|
execution := k6.NewExecution(slog.Default(), script.UnescapeString(param.Script))
|
|
|
|
|
2024-05-25 08:24:05 +00:00
|
|
|
var metadata map[string]interface{}
|
|
|
|
err := yaml.Unmarshal([]byte(param.Target.Metadata), &metadata)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-24 20:22:19 +00:00
|
|
|
ctx = zdravko.WithZdravkoContext(ctx, zdravko.Context{
|
|
|
|
Target: zdravko.Target{
|
2024-05-25 08:24:05 +00:00
|
|
|
Name: param.Target.Name,
|
|
|
|
Group: param.Target.Group,
|
|
|
|
Metadata: metadata,
|
2024-05-24 20:22:19 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
result, err := execution.Run(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &temporal.ActivityCheckResult{Success: result.Success, Note: result.Note}, nil
|
|
|
|
}
|