Пример #1
0
    def end_task(self, result):
        """End task and save result"""

        task = db.tasks.find_one({'worker': self.name, 'status': Task.STATUS_WAIT})

        if task is not None:
            task = Task(str(task['_id']))
            task.save_result(result)
        self.release()
Пример #2
0
    def get(self):
        """List all tasks"""

        tasks = []

        for task in Task.objects():
            tasks.append({
                '_id': task._id,
                'priority': task.priority,
                'status': task.status,
                'worker': task.worker,
                'result': task.result
            })

        self.finish({
            'tasks': tasks
        })
Пример #3
0
    def post(self):
        """Register task"""

        body = json.loads(self.request.body)

        if body.get('data') is not None:
            priority = body.get('priority', Task.PRIORITY_NORMAL)

            if priority in Task.PRIORITIES:
                task = Task.create(data=body['data'], priority=priority)
                data = {
                    'status': 'ok',
                    'task_id': task._id
                }
            else:
                data = errors.get(errors.INCORRECT_PRIORITY)
        else:
            data = errors.get(errors.TASK_NO_DATA)

        self.finish(data)
Пример #4
0
    def release(self):
        """Detach worker from all pending task"""

        for task in db.tasks.find({'worker': self.name, 'status': Task.STATUS_WAIT}):
            task = Task(str(task['_id']))
            task.set_worker(None)
Пример #5
0
def check_tasks():
    """Check uncompleted tasks"""

    for task in Task.objects({'worker': None, 'result': None}):
        send_task(task)
Пример #6
0
    p2 = Project("CoRe 2", noah.user_id, 2)

    # Adding projects
    raul.add_project(p1)
    noah.add_project(p2)

    # show projects
    raul.show_projects()

    # get project by user
    raul_p1 = raul.get_project_by_id(p1.project_id)
    raul_p1.add_user(noah.user_id)

    # Task
    task1 = Task(task_id=1,
                 project_id=raul_p1.project_id,
                 creator_id=raul.user_id,
                 description="Create API")
    task2 = Task(task_id=2,
                 project_id=raul_p1.project_id,
                 creator_id=raul.user_id,
                 description="Create Documentation")
    task3 = Task(task_id=3,
                 project_id=raul_p1.project_id,
                 creator_id=raul.user_id,
                 description="Wave people")

    raul_p1.add_task([task1, task2, task3])
    raul_p1.set_task(user_id=noah.user_id, tasks_id=[task2.task_id])
    raul_p1.set_task(user_id=raul.user_id,
                     tasks_id=[task1.task_id, task2.task_id, task2.task_id, 3])