Class: ExternalServices::ApiAction

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Action
Defined in:
app/models/external_services/api_action.rb

Constant Summary collapse

MAX_ACTION_AGE =
ENV.fetch('EXTERNAL_SERVICES_MAX_ACTION_AGE') { '90' }.to_i.days

Constants included from Action

ExternalServices::Action::QUEUE_PREFIX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Action

#execute!, #kick_active_job, #prefixed_queue, #processed?, #set_processed!

Instance Attribute Details

#async=(value) ⇒ Object

Sets the attribute async

Parameters:

  • value

    the value to set the attribute async to.



7
8
9
# File 'app/models/external_services/api_action.rb', line 7

def async=(value)
  @async = value
end

Class Method Details

.delete_old_processedObject



26
27
28
# File 'app/models/external_services/api_action.rb', line 26

def self.delete_old_processed
  processed.where(arel_table[:created_at].lt(MAX_ACTION_AGE.ago)).delete_all
end

Instance Method Details

#api_disabled?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/external_services/api_action.rb', line 44

def api_disabled?
  initiator_class.send(:"#{self.class.to_s.demodulize.underscore}_api_disabled")
end

#change_external_id?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/external_services/api_action.rb', line 36

def change_external_id?
  options['change_external_id']
end

#dataObject



52
53
54
# File 'app/models/external_services/api_action.rb', line 52

def data
  !async && (method.to_sym == :delete) ? nil : super
end

#initiator_classObject



30
31
32
33
34
# File 'app/models/external_services/api_action.rb', line 30

def initiator_class
  # Need to use initiator object for STI in polymorphic.. But still will be bugs with deleted STI object and
  # non-STI inheritance
  initiator.try(:class) || initiator_type.constantize
end

#job_classObject



40
41
42
# File 'app/models/external_services/api_action.rb', line 40

def job_class
  "ExternalServices::#{self.class.to_s.demodulize}ApiJob".constantize
end

#signatureObject



48
49
50
# File 'app/models/external_services/api_action.rb', line 48

def signature
  async ? super : calculate_signature
end