Django-Celery - 从管理页面重新提交任务?

发布于 2024-11-25 11:13:06 字数 544 浏览 3 评论 0原文

我目前正在开发一个使用 Django 1.3 和 Django-Celery 应用程序的项目。非常棒,顺便说一句,我建议任何不熟悉芹菜的人都看看。

我对管理页面功能有一个具体问题:

我们正在使用 celery 任务向第三方合作伙伴进行 RESTful API 调用。这些调用实际上是由用户操作启动的,因此您可以看到 celery 任务在这种情况下非常有用。

我们有一个关于管理员如何在由于某种原因失败时重新发送回调的用户故事。现在,如果回调因标准 HTTP 响应失败而失败,我们将使用 celery 重试机制以不同的时间间隔自动重新发送它们。然而,这些回调可能是针对数千个合作伙伴之一(是的,有很多),并且并非所有合作伙伴都会使用标准 HTTP 响应代码作为其失败响应。

长话短说,我在网上找不到任何可以通过管理界面重新发送芹菜任务的内容。我希望有人能对此有所启发。这似乎是一个非常明显的功能,如果没有这样的功能,我相信这是有充分理由的。如果没有办法做到这一点,如果有人可以解释原因,我会很高兴。只是想了解更多有关 celery 内部工作原理的信息。

谢谢大家!抱歉我的啰嗦,有时我会胡言乱语。

I'm currently working on a project using Django 1.3 with the Django-Celery app. It's pretty awesome, by the way, I suggest anyone who's not familiar with celery check it out.

I have a specific question around the admin page functionality:

We're using celery tasks to make RESTful API calls to third party partners. These calls are actually kicked off by a user action, so you could see how a celery task would be extremely useful in this case.

We have a user story around how an admin should be able to re-send a callback if it fails for some reason. Now, if the callback fails with a standard HTTP response failure, we are using the celery retry mechanism to automatically resend them at various intervals. However, these callbacks could be to one of any thousands of partners (yea, theres a lot), and not all of them will use a standard HTTP Response code as their failure response.

Long story short, I haven't been able to find anything online that states that one can re-send a celery task through the admin interface. I was hoping that someone could shed some light on this. It seems like a pretty obvious piece of functionality to have, and if there is no such functionality I'm sure there's a good reason for it. I'd love it if there isn't a way to do it, if someone could explain the reason. Just curious to learn more about the internal workings of celery.

Thanks everyone! Sorry for my wordiness, sometimes I tend to ramble.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-12-02 11:13:06

您可以尝试两种方法,

1:模型中的小技巧:

您可以使用布尔字段并将其命名为 celery_retry 之类的名称,并在模型保存方法中执行类似的操作。

def save(self, *args, **kwargs):
    if self.celery_retry and self.user.is_superuser():
          celery_task.apply_async()
    self.celery_retry = False
    super(MyModel, self).save(*args, **kwargs)

这只是一个想法,你可以自己决定如何以及何时提交回 celery 任务。

2:扩展管理模板:

您可以扩展管理模板并放入指向重新提交任务的视图的超链接。

You can try two approaches,

1: Small hack in model:

You can use a boolean field and name it something like celery_retry and in models save method do something like this.

def save(self, *args, **kwargs):
    if self.celery_retry and self.user.is_superuser():
          celery_task.apply_async()
    self.celery_retry = False
    super(MyModel, self).save(*args, **kwargs)

This is just an idea, you can determine your own how and when to submit celery task back.

2:Extend admin template:

You can extend the admin template and put in a hyperlink to a view which resubmits the task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文