@@ -38,7 +38,7 @@ def _encode_time(time):
3838 return arrow .get (time , tzinfo ).to ('utc' ).format ('YYYY-MM-DDTHH:mm:ss.SSS' ) + 'Z'
3939
4040
41- def send (data , channels = None , push_time = None , expiration_time = None , expiration_interval = None , where = None , cql = None ):
41+ def send (data , channels = None , push_time = None , expiration_time = None , expiration_interval = None , where = None , cql = None , flow_control = None ):
4242 """
4343 发送推送消息。返回结果为此条推送对应的 _Notification 表中的对象,但是如果需要使用其中的数据,需要调用 fetch() 方法将数据同步至本地。
4444
@@ -56,6 +56,8 @@ def send(data, channels=None, push_time=None, expiration_time=None, expiration_i
5656 :type cql: string_types
5757 :param data: 推送给设备的具体信息,详情查看 https://leancloud.cn/docs/push_guide.html#消息内容_Data
5858 :rtype: Notification
59+ :param flow_control: 不为 None 时开启平滑推送,值为每秒推送的目标终端用户数。开启时指定低于 1000 的值,按 1000 计。
60+ :type: flow_control: int
5961 """
6062 if expiration_interval and expiration_time :
6163 raise TypeError ('Both expiration_time and expiration_interval can\' t be set' )
@@ -79,6 +81,10 @@ def send(data, channels=None, push_time=None, expiration_time=None, expiration_i
7981 params ['where' ] = where .dump ().get ('where' , {})
8082 if cql :
8183 params ['cql' ] = cql
84+ # Do not change this to `if flow_control`, because 0 is falsy in Python,
85+ # but `flow_control = 0` will enable smooth push, and it is in fact equivlent to `flow_control = 1000`.
86+ if flow_control is not None :
87+ params ['flow_control' ] = flow_control
8288
8389 result = client .post ('/push' , params = params ).json ()
8490
0 commit comments