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
- #get_error_count ⇒ Object
- #get_error_status ⇒ Object
- #get_job ⇒ Object
- #increment_error_count ⇒ 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
- #replaced_while_waiting_to_retry? ⇒ Boolean
- #running? ⇒ Boolean
- #send_summary? ⇒ Boolean
- #set_error_status(e_status) ⇒ Object
- #set_job(job) ⇒ Object
- #set_worker_status(status) ⇒ Object
- #step ⇒ Object
- #synchronous? ⇒ Boolean
- #to_json(dummy = true) ⇒ Object
- #to_json_object(full) ⇒ Object
- #waiting_to_retry? ⇒ Boolean
- #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 26 |
# 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 raise "Missing priority" if @priority.nil? @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
44 45 46 |
# File 'lib/background_queue/server_lib/task.rb', line 44 def domain @options[:domain] end |
#get_error_count ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/background_queue/server_lib/task.rb', line 80 def get_error_count if @error_count.nil? 0 else @error_count end end |
#get_error_status ⇒ Object
92 93 94 |
# File 'lib/background_queue/server_lib/task.rb', line 92 def get_error_status @error_status end |
#get_job ⇒ Object
52 53 54 |
# File 'lib/background_queue/server_lib/task.rb', line 52 def get_job @job end |
#increment_error_count ⇒ Object
104 105 106 |
# File 'lib/background_queue/server_lib/task.rb', line 104 def increment_error_count @error_count = get_error_count + 1 end |
#initial_progress_caption ⇒ Object
72 73 74 |
# File 'lib/background_queue/server_lib/task.rb', line 72 def @options[:initial_progress_caption] end |
#is_excluded_from_count? ⇒ Boolean
56 57 58 |
# File 'lib/background_queue/server_lib/task.rb', line 56 def is_excluded_from_count? @options[:exclude] == true end |
#replaced_while_waiting_to_retry? ⇒ Boolean
100 101 102 |
# File 'lib/background_queue/server_lib/task.rb', line 100 def replaced_while_waiting_to_retry? @error_status == :replaced_while_waiting_to_retry end |
#running? ⇒ Boolean
40 41 42 |
# File 'lib/background_queue/server_lib/task.rb', line 40 def running? @running end |
#send_summary? ⇒ Boolean
76 77 78 |
# File 'lib/background_queue/server_lib/task.rb', line 76 def send_summary? @options[:send_summary] end |
#set_error_status(e_status) ⇒ Object
88 89 90 |
# File 'lib/background_queue/server_lib/task.rb', line 88 def set_error_status(e_status) @error_status = e_status end |
#set_job(job) ⇒ Object
48 49 50 |
# File 'lib/background_queue/server_lib/task.rb', line 48 def set_job(job) @job = job end |
#set_worker_status(status) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/background_queue/server_lib/task.rb', line 113 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 |
#step ⇒ Object
108 109 110 |
# File 'lib/background_queue/server_lib/task.rb', line 108 def step @options[:step] end |
#synchronous? ⇒ Boolean
60 61 62 |
# File 'lib/background_queue/server_lib/task.rb', line 60 def synchronous? @options[:synchronous] == true end |
#to_json(dummy = true) ⇒ Object
28 29 30 |
# File 'lib/background_queue/server_lib/task.rb', line 28 def to_json(dummy=true) to_json_object(false).to_json end |
#to_json_object(full) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/background_queue/server_lib/task.rb', line 32 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 |
#waiting_to_retry? ⇒ Boolean
96 97 98 |
# File 'lib/background_queue/server_lib/task.rb', line 96 def waiting_to_retry? @error_status == :waiting_to_retry end |
#weighted? ⇒ Boolean
64 65 66 |
# File 'lib/background_queue/server_lib/task.rb', line 64 def weighted? @options[:weight] && @options[:weight] > 0 end |
#weighted_percent ⇒ Object
68 69 70 |
# File 'lib/background_queue/server_lib/task.rb', line 68 def weighted_percent @options[:weight] end |