Class: Whirl::Job::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/whirl/job/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.job_actionObject

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

.newlineObject



30
31
32
# File 'lib/whirl/job/base.rb', line 30

def self.newline
  puts "\n"
end

.performObject



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.message}", :red
    if ENV['DEBUG']
      say ".. Backtrace:"
      puts e.backtrace
    end
  ensure
  end
end

.redisObject



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
  message = "#{self.name.ljust(28, " ")} === #{args.shift}"
  @shell.say *[message, *args]
end