Class: Beanpicker::Worker
- Inherits:
-
Object
- Object
- Beanpicker::Worker
- Includes:
- MsgLogger
- Defined in:
- lib/beanpicker/job_server.rb
Overview
Worker is the class used to create jobs
Defined Under Namespace
Classes: Child
Instance Attribute Summary collapse
-
#childs ⇒ Object
readonly
The list of childs.
-
#name ⇒ Object
readonly
The name of worker.
Instance Method Summary collapse
-
#initialize(filepath = nil, args = {}, &blk) ⇒ Worker
constructor
Accept a file and/or a block with jobs and add itself to workers list.
-
#job(name, args = {}, &blk) ⇒ Object
Pass the job to Child::process and add the return to childs list.
-
#log_file(f) ⇒ Object
Shortcut to log_handler=.
-
#log_handler ⇒ Object
Use it own log_handler or global if not defined.
Methods included from MsgLogger
#debug, #error, #fatal, #info, #log_handler=, #msg, #warn
Constructor Details
#initialize(filepath = nil, args = {}, &blk) ⇒ Worker
Accept a file and/or a block with jobs and add itself to workers list
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 105 |
# File 'lib/beanpicker/job_server.rb', line 80 def initialize(filepath=nil, args={}, &blk) @childs = [] @name = args[:name] rescue nil if filepath @name = filepath.split(/[\\\/]/)[-1].gsub(/\.[^\.]+$/,'').split(/[_\.]/).map do |x| x.capitalize end.join if @name.nil? begin instance_eval File.read(filepath) rescue => e error Beanpicker::(e, "when loading file #{filepath}") end end if block_given? begin instance_eval(&blk) rescue => e error Beanpicker::(e, "when evaluating block") end end @name = "BeanpickerWorker without name" unless @name Beanpicker::add_worker(self) end |
Instance Attribute Details
#childs ⇒ Object (readonly)
The list of childs
77 78 79 |
# File 'lib/beanpicker/job_server.rb', line 77 def childs @childs end |
#name ⇒ Object (readonly)
The name of worker. Pick from args or from the name of file(if passed)
75 76 77 |
# File 'lib/beanpicker/job_server.rb', line 75 def name @name end |
Instance Method Details
#job(name, args = {}, &blk) ⇒ Object
Pass the job to Child::process and add the return to childs list
108 109 110 111 |
# File 'lib/beanpicker/job_server.rb', line 108 def job(name, args={}, &blk) @childs << Child.process(name, args, self, &blk) @childs.flatten! end |
#log_file(f) ⇒ Object
Shortcut to log_handler=
119 120 121 122 |
# File 'lib/beanpicker/job_server.rb', line 119 def log_file(f) #without self call don't call log_handler= of this class Oo self.log_handler = f end |
#log_handler ⇒ Object
Use it own log_handler or global if not defined
114 115 116 |
# File 'lib/beanpicker/job_server.rb', line 114 def log_handler @log_handler || Beanpicker::log_handler end |