-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2118c61
commit a533a7a
Showing
8 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from writer.abstract import register_abstract_template | ||
from writer.ss_types import AbstractTemplate | ||
from writer.workflows_blocks.blocks import WorkflowBlock | ||
import writer.workflows | ||
|
||
class ForEach(WorkflowBlock): | ||
|
||
@classmethod | ||
def register(cls, type: str): | ||
super(ForEach, cls).register(type) | ||
register_abstract_template(type, AbstractTemplate( | ||
baseType="workflows_node", | ||
writer={ | ||
"name": "For-each loop", | ||
"description": "Executes a workflow repeatedly, based on the items provided.", | ||
"category": "Content", | ||
"fields": { | ||
"workflowKey": { | ||
"name": "Workflow key", | ||
"desc": "The workflow which will be executed for each item.", | ||
"type": "Text", | ||
}, | ||
"items": { | ||
"name": "Items", | ||
"desc": "The item value will be passed in the execution context and will be available via @{item}.", | ||
"default": "{}", | ||
"type": "Object", | ||
"control": "Textarea" | ||
}, | ||
"context": { | ||
"name": "Context", | ||
"desc": "You can add other values to the execution context.", | ||
"default": "{}", | ||
"type": "Object", | ||
"control": "Textarea" | ||
}, | ||
}, | ||
"outs": { | ||
"success": { | ||
"name": "Success", | ||
"description": "The workflow wasn't executed successfully.", | ||
"style": "success", | ||
}, | ||
"error": { | ||
"name": "Error", | ||
"description": "The workflow wasn't executed successfully.", | ||
"style": "error", | ||
}, | ||
}, | ||
} | ||
)) | ||
|
||
def run(self): | ||
workflow_key = self._get_field("workflowKey") | ||
items = self._get_field("items") | ||
context = self._get_field("context") | ||
|
||
try: | ||
for item in items: | ||
writer.workflows.run_workflow_by_key(self.session, workflow_key) | ||
self.outcome = "success" | ||
except Exception as e: | ||
self.result = "HTTP call failed." | ||
self.outcome = "connectionError" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from writer.abstract import register_abstract_template | ||
from writer.ss_types import AbstractTemplate | ||
from writer.workflows_blocks.blocks import WorkflowBlock | ||
import writer.workflows | ||
|
||
class RunWorkflow(WorkflowBlock): | ||
|
||
@classmethod | ||
def register(cls, type: str): | ||
super(RunWorkflow, cls).register(type) | ||
register_abstract_template(type, AbstractTemplate( | ||
baseType="workflows_node", | ||
writer={ | ||
"name": "Run workflow", | ||
"description": "Executes a workflow", | ||
"category": "Content", | ||
"fields": { | ||
"workflowKey": { | ||
"name": "Workflow key", | ||
"type": "Text", | ||
}, | ||
"context": { | ||
"name": "Context", | ||
"desc": "Values passed in the context will be available using the template syntax i.e. @{my_context_var}", | ||
"default": "{}", | ||
"type": "Object", | ||
"control": "Textarea" | ||
}, | ||
}, | ||
"outs": { | ||
"success": { | ||
"name": "Success", | ||
"description": "The request was successful.", | ||
"style": "success", | ||
}, | ||
"error": { | ||
"name": "Error", | ||
"description": "The workflow was executed successfully.", | ||
"style": "error", | ||
}, | ||
}, | ||
} | ||
)) | ||
|
||
def run(self): | ||
workflow_key = self._get_field("workflowKey") | ||
context = self._get_field("context", as_json=True) | ||
|
||
try: | ||
writer.workflows.run_workflow_by_key(self.session, workflow_key, context) | ||
self.outcome = "success" | ||
except Exception as e: | ||
print("running the other workflow " + repr(e)) | ||
self.result = "Running workflow failed." | ||
self.outcome = "error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters