Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.

Commit 19bb807

Browse files
authored
Merge pull request #44 from antoinereyt/add-intent-id
Add a intent_id when dispatching workflows and tasks
2 parents 444c6ee + 6feff04 commit 19bb807

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## [Unreleased]
44

55
### Added
6+
- Added a `intent_id` property when dispatching workflows and tasks, sending events to workflows, and
7+
pausing/resuming/killing workflows.
68

79
### Changed
810

zenaton/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__version__ = '0.3.3'
1+
__version__ = '0.3.4'
2+
__version_id__ = 304

zenaton/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import urllib
5+
import uuid
56

67
from .abstracts.workflow import Workflow
78
from .exceptions import InvalidArgumentError
@@ -24,6 +25,7 @@ class Client(metaclass=Singleton):
2425
APP_ID = 'app_id' # Parameter name for the application ID
2526
API_TOKEN = 'api_token' # Parameter name for the API token
2627

28+
ATTR_INTENT_ID = 'intent_id' # Parameter name for intent_id
2729
ATTR_ID = 'custom_id' # Parameter name for custom ids
2830
ATTR_NAME = 'name' # Parameter name for workflow names
2931
ATTR_CANONICAL = 'canonical_name' # Parameter name for version name
@@ -92,6 +94,7 @@ def start_workflow(self, flow):
9294
return self.http.post(
9395
self.instance_worker_url(),
9496
data=json.dumps({
97+
self.ATTR_INTENT_ID: self.uuid(),
9598
self.ATTR_PROG: self.PROG,
9699
self.ATTR_CANONICAL: self.canonical_name(flow),
97100
self.ATTR_NAME: self.class_name(flow),
@@ -104,6 +107,7 @@ def start_task(self, task):
104107
return self.http.post(
105108
self.worker_url('tasks'),
106109
data=json.dumps({
110+
self.ATTR_INTENT_ID: self.uuid(),
107111
self.ATTR_PROG: self.PROG,
108112
self.ATTR_NAME: self.class_name(task),
109113
self.ATTR_DATA: self.serializer.encode(self.properties.from_(task)),
@@ -114,6 +118,7 @@ def update_instance(self, workflow, custom_id, mode):
114118
params = '{}={}'.format(self.ATTR_ID, custom_id)
115119
url = self.instance_worker_url(params)
116120
options = json.dumps({
121+
self.ATTR_INTENT_ID: self.uuid(),
117122
self.ATTR_PROG: self.PROG,
118123
self.ATTR_NAME: workflow.__name__,
119124
self.ATTR_MODE: mode
@@ -130,6 +135,7 @@ def update_instance(self, workflow, custom_id, mode):
130135
"""
131136
def send_event(self, workflow_name, custom_id, event):
132137
body = json.dumps({
138+
self.ATTR_INTENT_ID: self.uuid(),
133139
self.ATTR_PROG: self.PROG,
134140
self.ATTR_NAME: workflow_name,
135141
self.ATTR_ID: custom_id,
@@ -235,3 +241,7 @@ def _connect_to_agent(self):
235241
raise ConnectionError(
236242
'Could not connect to Zenaton agent at "{}:{}", make sure it is running and '
237243
'listening.'.format(url, port))
244+
245+
def uuid(self):
246+
"""Generate a uuidv4"""
247+
return str(uuid.uuid4())

0 commit comments

Comments
 (0)