Class: KNSEmailEndpoint::MessageState

Inherits:
Object
  • Object
show all
Defined in:
lib/kns_email_endpoint/message_state.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, message)
  # setup the state
  @conn_name = conn_name
  @message = message
  @message_id = get_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

.storageObject

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

#messageObject (readonly)

Returns the value of attribute message.



20
21
22
# File 'lib/kns_email_endpoint/message_state.rb', line 20

def message
  @message
end

#message_idObject (readonly)

Returns the value of attribute message_id.



20
21
22
# File 'lib/kns_email_endpoint/message_state.rb', line 20

def message_id
  @message_id
end

#retry_countObject (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

#stateObject

Returns the value of attribute state.



20
21
22
# File 'lib/kns_email_endpoint/message_state.rb', line 20

def state
  @state
end

#unique_idObject (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.message_id.to_s != ""
  Digest::SHA1.hexdigest "#{conn}::#{msg.message_id}::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

#deleteObject



67
68
69
70
# File 'lib/kns_email_endpoint/message_state.rb', line 67

def delete
  @storage.delete
  self.state = :deleted
end

#resetObject



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_stateObject



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

#retryObject



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