Module: Taski

Defined in:
lib/taski.rb,
lib/taski/env.rb,
lib/taski/args.rb,
lib/taski/task.rb,
lib/taski/logging.rb,
lib/taski/version.rb,
lib/taski/task_proxy.rb,
lib/taski/test_helper.rb,
lib/taski/progress/config.rb,
lib/taski/test_helper/rspec.rb,
lib/taski/execution/executor.rb,
lib/taski/execution/registry.rb,
lib/taski/test_helper/errors.rb,
lib/taski/execution/scheduler.rb,
lib/taski/progress/layout/log.rb,
lib/taski/progress/theme/base.rb,
lib/taski/progress/layout/base.rb,
lib/taski/progress/layout/tags.rb,
lib/taski/progress/layout/tree.rb,
lib/taski/progress/theme/plain.rb,
lib/taski/test_helper/minitest.rb,
lib/taski/execution/worker_pool.rb,
lib/taski/progress/theme/detail.rb,
lib/taski/execution/task_wrapper.rb,
lib/taski/progress/layout/simple.rb,
lib/taski/progress/theme/compact.rb,
lib/taski/progress/theme/default.rb,
lib/taski/execution/task_observer.rb,
lib/taski/progress/layout/filters.rb,
lib/taski/static_analysis/visitor.rb,
lib/taski/execution/fiber_protocol.rb,
lib/taski/static_analysis/analyzer.rb,
lib/taski/test_helper/mock_wrapper.rb,
lib/taski/progress/layout/tree/live.rb,
lib/taski/test_helper/mock_registry.rb,
lib/taski/execution/execution_facade.rb,
lib/taski/execution/task_output_pipe.rb,
lib/taski/progress/layout/theme_drop.rb,
lib/taski/progress/layout/tree/event.rb,
lib/taski/execution/task_output_router.rb,
lib/taski/progress/layout/tree/structure.rb,
lib/taski/static_analysis/dependency_graph.rb,
lib/taski/static_analysis/start_dep_analyzer.rb

Defined Under Namespace

Modules: AggregateAware, Execution, Logging, Progress, StaticAnalysis, TestHelper Classes: AggregateError, Args, CircularDependencyError, Env, Task, TaskAbortException, TaskError, TaskFailure, TaskProxy

Constant Summary collapse

PROGRESS_MONITOR =
Monitor.new
PROGRESS_NOT_SET =
Object.new.freeze
VERSION =
"0.10.0"

Class Method Summary collapse

Class Method Details

.argsArgs?

Get the current runtime arguments

Returns:

  • (Args, nil)

    The current args or nil if no task is running



182
183
184
# File 'lib/taski.rb', line 182

def self.args
  @args_monitor.synchronize { @args }
end

.args_worker_countInteger?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the worker count from the current args (set via Task.run(workers: n))

Returns:

  • (Integer, nil)

    The worker count or nil to use WorkerPool default



320
321
322
# File 'lib/taski.rb', line 320

def self.args_worker_count
  args&.fetch(:_workers, nil)
end

.clear_current_registryObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clear the current registry for this thread (internal use only)



339
340
341
# File 'lib/taski.rb', line 339

def self.clear_current_registry
  Thread.current[:taski_current_registry] = nil
end

.current_registryExecution::Registry?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the current registry for this thread (used during dependency resolution)

Returns:



327
328
329
# File 'lib/taski.rb', line 327

def self.current_registry
  Thread.current[:taski_current_registry]
end

.envEnv?

Get the current execution environment

Returns:

  • (Env, nil)

    The current env or nil if no task is running



188
189
190
# File 'lib/taski.rb', line 188

def self.env
  @env_monitor.synchronize { @env }
end

.loggerLogger?

Get the current logger for structured logging

Returns:

  • (Logger, nil)

    The configured logger or nil (disabled by default)



170
171
172
# File 'lib/taski.rb', line 170

def self.logger
  @logger_monitor.synchronize { @logger }
end

.logger=(logger) ⇒ Object

Set the logger for structured logging

Parameters:

  • logger (Logger, nil)

    A Ruby Logger instance or nil to disable logging



176
177
178
# File 'lib/taski.rb', line 176

def self.logger=(logger)
  @logger_monitor.synchronize { @logger = logger }
end

