Class: Conveyor::Worker
- Inherits:
-
Object
- Object
- Conveyor::Worker
- Includes:
- Output, Conveyor::Workers::Syntax
- Defined in:
- lib/conveyor/worker.rb
Constant Summary
Constants included from Output
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#worker_def ⇒ Object
readonly
Returns the value of attribute worker_def.
Instance Method Summary collapse
-
#error(*msg) ⇒ Object
Catch any calls to error and set the status fail flags.
-
#initialize(file, worker_def, log = MSGLVLS[:debug]) ⇒ Worker
constructor
A new instance of Worker.
-
#logfile ⇒ Object
Default log file to be based on worker def name.
-
#name(value = nil) ⇒ Object
Return name to be used for logging purposes.
-
#start ⇒ Object
Start the worker.
Methods included from Conveyor::Workers::Syntax
#any, #chdir, #copy, #delete, #extension, #file, #like, #match, #method_missing, #mkdir, #move, #run, #scp, #sync, #watch
Methods included from Output
#announce, #debug, #info, #loglvl, #notify, #output, #say, #send_notifications, #should_log?, #warning
Constructor Details
#initialize(file, worker_def, log = MSGLVLS[:debug]) ⇒ Worker
Returns a new instance of Worker.
15 16 17 18 19 20 21 |
# File 'lib/conveyor/worker.rb', line 15 def initialize(file, worker_def, log = MSGLVLS[:debug]) @filename = file @loglvl = log @worker_def = worker_def @notify = [] # @glob = escape_glob(glob) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Conveyor::Workers::Syntax
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/conveyor/worker.rb', line 11 def filename @filename end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/conveyor/worker.rb', line 12 def status @status end |
#worker_def ⇒ Object (readonly)
Returns the value of attribute worker_def.
13 14 15 |
# File 'lib/conveyor/worker.rb', line 13 def worker_def @worker_def end |
Instance Method Details
#error(*msg) ⇒ Object
Catch any calls to error and set the status fail flags
37 38 39 40 41 42 43 44 45 |
# File 'lib/conveyor/worker.rb', line 37 def error(*msg) opts = msg. unless msg.flatten.empty? @status.fail! msg.unshift("Error encountered in #{worker_def}") super(*msg, opts) end @status.success? end |
#logfile ⇒ Object
Default log file to be based on worker def name
31 32 33 34 |
# File 'lib/conveyor/worker.rb', line 31 def logfile dir = File.dirname(worker_def) File.(File.basename(worker_def, '.worker') + '.log', dir) end |
#name(value = nil) ⇒ Object
Return name to be used for logging purposes
24 25 26 27 28 |
# File 'lib/conveyor/worker.rb', line 24 def name(value=nil) @name = value unless value.nil? @name ||= File.basename(worker_def) @name end |
#start ⇒ Object
Start the worker
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/conveyor/worker.rb', line 48 def start @status = Conveyor::Status.new(@filename) info "Starting #{@filename}", :color => :green @start = Time.now begin instance_eval(File.read(@worker_def), worker_def) ensure @elapsed = "%0.2f"%(Time.now - @start) #Check status and send any errors we collected if @status.success? info "Completed #{@filename}, #{@elapsed}s elapsed", :color => :green else error "Error(s) encountered in #{@filename}", :color => :red end send_notifications end end |