2024-02-16 12:07:29 +00:00
|
|
|
package activities
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-21 13:09:22 +00:00
|
|
|
"log/slog"
|
2024-02-16 12:07:29 +00:00
|
|
|
"net/http"
|
2024-02-21 09:06:54 +00:00
|
|
|
|
|
|
|
"code.tjo.space/mentos1386/zdravko/pkg/k6"
|
2024-02-16 12:07:29 +00:00
|
|
|
)
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
type HealtcheckParam struct {
|
|
|
|
Script string
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
type HealthcheckResult struct {
|
2024-02-16 12:41:18 +00:00
|
|
|
StatusCode int
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
func Healthcheck(ctx context.Context, param HealtcheckParam) (*HealthcheckResult, error) {
|
2024-02-16 12:07:29 +00:00
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
statusCode := http.StatusOK // FIXME
|
2024-02-16 12:07:29 +00:00
|
|
|
|
2024-02-21 13:09:22 +00:00
|
|
|
execution := k6.NewExecution(slog.Default(), param.Script)
|
2024-02-16 12:07:29 +00:00
|
|
|
|
2024-02-21 13:16:22 +00:00
|
|
|
err := execution.Run(ctx)
|
2024-02-16 12:07:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
return &HealthcheckResult{StatusCode: statusCode}, nil
|
2024-02-17 19:19:18 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
type HealtcheckAddToHistoryParam struct {
|
2024-02-17 19:19:18 +00:00
|
|
|
Id string
|
|
|
|
Success bool
|
|
|
|
StatusCode int
|
|
|
|
}
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
type HealthcheckAddToHistoryResult struct {
|
2024-02-17 19:19:18 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
func HealthcheckAddToHistory(ctx context.Context, param HealtcheckAddToHistoryParam) (*HealthcheckAddToHistoryResult, error) {
|
2024-02-17 19:19:18 +00:00
|
|
|
|
2024-02-21 09:06:54 +00:00
|
|
|
return &HealthcheckAddToHistoryResult{}, nil
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|