在浮士德框架(或其他框架)中,有芹菜倒计时和eta的替代方案吗



我想通过用户设置在特定时间触发一些任务。例如,如果用户设置下午4:00,那么我将在下午4:00运行任务它可以在带有倒计时和eta的Celery中处理。但我的经纪人更喜欢卡夫卡。芹菜倒计时和eta还有其他选择吗?

Celery中的代码如下:

result = add.apply_async((2, 2), countdown=3)

我希望不要使用Celery,必须使用Kafka

Faust确实有一个crontab触发器来启动进程。下面的示例显示了一个使用crontab的简单实现,它将每分钟运行一次作业:

import faust
import asyncio
app = faust.App(
'some_print_step',
broker="kafka://localhost:9092",
)
@app.crontab("* * * * *")
async def run_every_min():
print("This process will be triggered every minute.")

@app.crontab('0 18 * * *')
async def run_everyday_at_6pm:
print('This process will be triggered every day at 6pm.')

你可以在这里找到更多的crontab文档:

浮士德crontab和计时器文档

如果我正确理解您对@meherr的响应,那么这可能是正确的方法。使用asyncio.sleep((并将延迟时间与消息一起传入可以实现与此处所述相同的行为:https://docs.celeryproject.org/en/latest/userguide/calling.html#eta-和倒计时

但它不像是一个内置功能。

@app.agent(some_topic, concurrency=100)
async def do_something_later(things_to_do):
async for thing in things_to_do:
delay_by = thing.time_to_wait
await asyncio.sleep(delay_by)
result = do_the_thing_to_the(thing)
yield result

最新更新