コード例 #1
0
ファイル: flow_scheduler.py プロジェクト: phoenix-zhu/eums
def schedule_run_directly_for(runnable, run_delay):
    if Run.has_scheduled_run(runnable.contact_person_id):
        RunQueue.enqueue(runnable, run_delay)
    elif settings.RAPIDPRO_LIVE:
        task = _schedule_run.apply_async(args=[runnable.id], countdown=run_delay)
        Run.objects.create(scheduled_message_task_id=task.id, runnable=runnable,
                           status=Run.STATUS.scheduled, phone=runnable.contact.phone)
コード例 #2
0
ファイル: flow_scheduler.py プロジェクト: unicefuganda/eums
def schedule_run_directly_for(runnable, run_delay):
    if Run.has_scheduled_run(runnable.contact_person_id):
        RunQueue.enqueue(runnable, settings.DELIVERY_STATUS_CHECK_DELAY)
    elif settings.RAPIDPRO_LIVE:
        logger.info("schedule_run_directly_for:: run_delay=%s" % run_delay)
        task = _schedule_run.apply_async(args=[runnable.id], countdown=run_delay)
        Run.objects.create(scheduled_message_task_id=task.id, runnable=runnable,
                           status=Run.STATUS.not_started, phone=runnable.contact.phone)
コード例 #3
0
 def _schedule_run_for(self, runnable):
     if runnable.completed_run() is None:
         if Run.has_scheduled_run(runnable.contact_person_id):
             RunQueue.enqueue(runnable, 0)
         else:
             contact = runnable.build_contact()
             task = '231x31231231'
             Run.objects.create(scheduled_message_task_id=task, runnable=runnable,
                                status=Run.STATUS.scheduled, phone=contact['phone'] if contact else None)
コード例 #4
0
 def _schedule_run_for(self, runnable):
     if runnable.completed_run() is None:
         if Run.has_scheduled_run(runnable.contact_person_id):
             RunQueue.enqueue(runnable, 0)
         else:
             contact = runnable.build_contact()
             task = '231x31231231'
             Run.objects.create(scheduled_message_task_id=task, runnable=runnable,
                                status=Run.STATUS.scheduled, phone=contact['phone'] if contact else None)
コード例 #5
0
def schedule_run_directly_for(runnable, run_delay):
    if Run.has_scheduled_run(runnable.contact_person_id):
        RunQueue.enqueue(runnable, run_delay)
    elif settings.RAPIDPRO_LIVE:
        task = _schedule_run.apply_async(args=[runnable.id],
                                         countdown=run_delay)
        Run.objects.create(scheduled_message_task_id=task.id,
                           runnable=runnable,
                           status=Run.STATUS.scheduled,
                           phone=runnable.contact.phone)
コード例 #6
0
def schedule_run_directly_for(runnable, run_delay):
    if Run.has_scheduled_run(runnable.contact_person_id):
        RunQueue.enqueue(runnable, settings.DELIVERY_STATUS_CHECK_DELAY)
    elif settings.RAPIDPRO_LIVE:
        logger.info("schedule_run_directly_for:: run_delay=%s" % run_delay)
        task = _schedule_run.apply_async(args=[runnable.id],
                                         countdown=run_delay)
        Run.objects.create(scheduled_message_task_id=task.id,
                           runnable=runnable,
                           status=Run.STATUS.not_started,
                           phone=runnable.contact.phone)
コード例 #7
0
ファイル: test_run_queue.py プロジェクト: tomclement/eums
    def test_queues_run_for_particular_line_item_node(self):
        contact_person_id = 'id'
        run_delay = 1000

        node = DistributionPlanNodeFactory(contact_person_id=contact_person_id)

        RunQueue.enqueue(node, run_delay)
        queued_run = RunQueue.dequeue(contact_person_id)

        self.assertEqual(queued_run.status, RunQueue.STATUS.not_started)
        self.assertEqual(queued_run.contact_person_id, contact_person_id)
コード例 #8
0
ファイル: test_run_queue.py プロジェクト: z0x010/eums
    def test_queues_run_for_particular_line_item_node(self):
        contact_person_id = 'id'
        run_delay = 1000

        node = DeliveryNodeFactory(contact_person_id=contact_person_id)

        RunQueue.enqueue(node, run_delay)
        queued_run = RunQueue.dequeue(contact_person_id)

        self.assertEqual(queued_run.status, RunQueue.STATUS.not_started)
        self.assertEqual(queued_run.contact_person_id, contact_person_id)
コード例 #9
0
ファイル: test_run_queue.py プロジェクト: crazy-paf/eums
    def test_queues_run_for_particular_line_item_node(self):
        contact_person_id = 'id'
        start_run_date = datetime.now()

        consignee = ConsigneeFactory(contact_person_id=contact_person_id)
        node = DistributionPlanNodeFactory(consignee=consignee)
        node_line_item = DistributionPlanLineItemFactory(distribution_plan_node=node)

        RunQueue.enqueue(node_line_item, start_run_date)
        queued_run = RunQueue.deque(contact_person_id)

        self.assertEqual(queued_run.status, RunQueue.STATUS.not_started)
        self.assertEqual(queued_run.contact_person_id, contact_person_id)
コード例 #10
0
ファイル: flow_scheduler.py プロジェクト: tomclement/eums
def schedule_run_for(node):
    current_run = node.current_run()
    if current_run:
        _cancel_run(current_run)

    run_delay = _calculate_delay(node)
    if Run.current_run_for_node(node):
        RunQueue.enqueue(node, run_delay)
    else:
        contact = node.build_contact()
        task = _schedule_run.apply_async(args=[node.id], countdown=run_delay)
        Run.objects.create(scheduled_message_task_id=task.id, node=node,
                               status=Run.STATUS.scheduled, phone=contact['phone'])
コード例 #11
0
    def test_queues_run_for_particular_line_item_node(self):
        contact_person_id = 'id'
        start_run_date = datetime.now()

        consignee = ConsigneeFactory(contact_person_id=contact_person_id)
        node = DistributionPlanNodeFactory(consignee=consignee)
        node_line_item = DistributionPlanLineItemFactory(
            distribution_plan_node=node)

        RunQueue.enqueue(node_line_item, start_run_date)
        queued_run = RunQueue.deque(contact_person_id)

        self.assertEqual(queued_run.status, RunQueue.STATUS.not_started)
        self.assertEqual(queued_run.contact_person_id, contact_person_id)
コード例 #12
0
ファイル: flow_scheduler.py プロジェクト: gitter-badger/eums
def schedule_run_for(node_line_item):
    current_run = node_line_item.current_run()
    if current_run:
        _cancel_run(current_run)

    run_delay = _calculate_delay(node_line_item)
    node = node_line_item.distribution_plan_node
    if NodeLineItemRun.current_run_for_node(node):
        RunQueue.enqueue(node_line_item, run_delay)
    else:
        contact = node.build_contact()
        task = _schedule_run.apply_async(args=[node_line_item.id], countdown=run_delay)
        NodeLineItemRun.objects.create(scheduled_message_task_id=task.id, node_line_item=node_line_item,
                                       status=NodeLineItemRun.STATUS.scheduled, phone=contact['phone'])
コード例 #13
0
ファイル: test_run_queue.py プロジェクト: crazy-paf/eums
    def test_deque_returns_none_when_contact_person_no_pending_runs(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started,
                        start_run_date=datetime(2014, 12, 10))

        self.assertEqual(RunQueue.deque(contact_person_id), None)
コード例 #14
0
    def test_deque_returns_none_when_contact_person_no_pending_runs(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started,
                        run_delay=1000.0)

        self.assertEqual(RunQueue.dequeue(contact_person_id), None)
コード例 #15
0
ファイル: test_run_queue.py プロジェクト: v55448330/eums
    def test_can_deque_next_run_for_a_particular_contact_person(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started, run_delay=1000.0)
        run_queue = RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started,
                                    run_delay=1500.0)

        self.assertEqual(RunQueue.dequeue(contact_person_id), run_queue)
コード例 #16
0
ファイル: flow_scheduler.py プロジェクト: phoenix-zhu/eums
def expire_overdue_runs():
    overdue_runs = Run.overdue_runs()
    for overdue_run in overdue_runs:
        overdue_run.update_status(Run.STATUS.expired)
        next_run = RunQueue.dequeue(overdue_run.runnable.contact_person_id)
        if next_run:
            schedule_run_for(next_run.runnable)
            next_run.update_status(RunQueue.STATUS.started)
コード例 #17
0
ファイル: test_run_queue.py プロジェクト: tomclement/eums
    def test_can_deque_next_run_for_a_particular_contact_person(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started, run_delay=1000.0)
        run_queue = RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started,
                                    run_delay=1500.0)

        self.assertEqual(RunQueue.dequeue(contact_person_id), run_queue)
コード例 #18
0
def expire_overdue_runs():
    overdue_runs = Run.overdue_runs()
    for overdue_run in overdue_runs:
        overdue_run.update_status(Run.STATUS.expired)
        next_run = RunQueue.dequeue(overdue_run.runnable.contact_person_id)
        if next_run:
            schedule_run_for(next_run.runnable)
            next_run.update_status(RunQueue.STATUS.started)
コード例 #19
0
ファイル: test_run_queue.py プロジェクト: crazy-paf/eums
    def test_can_deque_next_run_for_a_particular_contact_person(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started,
                        start_run_date=datetime(2014, 12, 10))
        run_queue = RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started,
                                    start_run_date=datetime(2014, 10, 10))

        self.assertEqual(RunQueue.deque(contact_person_id), run_queue)
コード例 #20
0
    def test_deque_returns_none_when_contact_person_no_pending_runs(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id,
                        status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id,
                        status=RunQueue.STATUS.started,
                        start_run_date=datetime(2014, 12, 10))

        self.assertEqual(RunQueue.deque(contact_person_id), None)
