django - 如何在任务功能运行之前设置 celery 结果后端键?

标签 django redis celery

我在我的 Django 项目中使用了多个数据库(redis、postgresql)。在 celery 中,我正在运行一个任务函数,将倒计时参数设置为一周,将结果放入 redis 结果后端。然后我试图将 redis key 保存在 postresql 表中。如果我在任务函数运行之前设置了 redis 键,我可以稍后访问 redis 记录。那么,有没有办法做到这一点? (对不起我的英语)

最佳答案

你能试试这个吗

result = add.apply_async(countdown=time_in_seconds)
result.id #give you task id.

您现在可以将其保存到您的 postgres 中。

关于django - 如何在任务功能运行之前设置 celery 结果后端键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29283945/

相关文章:

python - 静态文件配置不当

python - 从Docker容器中的Django + Celery对API超时进行故障排除

python - 将 celery 与 Flask 应用程序上下文一起使用会产生 "Popped wrong app context."AssertionError

python - 如何解码来自 Mongodb 的 celery 结果?

javascript - 在 django 中获取 javascript 数组

html - Django Bootstrap 下拉菜单为空

python - 将文本文件中的 ascii 字符转换为 Unicode

php - Laravel 和 Redis : session driver 'array'

Python 和 Redis : Manager/Worker application best practices

ruby-on-rails - 如何使用 Ruby 推送 Celery 任务