Class: BackgroundQueue::ServerLib::TaskRegistry
- Inherits:
-
Object
- Object
- BackgroundQueue::ServerLib::TaskRegistry
- Defined in:
- lib/background_queue/server_lib/task_registry.rb
Overview
keep track if tasks already queued and running so if the same task comes in, we know to remove it.
Instance Method Summary collapse
- #de_register(task_id) ⇒ Object
- #get_waiting_task(task_id) ⇒ Object
-
#initialize ⇒ TaskRegistry
constructor
A new instance of TaskRegistry.
- #register(task) ⇒ Object
- #register_waiting_task(task) ⇒ Object
- #tasks ⇒ Object
- #waiting_tasks ⇒ Object
Constructor Details
#initialize ⇒ TaskRegistry
Returns a new instance of TaskRegistry.
6 7 8 9 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 6 def initialize @waiting_tasks = {} @tasks = {} end |
Instance Method Details
#de_register(task_id) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 32 def de_register(task_id) @tasks.delete(task_id) waiting = get_waiting_task(task_id) if waiting @tasks[task_id] = waiting end waiting end |
#get_waiting_task(task_id) ⇒ Object
45 46 47 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 45 def get_waiting_task(task_id) @waiting_tasks.delete(task_id) end |
#register(task) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 11 def register(task) existing_task = @tasks[task.id] if existing_task.nil? #puts "nil task" @tasks[task.id] = task [:new, nil] elsif existing_task.running? #puts "task running" register_waiting_task(task) [:waiting, nil] elsif existing_task.waiting_to_retry? #puts "task waiting_to_retry" @tasks[task.id] = task [:waiting_to_retry, existing_task] else #puts "task waiting" @tasks[task.id] = task [:existing, existing_task] end end |
#register_waiting_task(task) ⇒ Object
41 42 43 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 41 def register_waiting_task(task) @waiting_tasks[task.id] = task end |
#tasks ⇒ Object
53 54 55 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 53 def tasks @tasks end |
#waiting_tasks ⇒ Object
49 50 51 |
# File 'lib/background_queue/server_lib/task_registry.rb', line 49 def waiting_tasks @waiting_tasks end |