当前位置: 首页>>代码示例>>Python>>正文


Python models.Callrequest类代码示例

本文整理汇总了Python中dialer_cdr.models.Callrequest的典型用法代码示例。如果您正苦于以下问题:Python Callrequest类的具体用法?Python Callrequest怎么用?Python Callrequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Callrequest类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

    def run(self, **kwargs):
        logger = init_call_retry.get_logger()
        logger.info("TASK :: init_call_retry")
        try:
            # get callrequest which are failed
            callreq_retry_list = Callrequest.objects.filter(status=2, call_type=1)
            for callreq in callreq_retry_list:
                try:
                    # Call type => Retry Done = 3
                    callreq.call_type = 3
                    callreq.save()

                    campaign_obj = Campaign.objects.get(id=callreq.campaign_id)
                    if campaign_obj:
                        if callreq.num_attempt >= campaign_obj.maxretry:
                            logger.error("Not allowed retry")
                            break

                    dialer_set = user_dialer_setting(callreq.user)
                    if dialer_set:
                        if callreq.num_attempt >= dialer_set.maxretry:
                            logger.error("Not allowed retry")
                            break
                except:
                    # Call type =>  Can Not Retry = 2
                    callreq.call_type = 2
                    callreq.save()
                    logger.error("Can't find dialer setting for user of the campaign : %s" \
                                 % callreq.campaign_id)
                    break

                # TODO : Review Logic
                # Crete new callrequest, Assign parent_callrequest, Change callrequest_type
                # & num_attempt
                obj = Callrequest(request_uuid=uuid1(),
                                    parent_callrequest_id=callreq.id,
                                    call_type=1,
                                    num_attempt=callreq.num_attempt+1,
                                    user=callreq.user,
                                    campaign_id=callreq.campaign_id,
                                    aleg_gateway_id=callreq.aleg_gateway_id,
                                    content_type=callreq.content_type,
                                    object_id=callreq.object_id,
                                    phone_number=callreq.phone_number)
                obj.save()
                # TODO : perform retry
                init_callrequest.delay(obj.id, obj.campaign_id)
        except:
            logger.error("Can't find failed callrequest")
            return False
        return True
开发者ID:nbhatti,项目名称:newfies-dialer,代码行数:51,代码来源:tasks.py

示例2: check_retrycall_completion

def check_retrycall_completion(callrequest):
    """
    We will check if the callrequest need to be restarted
    in order to achieve completion
    """

    # Check if subscriber is not completed and check if
    # subscriber.completion_count_attempt < campaign.completion_maxretry
    if (
        callrequest.subscriber.status == SUBSCRIBER_STATUS.COMPLETED
        or callrequest.subscriber.completion_count_attempt >= callrequest.campaign.completion_maxretry
        or not callrequest.campaign.completion_maxretry
        or callrequest.campaign.completion_maxretry == 0
    ):
        logger.debug("Subscriber completed or limit reached!")
    else:
        # Let's Init a new callrequest

        # Increment subscriber.completion_count_attempt
        if callrequest.subscriber.completion_count_attempt:
            callrequest.subscriber.completion_count_attempt = callrequest.subscriber.completion_count_attempt + 1
        else:
            callrequest.subscriber.completion_count_attempt = 1
        callrequest.subscriber.save()

        # init_callrequest -> delay at completion_intervalretry
        new_callrequest = Callrequest(
            request_uuid=uuid1(),
            parent_callrequest_id=callrequest.id,
            call_type=CALLREQUEST_TYPE.ALLOW_RETRY,
            num_attempt=callrequest.num_attempt + 1,
            user=callrequest.user,
            campaign_id=callrequest.campaign_id,
            aleg_gateway_id=callrequest.aleg_gateway_id,
            content_type_id=callrequest.content_type_id,
            object_id=callrequest.object_id,
            phone_number=callrequest.phone_number,
            timelimit=callrequest.timelimit,
            callerid=callrequest.callerid,
            timeout=callrequest.timeout,
            content_object=callrequest.content_object,
            subscriber=callrequest.subscriber,
        )
        new_callrequest.save()
        # NOTE : implement a PID algorithm
        second_towait = callrequest.campaign.completion_intervalretry
        logger.debug("Init Completion Retry CallRequest in  %d seconds" % second_towait)
        init_callrequest.apply_async(
            args=[new_callrequest.id, callrequest.campaign.id, callrequest.campaign.callmaxduration],
            countdown=second_towait,
        )
