UbiquoJobs::Managers::ActiveManager

Public Class Methods

add(type, options = {}) click to toggle source

Creates a job using the given options, and planifies it to be run according to the planification options

  type: class type of the desired job
  options: properties for the new job
    # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 81
81:       def self.add(type, options = {})
82:         job = type.new(options)
83:         job.save
84:         job
85:       end
delete(job_id) click to toggle source

Deletes a the job that has the given identifier Returns true if successfully deleted, false otherwise

  job_id: job identifier
    # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 92
92:       def self.delete(job_id)
93:         job_class.find(job_id).destroy
94:       end
get(runner) click to toggle source

Get the most appropiate job to run, depending job priorities, states dependencies and planification dates

  runner: name of the worker that is asking for a job
    # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 12
12:       def self.get(runner)
13:         recovery(runner)
14:         candidate_jobs = job_class.all(
15:           :conditions => [
16:             'planified_at <= ? AND state = ?', 
17:             Time.now.utc,
18:             UbiquoJobs::Jobs::Base::STATES[:waiting]
19:           ],
20:           :order => 'priority asc'
21:         )
22:         job = first_without_dependencies(candidate_jobs)
23:         job.update_attributes({
24:             :state => UbiquoJobs::Jobs::Base::STATES[:instantiated],
25:             :runner => runner
26:           }) if job
27:         job
28:       end
get_assigned(runner) click to toggle source

TODO: see if this can be merged in recovery Get an already assigned task for a given runner, or nil if that runner does not have any assigned task

  runner: name of the worker that is asking for a job
    # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 61
61:       def self.get_assigned(runner)
62:         job_class.first(
63:           :conditions => [
64:             "runner = ? AND state NOT IN (%i,%i)" %
65:             [
66:               UbiquoJobs::Jobs::Base::STATES[:finished], 
67:               UbiquoJobs::Jobs::Base::STATES[:error]
68:             ],
69:             runner
70:           ],
71:           :order => 'priority asc'
72:         )
73:       end
get_by_id(job_id) click to toggle source

Get the job instance that has the given job_id

  job_id: job identifier
    # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 34
34:       def self.get_by_id(job_id)
35:         job_class.find(job_id)
36:       end
job_class() click to toggle source

Return the job class that the manager is using, as a constant

  type: class type of the desired job
  options: properties for the new job
     # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 119
119:       def self.job_class
120:         UbiquoJobs::Jobs::ActiveJob
121:       end
list(filters = {}) click to toggle source

Get an array of jobs matching filters

  filters: hash of properties that the jobs must fullfill, and/or the following options:
    {
      :order => list order, sql syntax
      :page => number of the asked page, for pagination
      :per_page => number per_page job elements (default 10)
    }

Returns an array with the format [pages_information, list_of_jobs]

    # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 49
49:       def self.list(filters = {})
50:         job_class.paginate(:page => filters[:page], :per_page => filters[:per_page] || 10) do
51:           job_class.filtered_search filters, :order => filters[:order]
52:         end
53:       end
repeat(job_id) click to toggle source

Marks the job with the given identifier to be repeated

  job_id: job identifier
     # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 110
110:       def self.repeat(job_id)
111:         job_class.find(job_id).reset!
112:       end
update(job_id, options) click to toggle source

Updates the existing job that has the given identifier Returns true if successfully updated, false otherwise

  job_id: job identifier
  options: a hash with the changed properties
     # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 102
102:       def self.update(job_id, options)
103:         job_class.find(job_id).update_attributes(options)
104:       end

Protected Class Methods

first_without_dependencies(candidates) click to toggle source

Given a set of jobs, returns the first one that have all their dependencies satisfied

     # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 132
132:       def self.first_without_dependencies(candidates)
133:         candidates.each do |candidate|
134:           return candidate if candidate.dependencies.inject(true) do |satisfied, job| 
135:             satisfied && job.state == UbiquoJobs::Jobs::Base::STATES[:finished]
136:           end
137:         end
138:         nil
139:       end
recovery(runner) click to toggle source

Performs a cleanup (reset) of possible stalled jobs for the asked runner

     # File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/managers/active_manager.rb, line 126
126:       def self.recovery(runner)
127:         job = get_assigned(runner)
128:         job.reset! if job
129:       end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.