Module: Fluke
- Defined in:
- lib/fluke.rb,
lib/fluke/cli.rb,
lib/fluke/result.rb,
lib/fluke/watcher.rb,
lib/fluke/monkey_patch.rb
Defined Under Namespace
Modules: Delays
Classes: CLI, Result, Watcher
Constant Summary
collapse
- VERSION =
'0.0.4'
- ROOT =
Dir.new(File.expand_path(File.dirname(__FILE__) + "/../"))
- DEFAULT_CONF_PATH =
"~/.fluke.yml"
- @@verbose =
false
- @@watchers =
{}
Class Method Summary
collapse
Class Method Details
.conf ⇒ Object
30
31
32
|
# File 'lib/fluke.rb', line 30
def self.conf
@@conf.dup
end
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/fluke.rb', line 49
def self.configure!(opts = {})
p = {
:conf_path => File.expand_path(DEFAULT_CONF_PATH),
:stdout => STDOUT,
:stderr => STDERR,
:log_here => :stderr
}
p.merge! opts
@@log_here = p[p[:log_here]] || p[:stderr]
begin
@@conf = YAML::load(File.open(p[:conf_path]))
if !@@conf[:proxy].nil?
@@conf[:s3][:connection][:proxy] = @@conf[:proxy]
@@conf[:proxy_string] = "http://#{@@conf[:proxy][:host]}:#{@@conf[:proxy][:port]}"
end
ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.logger = Logger.new(@@log_here) if verbose?
ActiveRecord::Base.establish_connection(@@conf[:db])
AWS::S3::Base.establish_connection!(@@conf[:s3][:connection])
Result::Body.set_current_bucket_to @@conf[:s3][:bucket][:result]
rescue => e
STDERR.puts e.inspect
return false
end
return true
end
|
.log ⇒ Object
34
35
36
37
|
# File 'lib/fluke.rb', line 34
def self.log
return unless verbose? and block_given?
@@log_here.puts yield
end
|
.run! ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/fluke.rb', line 77
def self.run!
watchers.each do |n,watcher|
watcher.thread = Thread.new do
while true
begin
watcher.run
watcher.wait
rescue => e
Fluke.log { "#{watcher}: failed to run: #{e.inspect}; backtrace: #{e.backtrace.join("; ")}" }
end
end
end
end
sleep while true
end
|
.verbose=(v = false) ⇒ Object
22
23
24
|
# File 'lib/fluke.rb', line 22
def self.verbose=(v = false)
@@verbose = v ? true : false
end
|
.verbose? ⇒ Boolean
18
19
20
|
# File 'lib/fluke.rb', line 18
def self.verbose?
@@verbose
end
|
.watch(watcher, &init) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/fluke.rb', line 39
def self.watch(watcher, &init)
unless watcher.is_a?(Watcher)
watcher = Watcher.find_by_name(watcher.to_s)
end
watchers[watcher.name] = watcher
if init
watcher.instance_eval &init
end
end
|
.watchers ⇒ Object
26
27
28
|
# File 'lib/fluke.rb', line 26
def self.watchers
@@watchers
end
|