class Jobly::Job

Attributes

params[R]

Public Class Methods

run(params = {}) click to toggle source

Allow running a job with `JobName.run`

# File lib/jobly/job.rb, line 22
def run(params = {})
  new.perform params
end
run_later(params = {}) click to toggle source

Allow running a job asynchronously with `JobName.run_later`

# File lib/jobly/job.rb, line 27
def run_later(params = {})
  perform_async params
end

Public Instance Methods

execute(params = {}) click to toggle source

Inheriting classes must implement this method only.

# File lib/jobly/job.rb, line 53
def execute(params = {})
  raise NotImplementedError
end
perform(params = {}) click to toggle source

This is the method sidekiq will call. We capture this call and convert the hash argument which was converted to array on sidekiq's side, back to a hash so we can forward to the job's `execute` method, which may implement keyword args. If the job was marked as isolated, we will run it in its own temporary directory.

# File lib/jobly/job.rb, line 38
def perform(params = {})
  if isolated?
    in_isolation { perform! params }
  else
    perform! params
  end
end
perform!(params = {}) click to toggle source

Run the job with its filters and actions.

# File lib/jobly/job.rb, line 47
def perform!(params = {})
  @params = params
  run_to_completion if run_before_filter
end

Private Instance Methods

run_before_filter() click to toggle source
# File lib/jobly/job.rb, line 59
def run_before_filter
  run_actions :before
  if skipped?
    run_actions :skip
    run_actions :after
    return false
  end
  return true
end
run_to_completion() click to toggle source
# File lib/jobly/job.rb, line 69
def run_to_completion
  params.empty? ? execute : execute(**params.to_kwargs)
  run_actions :success

rescue
  run_actions :failure
  raise

ensure
  run_actions :after
  
end