英文:
How to schedule multiple cron workflows in temporal?
问题
考虑到一个字符串数组作为输入,我的目标是为每个字符串安排cron作业。我尝试创建自定义的工作流选项并执行相同的操作,对于每个输入的迭代。按照这种方式,只有第一个cron工作流被安排,而其他cron作业则无限期等待。
for ind , sid := range ss_ids {
var cronScheduleStr string
if ind == 0 {
cronScheduleStr = "* * * * *"
}
if ind == 1 {
cronScheduleStr = "2 * * * *"
}
workflowID := "cron_" + sid
workflowOptions := client.StartWorkflowOptions{
ID: workflowID,
TaskQueue: "cron",
CronSchedule: cronScheduleStr,
}
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, cron.SampleCronWorkflow,sid)
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}
log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
}
除此之外,我也尝试了相同的方式使用子工作流,但只有第一个cron子工作流被安排。如果有人能帮忙,将非常感激。
英文:
Considering an array of strings as input, my aim is to schedule cron jobs for each. I have tried creating custom workflow options and executing the same, for each iteration of input. Following this only the first cron workflow gets scheduled while other cron jobs wait indefinetely.
for ind , sid := range ss_ids {
var cronScheduleStr string
if ind == 0 {
cronScheduleStr = "* * * * *"
}
if ind == 1 {
cronScheduleStr = "2 * * * *"
}
workflowID := "cron_" + sid
workflowOptions := client.StartWorkflowOptions{
ID: workflowID,
TaskQueue: "cron",
CronSchedule: cronScheduleStr,
}
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, cron.SampleCronWorkflow,sid)
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}
log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
}
Apart from this I have tried child workflows in the same manner, but that also schedules only the first cron child workflow. It would be very kind, if someone can help out.
答案1
得分: 2
如果ss_ids
是唯一的,第一个应该每分钟运行一次,第二个应该在每小时的第二分钟运行,其余的将使用CronSchedule: ''
。
英文:
If ss_ids
are unique, the first one should run every minute, the second one should run at the second minute of every hour, and the rest will have CronSchedule: ''
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论