本文整理汇总了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)
示例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)
示例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)