1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 实时推送
import json
from django.conf import settings
from .push_base import (
push_logger,
PushServiceBase,
)
from .push_builder import PushEvents
class TimelyPushService(PushServiceBase):
"""
实时推送 service
"""
_default_cache_name = "timely_push"
ratelimit_unit_times = 2 # 默认的单位时间推送数量
ratelimit_whole_rate_limit = settings.PUSH_RATE_LIMIT_SETTINGS.get("total_count", 10) # 一天推送总数
push_handlers = PushEvents.timely_push_handlers
# < ----------- push begin ------------ >
@classmethod
def push(cls, user_ids, action_type, **kwargs):
"""
实时 推送
:return:
"""
params = cls.build_push_params(user_ids, action_type, **kwargs)
if params:
from communal.tasks import push_control_task
task_ = push_control_task.delay(**params)
push_logger.info(json.dumps({
"step": 6,
"sole_sign": kwargs.get("sole_sign", ""),
"resume": "push information completed! timely push tasks delay.",
"params": params,
"task_id": task_.id,
}))
# < ----------- push end ------------ >