Skip to content

Commit

Permalink
Do no retry web push workers if the server returns a 4xx response (ma…
Browse files Browse the repository at this point in the history
…stodon#9434)

Add timeout of 10s to web push requests
  • Loading branch information
Gargron authored and hiyuki2578 committed Oct 2, 2019
1 parent f8502c8 commit c8dbf2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/models/web/push_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def push_payload(message, ttl = 5.minutes.seconds)
p256dh: key_p256dh,
auth: key_auth,
ttl: ttl,
ssl_timeout: 10,
open_timeout: 10,
read_timeout: 10,
vapid: {
subject: "mailto:#{::Setting.site_contact_email}",
private_key: Rails.configuration.x.vapid_private_key,
Expand Down
4 changes: 2 additions & 2 deletions app/workers/web/push_notification_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def perform(subscription_id, notification_id)
notification = Notification.find(notification_id)

subscription.push(notification) unless notification.activity.nil?
rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription
subscription.destroy!
rescue Webpush::ResponseError => e
subscription.destroy! if (400..499).cover?(e.response.code.to_i)
rescue ActiveRecord::RecordNotFound
true
end
Expand Down

0 comments on commit c8dbf2e

Please sign in to comment.