Module: Fasten
- Defined in:
- lib/fasten.rb,
lib/fasten/task.rb,
lib/fasten/runner.rb,
lib/fasten/worker.rb,
lib/fasten/version.rb,
lib/fasten/defaults.rb,
lib/fasten/ui/curses.rb,
lib/fasten/support/ui.rb,
lib/fasten/ui/console.rb,
lib/fasten/support/yaml.rb,
lib/fasten/task_manager.rb,
lib/fasten/support/state.rb,
lib/fasten/support/stats.rb,
lib/fasten/timeout_queue.rb,
lib/fasten/support/logger.rb,
lib/fasten/std_thread_proxy.rb,
lib/fasten/support/fork_worker.rb,
lib/fasten/support/thread_worker.rb
Defined Under Namespace
Modules: Support, UI Classes: Runner, StdThreadProxy, Task, TaskManager, TimeoutQueue, Worker, WorkerError
Constant Summary collapse
- VERSION =
'0.18.0'
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .cleanup ⇒ Object
- .default_developer ⇒ Object
- .default_fasten_dir ⇒ Object
- .default_jobs ⇒ Object
- .default_name ⇒ Object
- .default_priority ⇒ Object
- .default_stats ⇒ Object
- .default_summary ⇒ Object
- .default_ui_mode ⇒ Object
- .default_use_threads ⇒ Object
- .default_worker_class ⇒ Object
- .invoke ⇒ Object
- .load_fasten(args) ⇒ Object
- .map(list, **options, &block) ⇒ Object
-
.opt_parser ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
- .reconfigure(**options) ⇒ Object
- .register(**options, &block) ⇒ Object
- .runner(**options) ⇒ Object
- .runner_from_yaml(path, **options) ⇒ Object
- .show_help(exit_code = 0) ⇒ Object
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/fasten/support/logger.rb', line 7 def logger @logger end |
Class Method Details
.cleanup ⇒ Object
29 30 31 |
# File 'lib/fasten.rb', line 29 def cleanup @runner = nil end |
.default_developer ⇒ Object
43 44 45 |
# File 'lib/fasten/defaults.rb', line 43 def default_developer $stdin.tty? && $stdout.tty? end |
.default_fasten_dir ⇒ Object
25 26 27 |
# File 'lib/fasten/defaults.rb', line 25 def default_fasten_dir 'fasten' end |
.default_jobs ⇒ Object
17 18 19 |
# File 'lib/fasten/defaults.rb', line 17 def default_jobs Parallel.physical_processor_count end |
.default_name ⇒ Object
5 6 7 |
# File 'lib/fasten/defaults.rb', line 5 def default_name File.basename(Dir.getwd) end |
.default_priority ⇒ Object
47 48 49 |
# File 'lib/fasten/defaults.rb', line 47 def default_priority :dependants end |
.default_stats ⇒ Object
9 10 11 |
# File 'lib/fasten/defaults.rb', line 9 def default_stats true end |
.default_summary ⇒ Object
13 14 15 |
# File 'lib/fasten/defaults.rb', line 13 def default_summary false end |
.default_ui_mode ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/fasten/defaults.rb', line 33 def default_ui_mode return @default_ui_mode if defined? @default_ui_mode require 'fasten/ui/curses' @default_ui_mode = $stdin.tty? && $stdout.tty? ? :curses : :console rescue StandardError, LoadError @default_ui_mode = :console end |
.default_use_threads ⇒ Object
29 30 31 |
# File 'lib/fasten/defaults.rb', line 29 def default_use_threads !OS.posix? end |
.default_worker_class ⇒ Object
21 22 23 |
# File 'lib/fasten/defaults.rb', line 21 def default_worker_class Worker end |
.invoke ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/fasten.rb', line 111 def invoke opt_parser.parse! @options[:targets] = ARGV.to_a runner **@options @load_path = Dir['fasten/*_fasten.rb'] if @load_path.empty? load_fasten @load_path show_help 1 if runner.tasks.empty? runner.perform end |
.load_fasten(args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fasten.rb', line 41 def load_fasten(args) args.each do |path| if File.directory? path items = Dir["#{path}/*_fasten.rb"] items.each do |item| puts "Fasten: loading #{item}" load item end elsif File.file? path puts "Fasten: loading #{path}" load path else warn "Fasten: file/folder not found: #{path}" exit 1 end end end |
.map(list, **options, &block) ⇒ Object
21 22 23 |
# File 'lib/fasten.rb', line 21 def map(list, **, &block) runner(**).map(list, &block) end |
.opt_parser ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/fasten.rb', line 59 def opt_parser # rubocop:disable Metrics/MethodLength, Metrics/AbcSize return @opt_parser if defined? @opt_parser @options = { developer: false } @load_path = [] @opt_parser = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength opts. = "Usage: #{$PROGRAM_NAME} [options] [targets]" opts.separator '' opts.separator 'Examples:' opts.separator ' fasten # load and run all task from fasten/*_fasten.rb' opts.separator ' fasten -f tasks.rb # load task from ruby script' opts.separator ' fasten -y tasks.yml # load task from yaml file' opts.separator '' opts.separator 'Options:' opts.on '-n NAME', '--name NAME', String, "Change name of this runner (default: #{default_name} from current directory)" do |name| @options[:name] = name end opts.on '-f PATH', '--file PATH', String, 'File or folder with ruby code' do |path| @load_path << path end opts.on '-j JOBS', '--jobs JOBS', Numeric, "Maximum number of tasks to execute in parallel (default: #{default_jobs} on this machine)" do |jobs| @options[:jobs] = jobs end opts.on '-s', '--[no-]summary', TrueClass, 'Display summary at the end of execution' do |boolean| @options[:summary] = boolean end opts.on '--ui=UI', String, "Type of UI: curses, console. (default: #{default_ui_mode} on this machine)" do |ui_mode| @options[:ui_mode] = ui_mode end opts.on '-t', '--threads', "Use threads based jobs for parallel execution#{default_use_threads && ' (default on this machine)' || nil}" do @options[:use_threads] = true end opts.on '-p', '--processes', "Use process based jobs for parallel execution#{!default_use_threads && ' (default on this machine)' || nil}" do @options[:use_threads] = false end opts.on '-v', '--version', 'Display version info' do puts Fasten::VERSION exit 0 end opts.on_tail '-h', '--help', 'Shows this help' do show_help end end end |
.reconfigure(**options) ⇒ Object
33 34 35 |
# File 'lib/fasten.rb', line 33 def reconfigure(**) runner.reconfigure(**) end |
.register(**options, &block) ⇒ Object
37 38 39 |
# File 'lib/fasten.rb', line 37 def register(**, &block) runner(**).register(&block) end |
.runner(**options) ⇒ Object
25 26 27 |
# File 'lib/fasten.rb', line 25 def runner(**) @runner ||= Fasten::Runner.new(**) end |
.runner_from_yaml(path, **options) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/fasten.rb', line 14 def runner_from_yaml(path, **) runner = Fasten::Runner.new(**) runner.load_yaml(path) runner end |
.show_help(exit_code = 0) ⇒ Object
106 107 108 109 |
# File 'lib/fasten.rb', line 106 def show_help(exit_code = 0) puts opt_parser exit exit_code end |