如何在Temporal中安排多个cron工作流程?

huangapple go评论79阅读模式
英文:

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: ''.

huangapple
  • 本文由 发表于 2022年2月16日 04:49:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/71133216.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定