Class: Jobly::Job

Inherits:
Object
  • Object
show all
Includes:
Helpers, Jobly::JobExtensions::Actions, Jobly::JobExtensions::Isolation, Jobly::JobExtensions::OptionAccessors, Jobly::JobExtensions::Solo, Sidekiq::Status::Worker, Sidekiq::Worker
Defined in:
lib/jobly/job.rb

Direct Known Subclasses

Job, Ping

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

included

Methods included from Jobly::JobExtensions::Isolation

#in_isolation, included, #isolated?

Methods included from Jobly::JobExtensions::Solo

included, #solo?, #solo_full_key, #solo_key, #solo_key!, #solo_lock, #solo_locked?, #solo_unlock

Methods included from Jobly::JobExtensions::Actions

included, #skip_job, #skipped?

Methods included from Jobly::JobExtensions::OptionAccessors

included, #options

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



18
19
20
# File 'lib/jobly/job.rb', line 18

def params
  @params
end

Class Method Details

.run(params = {}) ⇒ Object

Allow running a job with ‘JobName.run`



22
23
24
# File 'lib/jobly/job.rb', line 22

def run(params = {})
  new.perform params
end

.run_later(params = {}) ⇒ Object

Allow running a job asynchronously with ‘JobName.run_later`



27
28
29
# File 'lib/jobly/job.rb', line 27

def run_later(params = {})
  perform_async params
end

Instance Method Details

#execute(params = {}) ⇒ Object

Inheriting classes must implement this method only.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/jobly/job.rb', line 53

def execute(params = {})
  raise NotImplementedError
end

#perform(params = {}) ⇒ Object

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.



38
39
40
41
42
43
44
# File 'lib/jobly/job.rb', line 38

def perform(params = {})
  if isolated?
    in_isolation { perform! params }
  else
    perform! params
  end
end

#perform!(params = {}) ⇒ Object

Run the job with its filters and actions.



47
48
49
50
# File 'lib/jobly/job.rb', line 47

def perform!(params = {})
  @params = params
  run_to_completion if run_before_filter
end