event_actions
定位
event_actions 定義一個 event_key 要執行哪些 notification template。
event_queue 只知道要送某個 event_key,實際要送 email、SMS、push 或 MoEngage,是由 event_actions 決定。
主要欄位
| 欄位 | 說明 |
|---|---|
event_key | event 名稱,例如 Contact_Pro |
template_type | 通知類型,例如 email、sms、push |
template_key | template 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.phpevent_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_type | template_key |
|---|---|
email | 701 Auto Quote Want to Contact Provider |
email | 701 (no message)Auto Quote Want to Contact Provider |
push | push.content.contact.provider |
web_push | push.content.contact.provider |
sms | sms.new_chat_sent |
moengage | Auto_Quote_Want_to_Contact_Provider_empty |
moengage | Auto_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_actions與params.tasks是否一致。