Class: KNSEmailEndpoint::MessageState
- Inherits:
-
Object
- Object
- KNSEmailEndpoint::MessageState
- Defined in:
- lib/kns_email_endpoint/message_state.rb
Class Attribute Summary collapse
-
.storage ⇒ Object
Returns the value of attribute storage.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#retry_count ⇒ Object
readonly
Returns the value of attribute retry_count.
-
#state ⇒ Object
Returns the value of attribute state.
-
#unique_id ⇒ Object
readonly
Returns the value of attribute unique_id.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(conn_name, message) ⇒ MessageState
constructor
A new instance of MessageState.
- #reset ⇒ Object
- #reset_state ⇒ Object
- #retry ⇒ Object
Constructor Details
#initialize(conn_name, message) ⇒ MessageState
Returns a new instance of MessageState.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kns_email_endpoint/message_state.rb', line 22 def initialize(conn_name, ) # setup the state @conn_name = conn_name @message = @message_id = @unique_id = get_unique_id @storage = self.class.storage raise "Unknown Storage" unless @storage # get from storage @storage.find_or_create(:unique_id => @unique_id, :message_id => @message_id) @state = @storage.state @retry_count = @storage.retry_count # Do not auto delete email. @message.mark_for_delete = false end |
Class Attribute Details
.storage ⇒ Object
Returns the value of attribute storage.
6 7 8 |
# File 'lib/kns_email_endpoint/message_state.rb', line 6 def storage @storage end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
20 21 22 |
# File 'lib/kns_email_endpoint/message_state.rb', line 20 def @message end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
20 21 22 |
# File 'lib/kns_email_endpoint/message_state.rb', line 20 def @message_id end |
#retry_count ⇒ Object (readonly)
Returns the value of attribute retry_count.
20 21 22 |
# File 'lib/kns_email_endpoint/message_state.rb', line 20 def retry_count @retry_count end |
#state ⇒ Object
Returns the value of attribute state.
20 21 22 |
# File 'lib/kns_email_endpoint/message_state.rb', line 20 def state @state end |
#unique_id ⇒ Object (readonly)
Returns the value of attribute unique_id.
20 21 22 |
# File 'lib/kns_email_endpoint/message_state.rb', line 20 def unique_id @unique_id end |
Class Method Details
.gen_unique_id(conn, msg) ⇒ Object
13 14 15 16 |
# File 'lib/kns_email_endpoint/message_state.rb', line 13 def gen_unique_id(conn,msg) raise "Message must have a valid message_id" unless msg..to_s != "" Digest::SHA1.hexdigest "#{conn}::#{msg.}::K-KEY" end |
.set_storage(storage, opts) ⇒ Object
8 9 10 11 |
# File 'lib/kns_email_endpoint/message_state.rb', line 8 def set_storage(storage, opts) @storage = Storage.get_storage(storage, opts) return @storage end |
Instance Method Details
#delete ⇒ Object
67 68 69 70 |
# File 'lib/kns_email_endpoint/message_state.rb', line 67 def delete @storage.delete self.state = :deleted end |
#reset ⇒ Object
54 55 56 57 58 |
# File 'lib/kns_email_endpoint/message_state.rb', line 54 def reset @retry_count = 0 @storage.retry_count = @retry_count return @retry_count end |
#reset_state ⇒ Object
60 61 62 63 64 65 |
# File 'lib/kns_email_endpoint/message_state.rb', line 60 def reset_state @storage.delete @storage.create(:unique_id => @unique_id, :message_id => @message_id) @retry_count = @storage.retry_count @state = @storage.state end |
#retry ⇒ Object
48 49 50 51 52 |
# File 'lib/kns_email_endpoint/message_state.rb', line 48 def retry @retry_count += 1 @storage.retry_count = @retry_count return @retry_count end |