Class: Aesop::Bootloader
- Inherits:
-
Object
show all
- Includes:
- Aesop
- Defined in:
- lib/aesop/bootloader.rb
Constant Summary
Constants included
from Aesop
VERSION
Instance Method Summary
collapse
Methods included from Aesop
#configuration, configuration
Instance Method Details
#boot ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/aesop/bootloader.rb', line 4
def boot
load_dispatchers
begin
if time = determine_latest_deploy_time
Aesop::Logger.info("Last deployment was at #{Time.at(time)}")
store_timestamp( time )
end
rescue => e
raise Aesop::BootloaderException.new(e)
end
end
|
#deployment_file ⇒ Object
62
63
64
|
# File 'lib/aesop/bootloader.rb', line 62
def deployment_file
self.configuration.deployment_file
end
|
#determine_latest_deploy_time ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/aesop/bootloader.rb', line 16
def determine_latest_deploy_time
file_time = read_deploy_time
redis_time = read_current_timestamp
if file_time
if redis_time > 0
reset_exceptions if file_time > redis_time
[redis_time, file_time].max
else
reset_exceptions
file_time
end
else
redis_time ? redis_time : Time.now.to_i
end
end
|
#load_dispatchers ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/aesop/bootloader.rb', line 43
def load_dispatchers
begin
current_dir = File.dirname(__FILE__)
Dir["#{current_dir}/dispatchers/**/*.rb"].each do |file|
require File.expand_path(file)
end
rescue => e
raise DispatcherLoadException.new(e)
end
end
|
#read_current_timestamp ⇒ Object
54
55
56
|
# File 'lib/aesop/bootloader.rb', line 54
def read_current_timestamp
redis.get( configuration.deployment_key ).to_i
end
|
#read_deploy_time ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/aesop/bootloader.rb', line 33
def read_deploy_time
if File.exists?(deployment_file)
File.open(deployment_file) do |file|
file.read.to_i
end
else
return nil
end
end
|
#redis ⇒ Object
73
74
75
|
# File 'lib/aesop/bootloader.rb', line 73
def redis
Aesop.instance.redis
end
|
#reset_exceptions ⇒ Object
66
67
68
69
70
71
|
# File 'lib/aesop/bootloader.rb', line 66
def reset_exceptions
Aesop::Logger.debug("Resetting stored exception occurrences")
redis.keys( "#{configuration.exception_prefix}:*" ).each do |key|
redis.del key
end
end
|
#store_timestamp(time) ⇒ Object
58
59
60
|
# File 'lib/aesop/bootloader.rb', line 58
def store_timestamp( time )
redis.set( configuration.deployment_key, time.to_i )
end
|