2024-02-16 21:31:00 +00:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/activities"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/config"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/temporal"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/workflows"
|
|
|
|
"go.temporal.io/sdk/worker"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Worker struct {
|
|
|
|
worker worker.Worker
|
|
|
|
cfg *config.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWorker(cfg *config.Config) (*Worker, error) {
|
|
|
|
return &Worker{
|
|
|
|
cfg: cfg,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Worker) Name() string {
|
|
|
|
return "Temporal Worker"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Worker) Start() error {
|
|
|
|
temporalClient, err := temporal.ConnectToTemporal(w.cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new Worker
|
|
|
|
// TODO: Maybe identify by region or something?
|
|
|
|
w.worker = worker.New(temporalClient, "default", worker.Options{})
|
|
|
|
|
|
|
|
// Register Workflows
|
|
|
|
w.worker.RegisterWorkflow(workflows.HealthcheckHttpWorkflowDefinition)
|
|
|
|
|
|
|
|
// Register Activities
|
2024-02-17 19:19:18 +00:00
|
|
|
w.worker.RegisterActivity(activities.HealthcheckHttp)
|
2024-02-16 21:31:00 +00:00
|
|
|
|
|
|
|
return w.worker.Run(worker.InterruptCh())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Worker) Stop() error {
|
|
|
|
w.worker.Stop()
|
|
|
|
return nil
|
|
|
|
}
|