Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #31 from freeman1988/master

Implemented - "Set a Task's Progress" and "Retry a Task" methods with tests
  • Loading branch information...
commit ac46ca9802ce601b8bb806da32d6d6cc18be23ca 2 parents 1ce47f9 + 81c5a94
@treeder treeder authored
Showing with 46 additions and 0 deletions.
  1. +23 −0 iron_worker.py
  2. +23 −0 test.py
View
23 iron_worker.py
@@ -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):
View
23 test.py
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.