botify-labs / simpleflow

Python library for dataflow programming.
https://botify-labs.github.com/simpleflow/
MIT License
68 stars 24 forks source link

New workflow versions are not registered #132

Open frncmx opened 7 years ago

frncmx commented 7 years ago

Hi,

We noticed if we start simpleflow like follows:

simpleflow decider.start --domain testdomain --task-list test examples.basic.BasicWorkflow
simpleflow worker.start --domain testdomain --task-list quickstart examples.basic.BasicWorkflow

... then the new workflow version is not registered. Only, when I call workflow.start, but currently we don't do that.

We do something like follows:

From the Jenkins node, I decided to use AWS CLI to start the workflow. Why? That seemed like a good idea, since based on the docs, that was pretty simple to restrict IAM to provide only the necessary permissions to SWF, i.e., Jenkins only can start workflows with specific tags.

However, that way the workflow is not registered. Jenkins currently don't even have the permission to register a new workflow.

What do you think? Wouldn't be a good idea to register new workflow versions from the decider?

ybastide commented 7 years ago

Hi!

Something like this? (Totally untested)

diff --git a/simpleflow/command.py b/simpleflow/command.py
index e04b673..26aad1d 100644
--- a/simpleflow/command.py
+++ b/simpleflow/command.py
@@ -334,6 +334,10 @@ def task_info(ctx, domain, workflow_id, task_id, details):
     print(with_format(ctx)(helpers.get_task)(domain, workflow_id, task_id, details))

+@click.option('--create/--no-create',
+              default=False,
+              help='Create workflows as needed.'
+              )
 @click.option('--nb-processes', '-N', type=int)
 @click.option('--log-level', '-l')
 @click.option('--task-list')
@@ -343,11 +347,19 @@ def task_info(ctx, domain, workflow_id, task_id, details):
               help='SWF Domain')
 @click.argument('workflows', nargs=-1, required=True)
 @cli.command('decider.start', help='Start a decider process to manage workflow executions.')
-def start_decider(workflows, domain, task_list, log_level, nb_processes):
+def start_decider(workflows, domain, task_list, log_level, nb_processes, create):
     if log_level:
         logger.warning(
             "Deprecated: --log-level will be removed, use LOG_LEVEL environment variable instead"
         )
+
+    if create:
+        domain_model = swf.models.Domain(domain)
+        query = swf.querysets.WorkflowTypeQuerySet(domain_model)
+        for workflow in workflows:
+            workflow_definition = get_workflow(workflow)
+            query.get_or_create(workflow_definition.name, workflow_definition.version)
+
     decider.command.start(
         workflows,
         domain,