-
-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一段时间无对话后响应会消失 #22
Comments
另外刚刚见到了没见过的新错误:
另外一旦这种情况发生,单纯重启后台服务无意义,必须在noVNC内重启酷Q。 |
你遇到这个 |
可以看下你定时任务的代码吗 |
@none.scheduler.scheduled_job('cron', minute='*')
async def _():
alert_list = get_alerts()
alert_to_send = []
for alert in alert_list:
alert_id = alert['_id']['$oid']
if not alert_recorded(alert_id):
record_alert(alert_id)
alert_to_send.append(alert)
if get_alert_record_size() > 100:
clear_alert_record()
for alert in alert_to_send:
record_alert(alert)
message = ''
if len(alert_to_send) == 0:
return
for alert in alert_to_send:
second_remaining = calculate_remain_seconds(alert['Expiry']['$date']['$numberLong'])
format_hour_remaining = second_remaining // 3600
second_remaining %= 3600
format_minute_remaining = second_remaining // 60
second_remaining %= 60
format_second_remaining = second_remaining
mission_info = alert['MissionInfo']
mission_type = DE_DICT.get(mission_info['missionType'])
if not mission_type:
mission_type = mission_info['missionType']
faction = DE_DICT.get(mission_info['faction'])
if not faction:
faction = mission_info['faction']
location = DE_DICT.get(mission_info['location'])
if not location:
location = mission_info['location']
enemy_level = '{}-{}'.format(mission_info['minEnemyLevel'], mission_info['maxEnemyLevel'])
mission_reward = mission_info['missionReward']
reward_credit = mission_reward.get('credits')
reward_item_list = []
if mission_reward.get('items'):
for item in mission_reward['items']:
item_dict_name = DE_DICT.get(item)
if not item_dict_name:
item_dict_name = item
reward_item_list.append(item_dict_name)
message += f'{location} {mission_type}\n派系:{faction}\n等级:{enemy_level}\n报酬:'
if reward_credit:
message += f'{reward_credit}现金 '
for item in reward_item_list:
message += f'{item} '
message += '\n剩余时间:'
if format_hour_remaining > 0:
message += f'{format_hour_remaining}小时'
if format_minute_remaining > 0:
message += f'{format_minute_remaining}分钟'
if format_second_remaining > 0:
message += f'{format_second_remaining}秒'
message += '\n\n'
message = message.strip()
bot = none.get_bot()
broadcast_group_list = get_alert_broadcast_group()
for group_id in broadcast_group_list:
await bot.send_group_msg(group_id=group_id, message=message) 其中
|
看你这个感觉初步判断应该是:每分钟执行了一次定时任务,然后调用了 |
应该还是因为插件的反向 WebSocket 不够稳定,先换 HTTP 试试 |
嗯是这样的没错。 改HTTP的话,直接往 |
对,然后 NoneBot 这边,配置 API_ROOT |
这个 issue 先不关,我有空研究下看看,你再发一下你现在的具体运行环境 |
阿里云ECS CentOS 7 x64 酷Q Pro 最新版(Docker) Python 3.6.5(Anaconda) 下面是pip的包
|
用HTTP一直很稳定了,只是WebSocket强迫症发作中…… |
对了,可否换成反向 WebSocket 复现一下(配置插件 另外:
NoneBot 里面不建议用 requests,因为它同步 IO,会阻塞的,可以用 asyncio 的 然后你现在 Docker 的启动命令也发来看看 |
我先复现再改get_alert好了。 Docker命令是 |
反向 WS 的地址是通过公网 IP 访问的吗 |
是的,不过酷Q和后台服务在同一服务器。 顺便,这个复现看脸……由于那个定时任务,放太久不管导致出错的几率更低了。 |
那大概原因可能是阿里云的防火墙在一段时间没通信之后掐掉了连接,尝试换 |
emm我试试 |
现在就放着看一会吧,顺便这个和心跳包有影响么?我还是开了。 |
当然开了心跳包是最好,因为心跳包就是因为之前有人说连接一段时间会断开而加的(你不说我都忘了 |
233我一直开着,应该不是这原因。 等等,如果说有心跳包存在,那上面
这个还可能会发生么? 想起来之前的问题是event正常但是api关了,或许就是因为心跳包才让event活下来了? |
等下,应该是这样的,心跳包是可以维护住 event 连接,但 api 连接还是会断 |
反正首先最好是用 docker 的网桥来访问宿主机,不要用公网 ip |
要不你给心跳包加个维护api连接(斜眼笑 |
api 你可以自行心跳呀其实,定时请求 |
啊,说到这个,上次加status功能时候报错了,我等等吃完东西再试试。 |
三种解决方案都能够解决问题。
|
好,感谢分享! |
代码重构时候想到一个小相关的问题,还是发在这里吧。
那如果在async函数中调用这些API,并且await返回结果,使用async后缀有无区别? 如 这几种方式有何差异?方便的话可否讲解下,谢谢。 |
这里的 |
那这么看来似乎是用async后缀和await 不带async效果一样? |
还是不一样的,看你需求,如果你需要知道这条消息有没有发成功,或者要获取群成员信息之类的,用不带 但 Python 这边无论如何都要 |
除非你故意让他在后台运行 |
明白了,另外如果不带async是不是就会产生线程池任务队列积累过多最后报错的隐患? |
应该是带 |
emm看来我理解错了,是不是应该是这样: 你之前说的
其实带不带async最终都会成功执行,但是带上async可能不会在调用时立即执行,导致可能需要返回信息的API利用失败,而不带async就会保证第一时间执行对应的API并返回信息?我这样理解有问题么。 |
对的,是这个意思,也就是说,你需要 API 的返回结果,那就不能带 |
OK,非常感谢!
|
是参照教程配置的,使用ws/api和ws/event。
如果一段时间(20-30分钟)不和机器人有任何交互,机器人会停止响应任何指令,包括command和自然语言。但server后台有记录(收到&处理),酷Q日志中有收到消息但无发送消息(向上箭头),怀疑api连接中断?
无论是用hypercorn还是直接python bot.py都有这个问题。
PS酷Q和bot.py在同一ECS上运行。
The text was updated successfully, but these errors were encountered: