Class: Whirl::Job::Base
- Inherits:
-
Object
- Object
- Whirl::Job::Base
- Defined in:
- lib/whirl/job/base.rb
Class Attribute Summary collapse
-
.job_action ⇒ Object
Returns the value of attribute job_action.
Class Method Summary collapse
- .action(&block) ⇒ Object
- .newline ⇒ Object
- .perform ⇒ Object
- .redis ⇒ Object
- .redis_key(val) ⇒ Object
- .say(*args) ⇒ Object
Class Attribute Details
.job_action ⇒ Object
Returns the value of attribute job_action.
8 9 10 |
# File 'lib/whirl/job/base.rb', line 8 def job_action @job_action end |
Class Method Details
.action(&block) ⇒ Object
11 12 13 |
# File 'lib/whirl/job/base.rb', line 11 def self.action(&block) self.job_action = block end |
.newline ⇒ Object
30 31 32 |
# File 'lib/whirl/job/base.rb', line 30 def self.newline puts "\n" end |
.perform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/whirl/job/base.rb', line 15 def self.perform say "starting...", :blue begin job_action.call rescue Exception => e say "Job #{self.name} failed!", :red say ".. Reason: #{e.}", :red if ENV['DEBUG'] say ".. Backtrace:" puts e.backtrace end ensure end end |
.redis ⇒ Object
45 46 47 |
# File 'lib/whirl/job/base.rb', line 45 def self.redis @redis ||= Whirl::Redis.new end |
.redis_key(val) ⇒ Object
41 42 43 |
# File 'lib/whirl/job/base.rb', line 41 def self.redis_key(val) "#{self.name}:#{val}" end |
.say(*args) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/whirl/job/base.rb', line 34 def self.say(*args) args.push :cyan if args.size == 1 @shell ||= Thor::Shell::Color.new = "#{self.name.ljust(28, " ")} === #{args.shift}" @shell.say *[, *args] end |