event_actions

定位

event_actions 定義一個 event_key 要執行哪些 notification template。

event_queue 只知道要送某個 event_key,實際要送 email、SMS、push 或 MoEngage,是由 event_actions 決定。

主要欄位

欄位說明
event_keyevent 名稱,例如 Contact_Pro
template_type通知類型,例如 emailsmspush
template_keytemplate key
notification_type額外通知分類,部分 handler 會使用

Worker 使用方式

Endpoint/V1/EventQueue.php::index() 處理一筆 event_queue 時會查:

SELECT *
FROM event_actions
WHERE event_key = '<event_key>';

接著依 template_type 交給:

Lib/Util/Notification/NotificationFactory.php

event_key 與 handler 的關係

event_key 是 workflow key,不是 PHP handler 名稱。NotificationFactory::$handlers 只用 template_type 找 handler。

event_queue.event_key
-> event_actions rows
-> event_actions.template_type
-> NotificationFactory::$handlers[template_type]
-> EmailHandler / SmsHandler / PushHandler / ...

因此不要期待在 NotificationFactory::$handlers 裡看到 User_Change_Password。正確查法是先查 event_actions

SELECT event_key, template_type, template_key
FROM event_actions
WHERE event_key = 'User_Change_Password';

User_Change_Password 範例:

event_key     = User_Change_Password
template_type = email
template_key  = 420 User Change Password

最後會走 NotificationFactory::$handlers['email'],也就是 EmailHandler

這是 DB-driven notification workflow,不是 Laravel 常見的 Event class -> Listener class。排查時必須查 event_actions 與 template table,不能只用 PHP class name 搜尋。

Contact_Pro 範例

目前 Contact_Pro 會對應多個通知:

template_typetemplate_key
email701 Auto Quote Want to Contact Provider
email701 (no message)Auto Quote Want to Contact Provider
pushpush.content.contact.provider
web_pushpush.content.contact.provider
smssms.new_chat_sent
moengageAuto_Quote_Want_to_Contact_Provider_empty
moengageAuto_Quote_Want_to_Contact_Provider

是否真的送出某一種通知,還要看 event_queue.params.tasks 裡是否有對應 task,以及使用者通知設定。

常用 SQL

查某個 event_key 會觸發哪些通知

SELECT
  id,
  event_key,
  template_type,
  template_key,
  notification_type
FROM event_actions
WHERE event_key = '<event_key>'
ORDER BY id;

查 Contact_Pro

SELECT
  id,
  event_key,
  template_type,
  template_key,
  notification_type
FROM event_actions
WHERE event_key = 'Contact_Pro'
ORDER BY id;

排查重點

  • 看到 event_queue.Contact_Pro 不代表所有 event_actions 都會成功送出。
  • event_actions 是 template 設定;實際 task 內容來自 event_queue.params.tasks
  • 若 log 顯示 template setting not found,要同時查 event_actionsparams.tasks 是否一致。