-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_tasks.py
More file actions
32 lines (24 loc) · 805 Bytes
/
test_tasks.py
File metadata and controls
32 lines (24 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
from celery.task import Task
from celery_tasktree import task_with_callbacks, run_with_callbacks
import os
@task_with_callbacks
def mkdir(directory):
""" Create directory.
We return CreateDirectoryResult object intentionally, so that
task_with_callbacks decorator can add async_result attribute to this one.
"""
os.mkdir(directory)
return CreateDirectoryResult(True)
class MkdirTask(Task):
@run_with_callbacks
def run(self, directory):
os.mkdir(directory)
return CreateDirectoryResult(True)
class CreateDirectoryResult(object):
def __init__(self, created):
self.created = created
def __bool__(self):
return bool(self.created)
def __str__(self):
return '%s <%s>' % (id(self), self.created)