Class: BackgroundQueue::ServerLib::Task
- Inherits:
-
Object
- Object
- BackgroundQueue::ServerLib::Task
- Defined in:
- lib/background_queue/server_lib/task.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#owner_id ⇒ Object
Returns the value of attribute owner_id.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#running ⇒ Object
Returns the value of attribute running.
-
#worker ⇒ Object
Returns the value of attribute worker.
Instance Method Summary collapse
- #domain ⇒ Object
- #initial_progress_caption ⇒ Object
-
#initialize(owner_id, job_id, id, priority, worker, params, options) ⇒ Task
constructor
A new instance of Task.
- #is_excluded_from_count? ⇒ Boolean
- #running? ⇒ Boolean
- #set_job(job) ⇒ Object
- #set_worker_status(status) ⇒ Object
- #synchronous? ⇒ Boolean
- #to_json(dummy = true) ⇒ Object
- #to_json_object(full) ⇒ Object
- #weighted? ⇒ Boolean
- #weighted_percent ⇒ Object
Constructor Details
#initialize(owner_id, job_id, id, priority, worker, params, options) ⇒ Task
Returns a new instance of Task.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/background_queue/server_lib/task.rb', line 16 def initialize(owner_id, job_id, id, priority, worker, params, ) @owner_id = owner_id @job_id = job_id @id = id @priority = priority @worker = worker @running = false @options = @params = params end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/background_queue/server_lib/task.rb', line 4 def id @id end |
#job_id ⇒ Object
Returns the value of attribute job_id.
8 9 10 |
# File 'lib/background_queue/server_lib/task.rb', line 8 def job_id @job_id end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/background_queue/server_lib/task.rb', line 14 def @options end |
#owner_id ⇒ Object
Returns the value of attribute owner_id.
7 8 9 |
# File 'lib/background_queue/server_lib/task.rb', line 7 def owner_id @owner_id end |
#priority ⇒ Object
Returns the value of attribute priority.
5 6 7 |
# File 'lib/background_queue/server_lib/task.rb', line 5 def priority @priority end |
#running ⇒ Object
Returns the value of attribute running.
12 13 14 |
# File 'lib/background_queue/server_lib/task.rb', line 12 def running @running end |
#worker ⇒ Object
Returns the value of attribute worker.
10 11 12 |
# File 'lib/background_queue/server_lib/task.rb', line 10 def worker @worker end |
Instance Method Details
#domain ⇒ Object
43 44 45 |
# File 'lib/background_queue/server_lib/task.rb', line 43 def domain @options[:domain] end |
#initial_progress_caption ⇒ Object
67 68 69 |
# File 'lib/background_queue/server_lib/task.rb', line 67 def @options[:initial_progress_caption] end |
#is_excluded_from_count? ⇒ Boolean
51 52 53 |
# File 'lib/background_queue/server_lib/task.rb', line 51 def is_excluded_from_count? @options[:exclude] == true end |
#running? ⇒ Boolean
39 40 41 |
# File 'lib/background_queue/server_lib/task.rb', line 39 def running? @running end |
#set_job(job) ⇒ Object
47 48 49 |
# File 'lib/background_queue/server_lib/task.rb', line 47 def set_job(job) @job = job end |
#set_worker_status(status) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/background_queue/server_lib/task.rb', line 71 def set_worker_status(status) raise "Task without job set" if @job.nil? status[:task_id] = self.id status[:exclude] = self.is_excluded_from_count? status[:weight] = self.weighted_percent if self.weighted? @job.set_worker_status(status) end |
#synchronous? ⇒ Boolean
55 56 57 |
# File 'lib/background_queue/server_lib/task.rb', line 55 def synchronous? @options[:synchronous] == true end |
#to_json(dummy = true) ⇒ Object
27 28 29 |
# File 'lib/background_queue/server_lib/task.rb', line 27 def to_json(dummy=true) to_json_object(false).to_json end |
#to_json_object(full) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/background_queue/server_lib/task.rb', line 31 def to_json_object(full) jo = {:owner_id=>@owner_id, :job_id=>@job_id, :id=>@id, :priority=>@priority, :worker=>@worker, :params=>@params } if full jo[:options] = @options end jo end |
#weighted? ⇒ Boolean
59 60 61 |
# File 'lib/background_queue/server_lib/task.rb', line 59 def weighted? @options[:weight] && @options[:weight] > 0 end |
#weighted_percent ⇒ Object
63 64 65 |
# File 'lib/background_queue/server_lib/task.rb', line 63 def weighted_percent @options[:weight] end |