class Cuetip::Job

Attributes

delay_execution[W]
delete_after_execution[W]
maximum_execution_time[W]
queue_name[W]
retry_count[W]
retry_interval[W]
ttl[W]
job[R]

Return the queued job object

@return [Cuetip::Models::Job]

Public Class Methods

delay_execution() click to toggle source

The length of time (in seconds) from when this job is queued to when it should be executed

# File lib/cuetip/job.rb, line 39
def delay_execution
  @delay_execution || 0
end
delete_after_execution() click to toggle source

Should this job be deleted after execution

# File lib/cuetip/job.rb, line 45
def delete_after_execution
  @delete_after_execution || false
end
maximum_execution_time() click to toggle source

The maximum length of time (in seconds) that a job can run for

# File lib/cuetip/job.rb, line 15
def maximum_execution_time
  @maximum_execution_time || 12.hours
end
new(job) click to toggle source

Initialize this job instance by providing a queued job instance

@param queued_job [Cuetip::Models::Job]

# File lib/cuetip/job.rb, line 84
def initialize(job)
  @job = job
end
prune(before) click to toggle source

Prune jobs before a specific time

@param before [ActiveSupport::TimeWithZone] The point in time to prune jobs until.

# File lib/cuetip/job.rb, line 76
def prune(before)
  Models::Job.where('created_at < ?', before).delete_all
end
queue(params = {}, &block) click to toggle source

Queue this job

@param params [Hash] @return [Cuetip::Models::Job]

# File lib/cuetip/job.rb, line 54
def queue(params = {}, &block)
  # Create our new job
  job = Models::Job.new(class_name: name, params: params)
  # Copy over any class leve lconfig
  job.queue_name = queue_name
  job.maximum_execution_time = maximum_execution_time
  job.ttl = ttl
  job.retry_count = retry_count
  job.retry_interval = retry_interval
  job.delay_execution = delay_execution
  job.delete_after_execution = delete_after_execution
  # Call the block
  block.call(job) if block_given?
  # Create the job
  job.save!
  # Return the job
  job
end
queue_name() click to toggle source

The queue that this job should be executed on

# File lib/cuetip/job.rb, line 9
def queue_name
  @queue_name || 'default'
end
retry_count() click to toggle source

The maximum number of times this job can be run

# File lib/cuetip/job.rb, line 27
def retry_count
  @retry_count || 0
end
retry_interval() click to toggle source

The maximum length of time (in seconds) between each execution of this job

# File lib/cuetip/job.rb, line 33
def retry_interval
  @retry_interval || 1.minute
end
ttl() click to toggle source

The maximum length of time (in seconds) between the job being created and it being run

# File lib/cuetip/job.rb, line 21
def ttl
  @ttl || 6.hours
end

Public Instance Methods

perform() click to toggle source

Perform a job

@return [void]

# File lib/cuetip/job.rb, line 91
def perform; end

Private Instance Methods

logger() click to toggle source

Return a quick access for the job

@return [Logger]

# File lib/cuetip/job.rb, line 110
def logger
  Cuetip.logger
end
params() click to toggle source

Return all parameters for the job

@return [Hashie::Mash]

# File lib/cuetip/job.rb, line 98
def params
  @job.params
end