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

#can_generate_service_typesObject

Calls service.service_type_generated, but cautious of service_id that is no longer in the ServiceStore

Note, this means all service types that could possibly be generated by this service, not those that actually have been


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

def can_generate_service_types
  if ServiceStore.service_definition_for( self.service_id ) 
    service.service_types_generated
  else
    []
  end
end

#completed?Boolean

Returns:

  • (Boolean)

68
69
70
# File 'app/models/dispatched_service.rb', line 68

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

#failed?Boolean

Returns:

  • (Boolean)

72
73
74
# File 'app/models/dispatched_service.rb', line 72

def failed?
  return (self.status == FailedTemporary) || (self.status == FailedFatal)
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).


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

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.


56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/dispatched_service.rb', line 56

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