مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-11-30 21:32:30 +00:00
feat: more consistent logging
هذا الالتزام موجود في:
@@ -53,41 +53,42 @@ class WebhookRequest < ApplicationRecord
|
||||
end
|
||||
|
||||
def deliver
|
||||
logger = Postal.logger_for(:webhooks)
|
||||
payload = { event: event, timestamp: created_at.to_f, payload: self.payload, uuid: uuid }.to_json
|
||||
logger.info "[#{id}] Sending webhook request to `#{url}`"
|
||||
result = Postal::HTTP.post(url, sign: true, json: payload, timeout: 5)
|
||||
self.attempts += 1
|
||||
self.retry_after = RETRIES[self.attempts]&.from_now
|
||||
server.message_db.webhooks.record(
|
||||
event: event,
|
||||
url: url,
|
||||
webhook_id: webhook_id,
|
||||
attempt: self.attempts,
|
||||
timestamp: Time.now.to_f,
|
||||
payload: self.payload.to_json,
|
||||
uuid: uuid,
|
||||
status_code: result[:code],
|
||||
body: result[:body],
|
||||
will_retry: (retry_after ? 0 : 1)
|
||||
)
|
||||
Postal.logger.tagged(event: event, url: url, component: "webhooks") do
|
||||
Postal.logger.info "Sending webhook request"
|
||||
result = Postal::HTTP.post(url, sign: true, json: payload, timeout: 5)
|
||||
self.attempts += 1
|
||||
self.retry_after = RETRIES[self.attempts]&.from_now
|
||||
server.message_db.webhooks.record(
|
||||
event: event,
|
||||
url: url,
|
||||
webhook_id: webhook_id,
|
||||
attempt: self.attempts,
|
||||
timestamp: Time.now.to_f,
|
||||
payload: self.payload.to_json,
|
||||
uuid: uuid,
|
||||
status_code: result[:code],
|
||||
body: result[:body],
|
||||
will_retry: (retry_after ? 0 : 1)
|
||||
)
|
||||
|
||||
if result[:code] >= 200 && result[:code] < 300
|
||||
logger.info "[#{id}] -> Received #{result[:code]} status code. That's OK."
|
||||
destroy
|
||||
webhook&.update_column(:last_used_at, Time.now)
|
||||
true
|
||||
else
|
||||
logger.error "[#{id}] -> Received #{result[:code]} status code. That's not OK."
|
||||
self.error = "Couldn't send to URL. Code received was #{result[:code]}"
|
||||
if retry_after
|
||||
logger.info "[#{id}] -> Will retry #{retry_after} (this was attempt #{self.attempts})"
|
||||
save
|
||||
else
|
||||
logger.info "[#{id}] -> Have tried #{self.attempts} times. Giving up."
|
||||
if result[:code] >= 200 && result[:code] < 300
|
||||
Postal.logger.info "Received #{result[:code]} status code. That's OK."
|
||||
destroy
|
||||
webhook&.update_column(:last_used_at, Time.now)
|
||||
true
|
||||
else
|
||||
Postal.logger.error "Received #{result[:code]} status code. That's not OK."
|
||||
self.error = "Couldn't send to URL. Code received was #{result[:code]}"
|
||||
if retry_after
|
||||
Postal.logger.info "Will retry #{retry_after} (this was attempt #{self.attempts})"
|
||||
save
|
||||
else
|
||||
Postal.logger.info "Have tried #{self.attempts} times. Giving up."
|
||||
destroy
|
||||
end
|
||||
false
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم