Class: Taski::Execution::Registry
- Inherits:
-
Object
- Object
- Taski::Execution::Registry
- Defined in:
- lib/taski/execution/registry.rb
Instance Method Summary collapse
-
#abort_requested? ⇒ Boolean
True if abort has been requested.
-
#create_wrapper(task_class, execution_facade:) ⇒ TaskWrapper
Create or retrieve a TaskWrapper for the given task class.
-
#failed_clean_wrappers ⇒ Array<TaskWrapper>
All wrappers that have clean errors.
-
#failed_wrappers ⇒ Array<TaskWrapper>
All wrappers that have errors.
-
#get_or_create(task_class) { ... } ⇒ Object
The task instance.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(task_class, wrapper) ⇒ Object
- #register_thread(thread) ⇒ Object
-
#registered?(task_class) ⇒ Boolean
Check if a task wrapper has been registered (created during run phase).
- #request_abort! ⇒ Object
- #reset! ⇒ Object
- #wait_all ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
8 9 10 11 12 13 |
# File 'lib/taski/execution/registry.rb', line 8 def initialize @tasks = {} @threads = [] @monitor = Monitor.new @abort_requested = false end |
Instance Method Details
#abort_requested? ⇒ Boolean
Returns true if abort has been requested.
60 61 62 |
# File 'lib/taski/execution/registry.rb', line 60 def abort_requested? @monitor.synchronize { @abort_requested } end |
#create_wrapper(task_class, execution_facade:) ⇒ TaskWrapper
Create or retrieve a TaskWrapper for the given task class. Encapsulates the standard wrapper creation pattern used by Executor and WorkerPool.
83 84 85 86 87 88 89 |
# File 'lib/taski/execution/registry.rb', line 83 def create_wrapper(task_class, execution_facade:) get_or_create(task_class) do task_instance = task_class.allocate task_instance.send(:initialize) TaskWrapper.new(task_instance, registry: self, execution_facade: execution_facade) end end |
#failed_clean_wrappers ⇒ Array<TaskWrapper>
Returns All wrappers that have clean errors.
72 73 74 75 76 |
# File 'lib/taski/execution/registry.rb', line 72 def failed_clean_wrappers @monitor.synchronize do @tasks.values.select { |w| w.clean_error } end end |
#failed_wrappers ⇒ Array<TaskWrapper>
Returns All wrappers that have errors.
65 66 67 68 69 |
# File 'lib/taski/execution/registry.rb', line 65 def failed_wrappers @monitor.synchronize do @tasks.values.select { |w| w.error } end end |
#get_or_create(task_class) { ... } ⇒ Object
Returns The task instance.
18 19 20 21 22 |
# File 'lib/taski/execution/registry.rb', line 18 def get_or_create(task_class) @monitor.synchronize do @tasks[task_class] ||= yield end end |
#register(task_class, wrapper) ⇒ Object
26 27 28 |
# File 'lib/taski/execution/registry.rb', line 26 def register(task_class, wrapper) @monitor.synchronize { @tasks[task_class] = wrapper } end |
#register_thread(thread) ⇒ Object
38 39 40 |
# File 'lib/taski/execution/registry.rb', line 38 def register_thread(thread) @monitor.synchronize { @threads << thread } end |
#registered?(task_class) ⇒ Boolean
Check if a task wrapper has been registered (created during run phase).
33 34 35 |
# File 'lib/taski/execution/registry.rb', line 33 def registered?(task_class) @monitor.synchronize { @tasks.key?(task_class) } end |
#request_abort! ⇒ Object
55 56 57 |
# File 'lib/taski/execution/registry.rb', line 55 def request_abort! @monitor.synchronize { @abort_requested = true } end |
#reset! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/taski/execution/registry.rb', line 47 def reset! @monitor.synchronize do @tasks.clear @threads.clear @abort_requested = false end end |
#wait_all ⇒ Object
42 43 44 45 |
# File 'lib/taski/execution/registry.rb', line 42 def wait_all threads = @monitor.synchronize { @threads.dup } threads.each(&:join) end |