Sha256: e431f44c0a618afb88f7b64b5e1bb9390fcb3b6caae034a53dcb9c8f2b768c7e
Contents?: true
Size: 1.36 KB
Versions: 117
Compression:
Stored size: 1.36 KB
Contents
# <%= autogenerated_event_warning %> module LiveEvents class RetryLiveEventJob < StandardError; end class BaseEvent < 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["attributes"]) @payload = HashWithIndifferentAccess.new(event_payload["body"]) process_with_retry end def process raise "process must be implemented in your subclass" end # Live events will use a canvas global ID (cross shard) for any ID's provided. This method will return the local ID. def local_canvas_id(id) id.to_i % 10_000_000_000_000 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
117 entries across 117 versions & 1 rubygems