Search code examples
goworkflowcadence-workflow

Cadence register workflows and activities separately


I have a network of multiple machines, and I'm using cadence go client.

Machine 1 needs to register activities.

// Machine 1 registering activities
func sampleActivity(ctx context.Context) (string, error) {
    logger := activity.GetLogger(ctx)
    logger.Info("separate machines are handling this")
    return "Activity machine succeeded"
}
func main() {
     activity.RegisterWithOptions(sampleActivity, RegisterOptions{Name: "Machine1Activity"})
}

Machine 2 needs to register workflows.

// Machine 2 registering workflows
func sample_workflow(ctx workflow.Context, name string) (string, error) {
     ...
     err := workflow.ExecuteActivity(ctx, "Machine1Activity")
     ...
}

func main() {
    workflow.RegisterWithOptions(sampleWorkflow, "Machine2Workflow")
}

Machine 3 needs to launch to start the workflow.

// Machine 3 starting the workflow

// Prepare options and ctx

client.StartWorkflow(ctx, options, "Machine2Workflow", "Machine1Activity")

The cadence-fronted service is on another machine.

How can I do this with the go client? Also does the register only save the workflow/activity in memory? How can I push them to the cadence service, so that other machines can find them as well.


Solution

  • Currently registration is purely local to a specific worker perocess. We plan to add some sort of metadata service with catalog of activity and workflow types in the future.

    To disable workflow worker on machine 1 specify WorkerOptions.DisableWorkflowWorker.

    To disable activity worker on machine 2 specify WorkerOptions.DisableActivityWorker.

    There is no need to register anything on the machine 3.