當前位置: 首頁>>代碼示例>>Python>>正文


Python Channel.redis_active_events_key方法代碼示例

本文整理匯總了Python中temba.channels.models.Channel.redis_active_events_key方法的典型用法代碼示例。如果您正苦於以下問題:Python Channel.redis_active_events_key方法的具體用法?Python Channel.redis_active_events_key怎麽用?Python Channel.redis_active_events_key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在temba.channels.models.Channel的用法示例。


在下文中一共展示了Channel.redis_active_events_key方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: register_active_event

# 需要導入模塊: from temba.channels.models import Channel [as 別名]
# 或者: from temba.channels.models.Channel import redis_active_events_key [as 別名]
    def register_active_event(self):
        """
        Helper function for registering active events on a throttled channel
        """
        r = get_redis_connection()

        channel_key = Channel.redis_active_events_key(self.channel_id)

        r.incr(channel_key)
開發者ID:teehamaral,項目名稱:rapidpro,代碼行數:11,代碼來源:models.py

示例2: unregister_active_event

# 需要導入模塊: from temba.channels.models import Channel [as 別名]
# 或者: from temba.channels.models.Channel import redis_active_events_key [as 別名]
    def unregister_active_event(self):
        """
        Helper function for unregistering active events on a throttled channel
        """
        r = get_redis_connection()

        channel_key = Channel.redis_active_events_key(self.channel_id)
        # are we on a throttled channel?
        current_tracked_events = r.get(channel_key)

        if current_tracked_events:

            value = int(current_tracked_events)
            if value <= 0:  # pragma: no cover
                raise ValueError("When this happens I'll quit my job and start producing moonshine/poitin/brlja !")

            r.decr(channel_key)
開發者ID:teehamaral,項目名稱:rapidpro,代碼行數:19,代碼來源:models.py

示例3: task_enqueue_call_events

# 需要導入模塊: from temba.channels.models import Channel [as 別名]
# 或者: from temba.channels.models.Channel import redis_active_events_key [as 別名]
def task_enqueue_call_events():
    from .models import IVRCall

    r = get_redis_connection()

    pending_call_events = (
        IVRCall.objects.filter(status=IVRCall.PENDING)
        .filter(direction=IVRCall.OUTGOING, is_active=True)
        .filter(channel__is_active=True)
        .filter(modified_on__gt=timezone.now() - timedelta(days=IVRCall.IGNORE_PENDING_CALLS_OLDER_THAN_DAYS))
        .select_related("channel")
        .order_by("modified_on")[:1000]
    )

    for call in pending_call_events:

        # are we handling a call on a throttled channel ?
        max_concurrent_events = call.channel.config.get(Channel.CONFIG_MAX_CONCURRENT_EVENTS)

        if max_concurrent_events:
            channel_key = Channel.redis_active_events_key(call.channel_id)
            current_active_events = r.get(channel_key)

            # skip this call if are on the limit
            if current_active_events and int(current_active_events) >= max_concurrent_events:
                continue
            else:
                # we can start a new call event
                call.register_active_event()

        # enqueue the call
        ChannelLog.log_ivr_interaction(call, "Call queued internally", HttpEvent(method="INTERNAL", url=None))

        call.status = IVRCall.QUEUED
        call.save(update_fields=("status",))

        start_call_task.apply_async(kwargs={"call_pk": call.id}, queue=Queue.HANDLER)
開發者ID:teehamaral,項目名稱:rapidpro,代碼行數:39,代碼來源:tasks.py


注:本文中的temba.channels.models.Channel.redis_active_events_key方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。