开发者ID:berinhard,项目名称:newfies-dialer,代码行数:51,代码来源:tasks.py

示例3: setUp

    def setUp(self):
        self.user = User.objects.get(username='admin')
        VoipSearchForm(self.user)

        try:
            content_type_id = ContentType.objects.get(model='survey').id
        except:
            content_type_id = 1

        # Callrequest model
        self.callrequest = Callrequest(
            call_type=1,
            status=1,
            user=self.user,
            phone_number='123456',
            subscriber_id=1,
            campaign_id=1,
            aleg_gateway_id=1,
            content_type_id=content_type_id,
            object_id=1,
        )
        self.callrequest.save()

        # VoIPCall model
        self.voipcall = VoIPCall(
            user=self.user,
            used_gateway_id=1,
            callrequest=self.callrequest,
            callid='Top Gun',
            phone_number='123456',
            leg_type=1,
            duration=20,
        )
        self.voipcall.save()
        self.assertEqual(self.voipcall.__unicode__(), u'2 - Top Gun')

        # Test mgt command
        call_command("create_callrequest_cdr", "1|1")

        call_command("create_callrequest_cdr", "3|1")
开发者ID:AffiniaDialer,项目名称:newfies-dialer,代码行数:40,代码来源:tests.py

示例4: run

    def run(self, **kwargs):
        logger.info("TASK :: alarmrequest_dispatcher")

        # Select AlarmRequest where date >= now() - 60 minutes
        start_time = datetime.utcnow().replace(tzinfo=utc) + relativedelta(minutes=-60)
        alarmreq_list = AlarmRequest.objects.filter(date__gte=start_time, status=ALARMREQUEST_STATUS.PENDING)
        no_alarmreq = alarmreq_list.count()
        if no_alarmreq == 0:
            logger.error("alarmrequest_dispatcher - no alarmreq found!")
            return False

        # Set time to wait for balanced dispatching of calls
        #time_to_wait = int(60 / DIV_MIN) / no_subscriber
        time_to_wait = 6.0 / no_alarmreq
        count = 0

        # Browse all the AlarmRequest found
        for obj_alarmreq in alarmreq_list:
            # Loop on AlarmRequest and start to the initcall's task
            count = count + 1
            second_towait = floor(count * time_to_wait)
            ms_addtowait = (count * time_to_wait) - second_towait
            logger.info("Init CallRequest for AlarmRequest in %d seconds (alarmreq:%d)" % (second_towait, obj_alarmreq.id))

            if obj_alarmreq.alarm.maxretry == 0:
                call_type = CALLREQUEST_TYPE.CANNOT_RETRY
            else:
                call_type = CALLREQUEST_TYPE.ALLOW_RETRY

            try:
                caluser_profile = CalendarUserProfile.objects.get(user=obj_alarmreq.alarm.event.creator)
            except CalendarUserProfile.DoesNotExist:
                logger.error("Error retrieving CalendarUserProfile")
                return False

            #manager_profile = UserProfile.objects.get(user=caluser_profile.manager)
            # manager_profile = caluser_profile.manager.get_profile()
            # manager_profile.dialersetting
            # Use manager_profile.dialersetting to retrieve some settings

            # TODO: build settings for this
            calltimeout = caluser_profile.calendar_setting.call_timeout
            callmaxduration = 60 * 60
            callerid = caluser_profile.calendar_setting.callerid
            caller_name = caluser_profile.calendar_setting.caller_name
            aleg_gateway = caluser_profile.calendar_setting.aleg_gateway
            content_type = ContentType.objects.get(model__in=["survey"])
            object_id = caluser_profile.calendar_setting.survey_id

            # Create Callrequest to track the call task
            new_callrequest = Callrequest(
                status=CALLREQUEST_STATUS.PENDING,
                call_type=call_type,
                call_time=datetime.utcnow().replace(tzinfo=utc),
                timeout=calltimeout,
                callerid=callerid,
                caller_name=caller_name,
                phone_number=obj_alarmreq.alarm.alarm_phonenumber,
                alarm_request_id=obj_alarmreq.id,
                aleg_gateway=aleg_gateway,
                content_type=content_type,
                object_id=object_id,
                user=caluser_profile.manager,
                extra_data='',
                timelimit=callmaxduration)
            new_callrequest.save()

            init_callrequest.apply_async(
                args=[new_callrequest.id, None, callmaxduration, ms_addtowait, obj_alarmreq.id],
                countdown=second_towait)

            obj_alarmreq.callrequest = new_callrequest
            obj_alarmreq.status = ALARMREQUEST_STATUS.IN_PROCESS
            obj_alarmreq.save()
            # Increment num_attempt
            obj_alarmreq.alarm.num_attempt = obj_alarmreq.alarm.num_attempt + 1
            obj_alarmreq.alarm.save()
开发者ID:Lautitia,项目名称:newfies-dialer,代码行数:77,代码来源:tasks.py

示例5: run


#.........这里部分代码省略.........
        # Get the subscriber of this campaign
        # get_pending_subscriber get Max 1000 records
        if settings.HEARTBEAT_MIN == 1:  # 1 task per minute
            callfrequency = frequency  # task run only once per minute, so we can assign frequency
        else:
            callfrequency = int(frequency / settings.HEARTBEAT_MIN) + 1  # 1000 per minutes
            #callfrequency = int(frequency) + 1  # 1000 per minutes

        (list_subscriber, no_subscriber) = obj_campaign\
            .get_pending_subscriber_update(callfrequency, SUBSCRIBER_STATUS.IN_PROCESS)
        logger.info("##subscriber=%d campaign_id=%d callfreq=%d freq=%d" %
                    (no_subscriber, campaign_id, callfrequency, frequency))
        debug_query(3)

        if no_subscriber == 0:
            return False

        # Set time to wait for balanced dispatching of calls
        time_to_wait = (60.0 / settings.HEARTBEAT_MIN) / no_subscriber
        count = 0
        loopnow = datetime.utcnow()
        loopnow + timedelta(seconds=1.55)

        for elem_camp_subscriber in list_subscriber:
            # Loop on Subscriber and start the initcall's task
            count = count + 1
            second_towait = floor(count * time_to_wait)
            # ms_addtowait now used anymore, replaced by async eta
            ms_addtowait = (count * time_to_wait) - second_towait

            eta_delta = loopnow + timedelta(seconds=(count * time_to_wait))
            # as we use eta_delta ms_addtowait is set to 0
            ms_addtowait = 0

            logger.info("Init CallRequest in %d seconds (cmpg:%d,subscr:%d:eta_delta:%s)" %
                        (second_towait, campaign_id, elem_camp_subscriber.id, eta_delta))

            phone_number = elem_camp_subscriber.duplicate_contact
            debug_query(4)

            #Verify that the contact is authorized
            if not obj_campaign.is_authorized_contact(obj_campaign.user.userprofile.dialersetting, phone_number):
                logger.error("Error : Contact not authorized")
                elem_camp_subscriber.status = SUBSCRIBER_STATUS.NOT_AUTHORIZED
                elem_camp_subscriber.save()
                continue
            #Verify that the contact is not in the DNC list
            if obj_campaign.dnc:
                res_dnc = DNCContact.objects.filter(dnc_id=obj_campaign.dnc_id, phone_number=phone_number)
                if res_dnc:
                    logger.error("Contact (%s) in DNC list" % phone_number)
                    elem_camp_subscriber.status = SUBSCRIBER_STATUS.NOT_AUTHORIZED
                    elem_camp_subscriber.save()
                    continue
                else:
                    logger.debug("Contact (%s) not in DNC list" % phone_number)

            debug_query(5)

            #TODO: idea to speed up, create bluck of 10(Y) and then send a list
            # of callrequest_id to init_callrequest

            # Create Callrequest
            new_callrequest = Callrequest(
                status=CALLREQUEST_STATUS.PENDING,
                call_type=call_type,
                call_time=datetime.utcnow().replace(tzinfo=utc),
                timeout=obj_campaign.calltimeout,
                callerid=obj_campaign.callerid,
                caller_name=obj_campaign.caller_name,
                phone_number=phone_number,
                campaign=obj_campaign,
                aleg_gateway=obj_campaign.aleg_gateway,
                content_type=obj_campaign.content_type,
                object_id=obj_campaign.object_id,
                user=obj_campaign.user,
                extra_data=obj_campaign.extra_data,
                timelimit=obj_campaign.callmaxduration,
                subscriber=elem_camp_subscriber)
            new_callrequest.save()

            debug_query(6)

            second_towait = second_towait + settings.DELAY_OUTBOUND

            init_callrequest.apply_async(
                args=[new_callrequest.id, obj_campaign.id, obj_campaign.callmaxduration, ms_addtowait],
                # countdown=second_towait)
                eta=eta_delta)

            # Shell_plus
            # from dialer_cdr.tasks import init_callrequest
            # from datetime import datetime
            # new_callrequest_id = 112
            # obj_campaign_id = 3
            # countdown = 1
            # init_callrequest.apply_async(args=[new_callrequest.id, obj_campaign.id, obj_campaign.callmaxduration, ms_addtowait], countdown=1)

        debug_query(7)
        return True
