标准运维本地运行时的注意事项:
1、启动redis,在终端执行redis-server即可启动。
2、启动celery。
下面介绍一下本次原子开发遇到的问题:
开发场景:执行一个异步任务,并拿到执行状态。难点:异步执行需要时间,状态是实时变化的,所以需要轮询去拿状态。
轮询的使用要点:
- need_schedule = True:是否是异步执行,默认为 False
- interval = StaticIntervalGenerator(5):异步标准插件的轮询策略(5秒钟执行一次)
- def schedule:轮询逻辑、结果输出
由 interval 控制调用策略,如 pipeline.core.flow.activity.StaticIntervalGenerator(每隔多少秒轮询一次)、DefaultIntervalGenerator(每次轮询间隔时间是上一次的两倍)。
具体代码如下:
拿到结果之后:
- 使用 self.finish_schedule 结束轮询。
- 返回 True 表示标准插件执行成功,False 表示执行失败。
具体代码如下:
至此,轮询的原子已经完成:每五秒执行一次。