# post\_created、post\_edited Webhooks 队列问题

**URL:** https://meta.discourse.org/t/post-created-post-edited-webhooks-enqueue-issue/177671
**Category:** Development
**Created:** [2021年一月29日 12:48 UTC](https://meta.discourse.org/t/post-created-post-edited-webhooks-enqueue-issue/177671 "2021-01-29T12:48:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2021年一月29日 12:48 UTC](https://meta.discourse.org/t/post-created-post-edited-webhooks-enqueue-issue/177671/1 "2021-01-29T12:48:54Z")

</div>

最近，我们在使用评分插件时遇到了一个问题：过时的或空数据被传递给了 Webhook。原来，这是因为在入队这些 Webhook 时依赖了 `DiscourseEvent`。

这导致 Webhook 在某些甚至所有插件完成其模型修改之前就被入队了，因为我们没有任何机制来确保执行的先后顺序。特别是，核心代码会具有更高的优先级。

我建议将这些 Webhook 的入队操作安排在 `DiscourseEvent.trigger` 调用之后，以确保此时所有插件都已完成了对模型的修改。

大家怎么看？

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2021年二月3日 01:35 UTC](https://meta.discourse.org/t/post-created-post-edited-webhooks-enqueue-issue/177671/2 "2021-02-03T01:35:03Z")

</div>

或许可以为此变更提交一个 PR，原则上听起来没问题。

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2021年二月4日 12:05 UTC](https://meta.discourse.org/t/post-created-post-edited-webhooks-enqueue-issue/177671/3 "2021-02-04T12:05:58Z")

</div>

我和 @angus 讨论了这个问题，并找到了一个非常简单的解决方案。目前看来运行正常。

将 `on()` 代码写在 `after_initialize` 之外解决了该问题。我认为所有插件都应该这样做。问题出在我们这边。

之所以这样能行，是因为控制流在 Rails 初始化器运行之前就已进入 plugin.rb，因此 `on()` 回调会在 Webhook 入队之前完成注册。