开发者ID:chengjunjian,项目名称:newfies-dialer,代码行数:101,代码来源:tasks.py

示例6: DialerCdrModel

class DialerCdrModel(TestCase):

    """Test Callrequest, VoIPCall models"""

    fixtures = ['auth_user.json', 'gateway.json', 'dialer_setting.json',
                'user_profile.json', 'phonebook.json', 'contact.json',
                'dnc_list.json', 'dnc_contact.json', 'survey.json',
                'campaign.json', 'subscriber.json', 'callrequest.json', 'voipcall.json',
                'user_profile.json']

    def setUp(self):
        self.user = User.objects.get(username='admin')
        VoipSearchForm(self.user)

        try:
            content_type_id = ContentType.objects.get(model='survey').id
        except:
            content_type_id = 1

        # Callrequest model
        self.callrequest = Callrequest(
            call_type=1,
            status=1,
            user=self.user,
            phone_number='123456',
            subscriber_id=1,
            campaign_id=1,
            aleg_gateway_id=1,
            content_type_id=content_type_id,
            object_id=1,
        )
        self.callrequest.save()

        # VoIPCall model
        self.voipcall = VoIPCall(
            user=self.user,
            used_gateway_id=1,
            callrequest=self.callrequest,
            callid='Top Gun',
            phone_number='123456',
            leg_type=1,
            duration=20,
        )
        self.voipcall.save()
        self.assertEqual(self.voipcall.__unicode__(), u'2 - Top Gun')

        # Test mgt command
        call_command("create_callrequest_cdr", "1|1")

        call_command("create_callrequest_cdr", "3|1")

    def test_name(self):
        self.assertEqual(self.callrequest.phone_number, "123456")
        #self.assertEqual(self.callrequest.__unicode__(), u'Top Gun')
        self.assertEqual(self.voipcall.phone_number, "123456")

        Callrequest.objects.get_pending_callrequest()

        self.voipcall.destination_name()
        self.voipcall.duration = ''
        self.voipcall.min_duration()
        self.voipcall.duration = 12
        self.voipcall.min_duration()

    def teardown(self):
        self.callrequest.delete()
        self.voipcall.delete()
开发者ID:AffiniaDialer,项目名称:newfies-dialer,代码行数:67,代码来源:tests.py


注:本文中的dialer_cdr.models.Callrequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。