Sha256: ec4f64a02580662c0aab2444d17eb8b2e1cc834e779d07f5504322bd548da5b2
Contents?: true
Size: 1.81 KB
Versions: 8
Compression:
Stored size: 1.81 KB
Contents
class J8W1ApplicationDevice < ActiveRecord::Base self.table_name = 'j7w1_application_devices' belongs_to :owner, polymorphic: true scope :enabled, -> {where(disabled: false)} <%- if options['async_engine'] -%> after_create :create_device_endpoint_async after_destroy :destroy_device_endpoint_async <%- else -%> after_create :create_device_endpoint after_destroy :destroy_device_endpoint <%- end -%> scope :identified, -> identifier { where(device_identifier: identifier) } scope :on_platform, -> platform { where(platform: J7W1::Util.normalize_platform(platform)) } def push!(options = {}) J7W1::PushClient.push device_endpoint_arn, platform, options rescue AWS::SNS::Errors::EndpoiintDisabled logger.warn{"push for Application Device ##{id} is currently disabled."} begin update_attributes!(disabled: true) rescue logger.warn { "Disabling failure: application device ##{id}" } # grasp all the exception raised. end end def create_device_endpoint device_endpoint_arn = J7W1::PushClient.create_device_endpoint device_identifier, platform_id, custom_user_data: "#{owner.class} ##{owner.id}" update_attributes! device_endpoint_arn: device_endpoint_arn end def self.destroy_device_endpoint(device_arn) J7W1::PushClient.destroy_endpoint device_arn end private <%- if options['async_engine'] == 'delayed_job' -%> def create_device_endpoint_async delay.create_device_endpoint end def destroy_device_endpoint_async self.class.delay.destroy_device_endpoint device_endpoint_arn end <%- elsif options['async_engine'] == 'sidekiq' -%> def create_device_endpoint_async J7W1CreateEndpointWorker.perform_async id end def destroy_device_endpoint_async J7W1DestroyEndpointWorker.perform_async device_endpoint_arn end <%- end -%> end
Version data entries
8 entries across 8 versions & 1 rubygems