Sha256: 8af3581f38b64de6a8a3e53c19cb4eddcb8b36df77fb229259f127f51838a792
Contents?: true
Size: 1.17 KB
Versions: 25
Compression:
Stored size: 1.17 KB
Contents
module CanvasSync::LiveEvents class RetryLiveEventJob < StandardError; end # Deprecated class BaseHandler < CanvasSync::Job attr_accessor :raw_payload attr_accessor :payload attr_accessor :metadata def perform(event_payload) @raw_payload = event_payload @metadata = HashWithIndifferentAccess.new(event_payload["metadata"]) @payload = HashWithIndifferentAccess.new(event_payload["body"]) process_with_retry end protected def process raise "process must be implemented in your subclass" end private # Sometimes a creation and update event get sent by Canvas at almost the exact same time. This means # that there is sometimes a race condition that causes them to both try to save a new record at the same time. # If that happens, just wait a few seconds and try again -- the second try should be able to see that # the save already occured, and it will just update the row.. def process_with_retry tries ||= 5 process rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid, RetryLiveEventJob => e raise e if (tries -= 1).zero? sleep 5 retry end end end
Version data entries
25 entries across 25 versions & 1 rubygems