コード例 #21
0
ファイル: flow_scheduler.py プロジェクト: gitter-badger/eums
def expire_overdue_runs():
    overdue_runs = NodeLineItemRun.overdue_runs()
    for overdue_run in overdue_runs:
        overdue_run.status = NodeLineItemRun.STATUS.expired
        overdue_run.save()
        next_run = RunQueue.dequeue(overdue_run.node_line_item.distribution_plan_node.contact_person_id)
        if next_run:
            schedule_run_for(next_run.node_line_item)
            next_run.status = RunQueue.STATUS.started
            next_run.save()
コード例 #22
0
ファイル: flow_scheduler.py プロジェクト: tomclement/eums
def expire_overdue_runs():
    overdue_runs = Run.overdue_runs()
    for overdue_run in overdue_runs:
        overdue_run.status = Run.STATUS.expired
        overdue_run.save()
        next_run = RunQueue.dequeue(overdue_run.node.contact_person_id)
        if next_run:
            schedule_run_for(next_run.node)
            next_run.status = RunQueue.STATUS.started
            next_run.save()
コード例 #23
0
ファイル: test_run_queue.py プロジェクト: z0x010/eums
    def test_can_deque_next_run_for_a_particular_contact_person(self):
        contact_person_id = 'id'
        date_first = datetime.datetime(2016, 2, 1, 9, 0, 0, 0)
        date_second = datetime.datetime(2016, 2, 2, 9, 0, 0, 0)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started, start_time=date_second)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started, start_time=date_first)
        run_queue = RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.not_started,
                                    start_time=date_first)

        self.assertEqual(RunQueue.dequeue(contact_person_id).start_time, run_queue.start_time)
コード例 #24
0
    def test_should_have_all_expected_fields(self):
        node_line_item_run = RunQueue()
        fields_in_run_queue = [
            field.attname for field in node_line_item_run._meta.fields
        ]

        for field in [
                'node_line_item_id', 'contact_person_id', 'status',
                'start_run_date'
        ]:
            self.assertIn(field, fields_in_run_queue)
コード例 #25
0
    def test_can_deque_next_run_for_a_particular_contact_person(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id,
                        status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id,
                        status=RunQueue.STATUS.not_started,
                        start_run_date=datetime(2014, 12, 10))
        run_queue = RunQueueFactory(contact_person_id=contact_person_id,
                                    status=RunQueue.STATUS.not_started,
                                    start_run_date=datetime(2014, 10, 10))

        self.assertEqual(RunQueue.deque(contact_person_id), run_queue)
コード例 #26
0
ファイル: hook.py プロジェクト: unicefuganda/eums
def _dequeue_next_run(contact_person_id, run_delay):
    next_run_queue = RunQueue.dequeue(contact_person_id=contact_person_id)
    if next_run_queue:
        schedule_run_for(next_run_queue.runnable, run_delay)
        next_run_queue.update_status(RunQueue.STATUS.started)
コード例 #27
0
ファイル: web_answers_endpoint.py プロジェクト: z0x010/eums
def _dequeue_next_run_for(runnable):
    next_run = RunQueue.dequeue(contact_person_id=runnable.contact_person_id)
    logger.info("next run is %s" % next_run)
    if next_run:
        schedule_run_for(next_run.runnable)
        next_run.update_status(RunQueue.STATUS.started)
コード例 #28
0
ファイル: test_run_queue.py プロジェクト: z0x010/eums
    def test_deque_returns_none_when_contact_person_no_pending_runs(self):
        contact_person_id = 'id'
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started)
        RunQueueFactory(contact_person_id=contact_person_id, status=RunQueue.STATUS.started, run_delay=1000.0)

        self.assertEqual(RunQueue.dequeue(contact_person_id), None)
コード例 #29
0
ファイル: hook.py プロジェクト: tomclement/eums
def _dequeue_next_run(run):
    next_run = RunQueue.dequeue(contact_person_id=run.node.contact_person_id)
    if next_run:
        _schedule_next_run(next_run.node)
        next_run.status = RunQueue.STATUS.started
        next_run.save()
コード例 #30
0
ファイル: hook.py プロジェクト: yaroing/eums
def _dequeue_next_run(contact_person_id):
    next_run_queue = RunQueue.dequeue(contact_person_id=contact_person_id)
    if next_run_queue:
        _schedule_next_run(next_run_queue.runnable)
        next_run_queue.update_status(RunQueue.STATUS.started)
コード例 #31
0
def _dequeue_next_run_for(runnable):
    next_run = RunQueue.dequeue(contact_person_id=runnable.contact_person_id)
    logger.info("next run is %s" % next_run)
    if next_run:
        schedule_run_for(next_run.runnable)
        next_run.update_status(RunQueue.STATUS.started)
コード例 #32
0
ファイル: hook.py プロジェクト: gitter-badger/eums
def _dequeue_next_run(line_item_run):
    next_run = RunQueue.dequeue(contact_person_id=line_item_run.node_line_item.distribution_plan_node.contact_person_id)
    _schedule_next_run(line_item_run.node_line_item)
    next_run.status = RunQueue.STATUS.started
    next_run.save()