lib/taskinator/persistence.rb in taskinator-0.3.10 vs lib/taskinator/persistence.rb in taskinator-0.3.11

- old
+ new

@@ -189,10 +189,16 @@ tasks_count > 0 ? (send("count_#{status}") / tasks_count.to_f) * 100.0 : 0.0 end end + def deincr_pending_tasks + Taskinator.redis do |conn| + conn.incrby("#{key}.pending", -1) + end + end + # 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 def process_options @process_options ||= begin @@ -201,17 +207,17 @@ end yaml ? Taskinator::Persistence.deserialize(yaml) : {} end end - EXPIRE_IN = 10 * 60 # 10 minutes + EXPIRE_IN = 30 * 60 # 30 minutes - def cleanup(expire_at=Time.now+EXPIRE_IN) + def cleanup(expire_in=EXPIRE_IN) Taskinator.redis do |conn| # use the "clean up" visitor - RedisCleanupVisitor.new(conn, self, expire_at).visit + RedisCleanupVisitor.new(conn, self, expire_in).visit # remove from the list conn.srem(Persistence.processes_list_key(scope), uuid) end @@ -274,10 +280,12 @@ unless task.is_a?(Task::SubProcess) incr_task_count unless self == @base_visitor @base_visitor.incr_task_count end end + @conn.set("#{@key}.count", tasks.count) + @conn.set("#{@key}.pending", tasks.count) end def visit_attribute(attribute) value = @instance.send(attribute) @hmset += [attribute, value] if value @@ -375,11 +383,11 @@ end end end def visit_tasks(tasks) - builder.tag!('tasks') do |xml| + builder.tag!('tasks', :count => tasks.count) do |xml| tasks.each do |task| xml.tag!('task', :key => task.key) do |xml2| XmlSerializationVisitor.new(xml2, task, @base_visitor).visit unless task.is_a?(Task::SubProcess) incr_task_count unless self == @base_visitor @@ -493,11 +501,11 @@ def visit_tasks(tasks) # tasks are a linked list, so just get the first one Taskinator.redis do |conn| uuid = conn.lindex("#{@key}:tasks", 0) - tasks << lazy_instance_for(Task, uuid) if uuid + tasks.attach(lazy_instance_for(Task, uuid), conn.get("#{@key}.count").to_i) if uuid end end def visit_process_reference(attribute) uuid = @attribute_values[attribute] @@ -574,31 +582,31 @@ end class RedisCleanupVisitor < Taskinator::Visitor::Base attr_reader :instance - attr_reader :expire_at + attr_reader :expire_in # seconds - def initialize(conn, instance, expire_at) + def initialize(conn, instance, expire_in) @conn = conn @instance = instance - @expire_at = expire_at.utc + @expire_in = expire_in.to_i @key = instance.key end def visit @instance.accept(self) - @conn.expireat(@key, expire_at.to_i) + @conn.expire(@key, expire_in) end def visit_process(attribute) process = @instance.send(attribute) - RedisCleanupVisitor.new(@conn, process, expire_at).visit if process + RedisCleanupVisitor.new(@conn, process, expire_in).visit if process end def visit_tasks(tasks) tasks.each do |task| - RedisCleanupVisitor.new(@conn, task, expire_at).visit + RedisCleanupVisitor.new(@conn, task, expire_in).visit end end end