lib/qpush/job.rb in qpush-0.1.2 vs lib/qpush/job.rb in qpush-0.1.4

- old
+ new

@@ -7,25 +7,23 @@ end module Job class << self def included(base) - base.extend(ClassMethods) + _register_job(base) end - end - module ClassMethods - def queue(options) - QPush.job(options.merge(klass: name)) + def _register_job(base) + QPush.redis.with { |c| c.sadd(QPush.keys.jobs, base.name) } end end class Base attr_accessor :klass, :id, :priority, :created_at, :start_at, :cron, :retry_max, :total_success, :total_fail, :run_time, :namespace - attr_reader :args + attr_reader :args, :failed def initialize(options = {}) options = defaults.merge(options) options.each { |key, value| send("#{key}=", value) } end @@ -37,20 +35,25 @@ end rescue JSON::ParserError @args = nil end + def failed=(failed) + @failed = failed == 'true' || failed == true + end + def to_json { klass: @klass, id: @id, priority: @priority, created_at: @created_at, start_at: @start_at, cron: @cron, retry_max: @retry_max, total_fail: @total_fail, total_success: @total_success, + failed: @failed, args: @args }.to_json end private @@ -62,17 +65,18 @@ start_at: Time.now.to_i - 1, cron: '', retry_max: 10, total_fail: 0, total_success: 0, + failed: false, namespace: QPush.config.namespace } end end class ClientWrapper < QPush::Job::Base def queue QPush.redis.with do |conn| - conn.incr("qpush:v1:#{@namespace}:stats:queued") + conn.hincrby("qpush:v1:#{@namespace}:stats", 'queued', 1) conn.lpush("qpush:v1:#{@namespace}:queue", to_json) end end end end