Class: DispatchedService

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dispatched_service.rb

Constant Summary collapse

InProgress =

Statuses for status column Still executing, has started

'in_progress'
Queued =

Queued up, not yet started. Generally used for background services.

'queued'
Successful =

Complete, succesful. May or may not have produced responses, but completed succesfully either way.

'successful'
FailedFatal =

Failed, and do not advise trying again.

'failed_fatal'
FailedTemporary =

Failed, but it might be worth trying again.

'failed_temporary'

Instance Method Summary collapse

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/dispatched_service.rb', line 55

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

#serviceObject

instantiates a new service object that represents the service that dispatched.



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

def service
  @service ||= ServiceStore.instantiate_service!( self.service_id, request )
end

#service=(service) ⇒ Object



21
22
23
# File 'app/models/dispatched_service.rb', line 21

def service=(service)
  self.service_id = service.service_id
end

#status=(a_status) ⇒ Object

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).



33
34
35
36
37
38
39
40
# File 'app/models/dispatched_service.rb', line 33

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

#store_exception(a_exc) ⇒ Object

Will silently refuse to over-write an existing stored exception.



43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/dispatched_service.rb', line 43

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