.message(text) ⇒ Object

Output a message to the user without being captured by TaskOutputRouter. During task execution with progress display, messages are queued and displayed after execution completes. Without progress display or outside task execution, messages are output immediately.

Parameters:

  • text (String)

    The message text to display



198
199
200
201
202
203
204
205
206
207
# File 'lib/taski.rb', line 198

def self.message(text)
  @message_monitor.synchronize do
    progress = progress_display
    if progress&.respond_to?(:queue_message)
      progress.queue_message(text)
    else
      $stdout.puts(text)
    end
  end
end

.progressProgress::Config

Get the progress configuration singleton.

Returns:



285
286
287
# File 'lib/taski.rb', line 285

def self.progress
  PROGRESS_MONITOR.synchronize { @progress_config }
end

.progress_displayObject



289
290
291
292
293
294
295
296
# File 'lib/taski.rb', line 289

def self.progress_display
  PROGRESS_MONITOR.synchronize do
    if @progress_display.equal?(PROGRESS_NOT_SET)
      @progress_display = @progress_config.build
    end
    @progress_display
  end
end

.progress_display=(display) ⇒ Object



298
299
300
301
302
303
304
305
# File 'lib/taski.rb', line 298

def self.progress_display=(display)
  PROGRESS_MONITOR.synchronize do
    unless @progress_display.equal?(PROGRESS_NOT_SET)
      @progress_display.stop if @progress_display.respond_to?(:stop)
    end
    @progress_display = display
  end
end

.reset_args!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reset the runtime arguments (internal use only)



253
254
255
# File 'lib/taski.rb', line 253

def self.reset_args!
  @args_monitor.synchronize { @args = nil }
end

.reset_env!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reset the execution environment (internal use only)



222
223
224
# File 'lib/taski.rb', line 222

def self.reset_env!
  @env_monitor.synchronize { @env = nil }
end

.reset_progress_display!Object



307
308
309
310
311
312
313
314
315
# File 'lib/taski.rb', line 307

def self.reset_progress_display!
  PROGRESS_MONITOR.synchronize do
    unless @progress_display.equal?(PROGRESS_NOT_SET)
      @progress_display.stop if @progress_display.respond_to?(:stop)
    end
    @progress_display = PROGRESS_NOT_SET
    @progress_config.reset
  end
end

.set_current_registry(registry) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the current registry for this thread (internal use only)



333
334
335
# File 'lib/taski.rb', line 333

def self.set_current_registry(registry)
  Thread.current[:taski_current_registry] = registry
end

.start_args(options:) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start new runtime arguments (internal use only)

Returns:

  • (Boolean)

    true if this call created the args, false if args already existed



243
244
245
246
247
248
249
# File 'lib/taski.rb', line 243

def self.start_args(options:)
  @args_monitor.synchronize do
    return false if @args
    @args = Args.new(options: options)
    true
  end
end

.start_env(root_task:) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start new execution environment (internal use only)

Returns:

  • (Boolean)

    true if this call created the env, false if env already existed



212
213
214
215
216
217
218
# File 'lib/taski.rb', line 212

def self.start_env(root_task:)
  @env_monitor.synchronize do
    return false if @env
    @env = Env.new(root_task: root_task)
    true
  end
end

.with_args(options:) { ... } ⇒ Object

Execute a block with args lifecycle management. Creates args if they don't exist, and resets them only if this call created them. This prevents race conditions in concurrent execution.

Parameters:

  • options (Hash)

    User-defined options

Yields:

  • The block to execute with args available

Returns:

  • (Object)

    The result of the block



264
265
266
267
268
269
# File 'lib/taski.rb', line 264

def self.with_args(options:)
  created_args = start_args(options: options)
  yield
ensure
  reset_args! if created_args
end

.with_env(root_task:) { ... } ⇒ Object

Execute a block with env lifecycle management. Creates env if it doesn't exist, and resets it only if this call created it. This prevents race conditions in concurrent execution.

Parameters:

  • root_task (Class)

    The root task class

Yields:

  • The block to execute with env available

Returns:

  • (Object)

    The result of the block



233
234
235
236
237
238
# File 'lib/taski.rb', line 233

def self.with_env(root_task:)
  created_env = start_env(root_task: root_task)
  yield
ensure
  reset_env! if created_env
end