module Taskinator::Persistence::InstanceMethods
Constants
- EXPIRE_IN
Public Instance Methods
cleanup(expire_in=EXPIRE_IN)
click to toggle source
# File lib/taskinator/persistence.rb, line 214 def cleanup(expire_in=EXPIRE_IN) Taskinator.redis do |conn| # use the "clean up" visitor RedisCleanupVisitor.new(conn, self, expire_in).visit # remove from the list conn.srem(Persistence.processes_list_key(scope), uuid) end end
deincr_pending_tasks()
click to toggle source
# File lib/taskinator/persistence.rb, line 194 def deincr_pending_tasks Taskinator.redis do |conn| conn.incrby("#{key}.pending", -1) end end
error()
click to toggle source
retrieves the error type, message and backtrace and returns an array with 3 subscripts respectively
# File lib/taskinator/persistence.rb, line 146 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=nil)
click to toggle source
persists the error information
# File lib/taskinator/persistence.rb, line 130 def fail(error=nil) return unless error && error.is_a?(Exception) Taskinator.redis do |conn| conn.hmset( self.key, :error_type, error.class.name, :error_message, error.message, :error_backtrace, JSON.generate(error.backtrace || []), :updated_at, Time.now.utc ) end end
key()
click to toggle source
the persistence key
# File lib/taskinator/persistence.rb, line 81 def key @key ||= self.class.key_for(self.uuid) end
load_workflow_state()
click to toggle source
retrieves the workflow state this method is called from the workflow gem
# File lib/taskinator/persistence.rb, line 99 def load_workflow_state state = Taskinator.redis do |conn| conn.hget(self.key, :state) || 'initial' end state.to_sym end
persist_workflow_state(new_state)
click to toggle source
persists the workflow state this method is called from the workflow gem
# File lib/taskinator/persistence.rb, line 108 def persist_workflow_state(new_state) @updated_at = Time.now.utc Taskinator.redis do |conn| process_key = self.process_key conn.multi do conn.hmset( self.key, :state, new_state, :updated_at, @updated_at ) # also update the "root" process conn.hset( process_key, :updated_at, @updated_at ) end end new_state end
process_key()
click to toggle source
the root process persistence key associated with this process or task
# File lib/taskinator/persistence.rb, line 93 def process_key @process_key ||= Taskinator::Process.key_for(process_uuid) end
process_options()
click to toggle source
retrieves the process options of the root process this is so that meta data of the process can be maintained and accessible to instrumentation subscribers
# File lib/taskinator/persistence.rb, line 203 def process_options @process_options ||= begin yaml = Taskinator.redis do |conn| conn.hget(self.process_key, :options) end yaml ? Taskinator::Persistence.deserialize(yaml) : {} end end
process_uuid()
click to toggle source
the root process uuid associated with this process or task
# File lib/taskinator/persistence.rb, line 86 def process_uuid @process_uuid ||= Taskinator.redis do |conn| conn.hget(self.key, :process_uuid) end end
save()
click to toggle source
# File lib/taskinator/persistence.rb, line 54 def save Taskinator.redis do |conn| conn.pipelined do visitor = RedisSerializationVisitor.new(conn, self).visit conn.hmset( Taskinator::Process.key_for(uuid), :tasks_count, visitor.task_count, :tasks_failed, 0, :tasks_processing, 0, :tasks_completed, 0, :tasks_cancelled, 0, ) true end end end
tasks_count()
click to toggle source
# File lib/taskinator/persistence.rb, line 155 def tasks_count @tasks_count ||= begin count = Taskinator.redis do |conn| conn.hget self.process_key, :tasks_count end count.to_i end end
to_xml()
click to toggle source
# File lib/taskinator/persistence.rb, line 71 def to_xml builder = ::Builder::XmlMarkup.new builder.instruct! builder.tag!('process', :key => self.key) do |xml| XmlSerializationVisitor.new(xml, self).visit end builder end