Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
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'])
Ejemplo n.º 10
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)
Ejemplo n.º 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)
Ejemplo n.º 12
0
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'])