Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Implemented - "Set a Task's Progress" and "Retry a Task" methods with tests #31

Merged
merged 1 commit into from

3 participants

Kononov Dmitriy Evan Shaw Travis Reeder
Kononov Dmitriy

No description provided.

Evan Shaw edsrzf was assigned by rkononov
Travis Reeder treeder merged commit ac46ca9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 46 additions and 0 deletions.
  1. +23 −0 iron_worker.py
  2. +23 −0 test.py
23 iron_worker.py
View
@@ -457,6 +457,29 @@ def log(self, id):
headers = {"Accept": "text/plain"}
resp = self.client.get(url, headers=headers)
return resp["body"]
+
+ def setProgress(self, id, percent, msg=''):
+ if isinstance(id, Task):
+ id = id.id
+ url = "tasks/%s/progress" % id
+ body = {}
+ body['percent'] = percent
+ body['msg'] = msg
+ body = json.dumps(body)
+ resp = self.client.post(url, body=body,
+ headers={"Content-Type":"application/json"})
+ return resp["body"]
+
+ def retry(self, id, delay=1):
+ if isinstance(id, Task):
+ id = id.id
+ url = "tasks/%s/retry" % id
+ body = {}
+ body['delay'] = delay
+ body = json.dumps(body)
+ resp = self.client.post(url, body=body,
+ headers={"Content-Type":"application/json"})
+ return resp["body"]
def cancel(self, id, scheduled=False):
if isinstance(id, Task):
23 test.py
View
@@ -75,6 +75,29 @@ def test_zcancelTask(self):
self.assertEqual(len(real_tasks), 0)
+ def test_setTaskProgress(self):
+ payload = {
+ "dict": {"a": 1, "b": 2},
+ "var": "alpha",
+ "list": ['apples', 'oranges', 'bananas']
+ }
+ resp = self.worker.queue(code_name=self.code_name, payload=payload)
+ task_id = resp.id
+ res = self.worker.setProgress(task_id, 50, 'Job half-done');
+ self.assertEqual(res["msg"], 'Progress set');
+
+ def test_setRetryTask(self):
+ payload = {
+ "dict": {"a": 1, "b": 2},
+ "var": "alpha",
+ "list": ['apples', 'oranges', 'bananas']
+ }
+ resp = self.worker.queue(code_name=self.code_name, payload=payload)
+ task_id = resp.id
+ res = self.worker.retry(task_id, 10);
+
+ self.assertEqual(res["msg"], "Queued up");
+
def test_postSchedule(self):
resp = self.worker.queue(code_name=self.code_name, delay=120)
Something went wrong with that request. Please try again.