You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
9 months ago
|
package commands
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"log"
|
||
|
"time"
|
||
|
|
||
|
"git.cheetah.cat/archivinator-ng/workerclient/common"
|
||
|
grabber "git.cheetah.cat/archivinator-ng/workerclient/downloader"
|
||
|
"go.temporal.io/api/enums/v1"
|
||
|
"go.temporal.io/sdk/client"
|
||
|
)
|
||
|
|
||
|
type KickstartCommand struct {
|
||
|
//Token string `long:"token" description:"authenticate with this token"`
|
||
|
}
|
||
|
|
||
|
func (command *KickstartCommand) Execute(args []string) error {
|
||
|
ctx := context.Background()
|
||
|
|
||
|
c, err := client.Dial(client.Options{
|
||
|
HostPort: common.WorkerSettings.TemporalHost,
|
||
|
Namespace: common.WorkerSettings.TemporalNS,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalln("Unable to create client", err)
|
||
|
}
|
||
|
defer c.Close()
|
||
|
|
||
|
// @@@SNIPSTART samples-go-schedule-create-delete
|
||
|
// This schedule ID can be user business logic identifier as well.
|
||
|
scheduleID := "schedule_periodic_fetch"
|
||
|
workflowID := "RequestProcessingWorkflow"
|
||
|
// Create the schedule, start with no spec so the schedule will not run.
|
||
|
scheduleHandle, err := c.ScheduleClient().Create(ctx, client.ScheduleOptions{
|
||
|
ID: scheduleID,
|
||
|
Spec: client.ScheduleSpec{
|
||
|
Intervals: []client.ScheduleIntervalSpec{
|
||
|
{
|
||
|
Every: 1 * time.Minute,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
Action: &client.ScheduleWorkflowAction{
|
||
|
ID: workflowID,
|
||
|
Workflow: grabber.RequestProcessingWorkflow,
|
||
|
TaskQueue: "request-grabber",
|
||
|
},
|
||
|
Overlap: enums.SCHEDULE_OVERLAP_POLICY_SKIP,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalln("Unable to create schedule", err)
|
||
|
}
|
||
|
log.Println("Created Schedule", scheduleHandle.GetID())
|
||
|
/*
|
||
|
// Delete the schedule once the sample is done
|
||
|
defer func() {
|
||
|
log.Println("Deleting schedule", "ScheduleID", scheduleHandle.GetID())
|
||
|
err = scheduleHandle.Delete(ctx)
|
||
|
if err != nil {
|
||
|
log.Fatalln("Unable to delete schedule", err)
|
||
|
}
|
||
|
}()
|
||
|
*/
|
||
|
// @@@SNIPEND
|
||
|
|
||
|
/*
|
||
|
// @@@SNIPSTART samples-go-schedule-trigger
|
||
|
// Manually trigger the schedule once
|
||
|
log.Println("Manually triggering schedule", "ScheduleID", scheduleHandle.GetID())
|
||
|
|
||
|
err = scheduleHandle.Trigger(ctx, client.ScheduleTriggerOptions{
|
||
|
Overlap: enums.SCHEDULE_OVERLAP_POLICY_SKIP,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalln("Unable to trigger schedule", err)
|
||
|
}
|
||
|
// @@@SNIPEND
|
||
|
|
||
|
*/
|
||
|
return nil
|
||
|
}
|