Module: Taskinator::Persistence::InstanceMethods

Defined in:
lib/taskinator/persistence.rb

Instance Method Summary collapse

Instance Method Details

#errorObject

retrieves the error type, message and backtrace and returns an array with 3 subscripts respectively



97
98
99
100
101
102
103
104
# File 'lib/taskinator/persistence.rb', line 97

def error
  @error ||= Taskinator.redis do |conn|
    error_type, error_message, error_backtrace =
      conn.hmget(self.key, :error_type, :error_message, :error_backtrace)

    [error_type, error_message, JSON.parse(error_backtrace)]
  end
end

#fail(error) ⇒ Object

persists the error information



84
85
86
87
88
89
90
91
92
93
# File 'lib/taskinator/persistence.rb', line 84

def fail(error)
  Taskinator.redis do |conn|
    conn.hmset(
      self.key,
      :error_type, error.class.name,
      :error_message, error.message,
      :error_backtrace, JSON.generate(error.backtrace)
    )
  end
end

#keyObject



52
53
54
# File 'lib/taskinator/persistence.rb', line 52

def key
  self.class.key_for(self.uuid)
end

#load_workflow_stateObject

retrieves the workflow state this method is called from the workflow gem



68
69
70
71
72
73
# File 'lib/taskinator/persistence.rb', line 68

def load_workflow_state
  state = Taskinator.redis do |conn|
    conn.hget(self.key, :state)
  end
  (state || 'initial').to_sym
end

#persist_workflow_state(new_state) ⇒ Object

persists the workflow state this method is called from the workflow gem



77
78
79
80
81
# File 'lib/taskinator/persistence.rb', line 77

def persist_workflow_state(new_state)
  Taskinator.redis do |conn|
    conn.hset(self.key, :state, new_state)
  end
end

#saveObject



56
57
58
59
60
61
62
63
64
# File 'lib/taskinator/persistence.rb', line 56

def save
  Taskinator.redis do |conn|
    conn.multi do
      RedisSerializationVisitor.new(conn, self).visit
      conn.sadd "taskinator:#{self.class.base_key}", self.uuid
      true
    end
  end
end