环境依赖
- Python2.7+ or Python3.4+
Huey 简介
一个轻量 Python2.7+ Python3.4+ 轻巧的消息队列.
功能说明
huey 支持:
- 多进程,多线程或 greenlet 任务执行模型
- 安排任务在给定时间或在给定延迟后执行
- 安排重复任务,例如 crontab
- 自动重试失败的任务
- 任务优先级
- 任务结果存储
- 任务锁定
- 任务管道和链
不支持项:
- Huey 服务异常,异常服务无法继续运行,需要重新运行。(根据任务队列进行运行。)
- 不支持彻底取消,即任务永不使用。
- 无法暂定任务。任务尚未开始时,可以取消和撤销,任务已经进行后,无法取消。
- 定时任务精准度为分钟,无法精确到秒。
Huey 对象:
- Huey Huey 实例
- TaskWrapper 不需要 TaskWrapper 直接创建实例。在 Huey.task()与 Huey.periodic_task() 装饰会自动创建相应的 TaskWrapper。
- Task 所述 Task 类表示的函数的执行。任务的实例被序列化并排入队列以供使用者执行,消费者反序列化并执行任务功能
- Result 结果
Huey 启动参数: 保证 huey 的稳定持续启动,附带 Worker 检查等参数
安装部署
安装 Huey
1 | pip install huey |
安装 Redis
详见 “Module-Redis 文档”
安装 Sqlite3
1 | yum install sqlite -y |
软件使用
1 | # 启动 Redis |
问题记录
DENIED Redis is running in protected mode
1 | ResponseError: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside. |
解决方法: Redis 服务处于保护模式, 需要修改配置文件 redis.conf。
将 NETWORK 下的 protected-mode yes 修改为 protected-mode no,然后重启 Redis 服务.
The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
日志信息
1 | redis启动警告问题:WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. |
解决方法
1 | # 临时修改 |