在浮士德(Faust)框架(或其他框架)中,芹菜倒计时和eta是否有其他选择?

问题描述 投票:0回答:2

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

Celery中的代码如下:

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

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

python-3.x celery scheduled-tasks countdown faust
2个回答
1
投票

福斯特确实有一个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文档:

Faust crontab and timer documentation


0
投票

如果我正确理解了您对@meherrr的回复,那么这可能是可行的方法。使用asyncio.sleep()并在消息中传递延迟时间可以实现与此处所述相同的行为:https://docs.celeryproject.org/en/latest/userguide/calling.html#eta-and-countdown

但是它不像内置功能。

@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
© www.soinside.com 2019 - 2024. All rights reserved.