class QPush::Base::Job

Attributes

args[R]
created_at[RW]
cron[RW]
failed[R]
id[RW]
klass[RW]
namespace[RW]
priority[RW]
retry_max[RW]
run_time[RW]
start_at[RW]
total_fail[RW]
total_success[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/qpush/base/job.rb, line 17
def initialize(options = {})
  options = defaults.merge(options)
  options.each { |key, value| send("#{key}=", value) }
end

Public Instance Methods

args=(args) click to toggle source
# File lib/qpush/base/job.rb, line 22
def args=(args)
  @args =
    if args.is_a?(String) then JSON.parse(args)
    else args
    end
rescue JSON::ParserError
  @args = nil
end
failed=(failed) click to toggle source
# File lib/qpush/base/job.rb, line 31
def failed=(failed)
  @failed = failed == 'true' || failed == true
end
to_json() click to toggle source
# File lib/qpush/base/job.rb, line 35
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 Instance Methods

defaults() click to toggle source
# File lib/qpush/base/job.rb, line 51
def defaults
  { id: SecureRandom.urlsafe_base64,
    args: {},
    priority: 3,
    created_at: Time.now.to_i,
    start_at: Time.now.to_i - 1,
    cron: '',
    retry_max: 10,
    total_fail: 0,
    total_success: 0,
    failed: false,
    namespace: 'default' }
end