Sha256: c9b0a88f6d1127563d9494d446a12adb2b7797326e57fb469cf0e3e8772f8be5

Contents?: true

Size: 1.87 KB

Versions: 39

Compression:

Stored size: 1.87 KB

Contents

class DispatchedService < ActiveRecord::Base
  belongs_to :request
  
  # Serialized hash of exception info. 
  serialize :exception_info
  
  # Statuses for status column
  # Still executing, has started  
  InProgress = 'in_progress'
  # Queued up, not yet started. Generally used for background services.
  Queued = 'queued'
  # Complete, succesful. May or may not have produced responses, but
  # completed succesfully either way. 
  Successful = 'successful'
  # Failed, and do not advise trying again. 
  FailedFatal = 'failed_fatal' # Complete, failed,
  # Failed, but it might be worth trying again.
  FailedTemporary = 'failed_temporary'
 
 
  def service=(service)
    self.service_id = service.service_id
  end
  # instantiates a new service object that represents the service
  # that dispatched. 
  def service
    @service ||= ServiceStore.instantiate_service!( self.service_id, request )
  end

  # For old-time's sake, true can be used for Succesful
  # and false can be used for FailedTemporary (that keeps
  # previous semantics for false intact). 
  def status=(a_status)
    a_status = FailedTemporary if a_status.kind_of?(FalseClass)
    a_status = Successful if a_status.kind_of?(TrueClass)

    # NO: @status = a_status
    # Instead, this is how you 'override' an AR attribute:
    write_attribute(:status, a_status)
  end

  # Will silently refuse to over-write an existing stored exception. 
  def store_exception(a_exc)
      return if a_exc.nil? || ! self.exception_info.nil?
      # Just yaml'izing the exception doesn't keep the backtrace, which is
      # what we wanted. Doh!
      e_hash = Hash.new
      e_hash[:class_name] = a_exc.class.name
      e_hash[:message] = a_exc.message
      e_hash[:backtrace] = a_exc.backtrace
      
      write_attribute(:exception_info, e_hash)
  end

  def completed?
    return (self.status != InProgress) && (self.status != Queued)
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
umlaut-3.3.1 app/models/dispatched_service.rb
umlaut-3.3.0 app/models/dispatched_service.rb
umlaut-3.2.0 app/models/dispatched_service.rb
umlaut-3.1.1 app/models/dispatched_service.rb
umlaut-3.1.0 app/models/dispatched_service.rb
umlaut-3.1.0.pre2 app/models/dispatched_service.rb
umlaut-3.1.0.pre1 app/models/dispatched_service.rb
umlaut-3.0.5 app/models/dispatched_service.rb
umlaut-3.0.4 app/models/dispatched_service.rb
umlaut-3.0.3 app/models/dispatched_service.rb
umlaut-3.0.2 app/models/dispatched_service.rb
umlaut-3.0.1 app/models/dispatched_service.rb
umlaut-3.0.0 app/models/dispatched_service.rb
umlaut-3.0.0rc1 app/models/dispatched_service.rb
umlaut-3.0.0beta10 app/models/dispatched_service.rb
umlaut-3.0.0beta9 app/models/dispatched_service.rb
umlaut-3.0.0beta8 app/models/dispatched_service.rb
umlaut-3.0.0beta7 app/models/dispatched_service.rb
umlaut-3.0.0beta6 app/models/dispatched_service.rb
umlaut-3.0.0beta5 app/models/dispatched_service.rb