Class: Surety::Message

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/surety/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_message(message_content) ⇒ Object



22
23
24
# File 'lib/surety/message.rb', line 22

def self.generate_message(message_content)
  self.create(:message_content=>message_content)
end

.get_next_for_processingObject



26
27
28
29
30
31
32
33
# File 'lib/surety/message.rb', line 26

def self.get_next_for_processing
  next_message = nil
  ActiveRecord::Base.transaction do
    next_message = self.needs_processing.first
    next_message.begin_processing! if next_message
  end
  next_message
end

Instance Method Details

#processObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/surety/message.rb', line 63

def process
  begin
    Surety::Configuration.message_processing_delegate.process(self)
    self.complete_processing!
  rescue Exception => ex
    self.last_exception = ex
    self.fail_processing!
    raise ex
  end
end

#record_completionObject



74
75
76
77
# File 'lib/surety/message.rb', line 74

def record_completion
  self.completed_at = Time.now
  self.last_exception = nil
end

#record_failureObject



79
80
81
82
# File 'lib/surety/message.rb', line 79

def record_failure
  self.failed_at = Time.now
  self.failure_count = self.failure_count+1
end

#reserveObject



58
59
60
61
# File 'lib/surety/message.rb', line 58

def reserve
  self.processing_started_at = Time.now
  self.processing_attempt_count = self.processing_attempt_count+1
end