Execute workflow immediately and then via Cron?

I’m working on scheduling a task to run every 15 minutes. This isn’t a problem with @every 15m. But the first task waits 15 minutes. Can I execute it right away? Or do I have to execute one separately?

Here’s what I’m doing with the cron right now:

	wf, err := tp.ExecuteWorkflow(ctx, tpclient.StartWorkflowOptions{
		ID:                       wfID,
		TaskQueue:                "queue",
		CronSchedule:             "@every 15m",
		WorkflowExecutionTimeout: time.Hour * 24, // fail after 1 day
	}, workflows.ManageThings, wfReq)

You are correct if you start your workflow exec with a cron schedule the first execution is going to be created and started right away but your workflow code exec won’t start till the cron timer fires.

One way you could do this is:

  1. Start your wf execution without setting cron, have workflow function take for example some boolean “isfirst” param, set it to true

  2. Before your workflow completes check isFirst flag, if true start async child workflow (of the same workflow type) with abandoned parent close policy (see here for more info on that) and set the CronSchedule in ChildWorkflowOptions. Also pass false as isFirst so wf code will bypass starting the child workflow again.

This way you would have an execution right away and then again according to the set CronSchedule in ChildWorkflowOptions.