ixtlan-core 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ixtlan/core/configuration_manager.rb +10 -3
- data/lib/ixtlan/core/heartbeat.rb +60 -0
- metadata +4 -3
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'slf4r'
|
2
1
|
module Ixtlan
|
3
2
|
module Core
|
4
3
|
module Configuration
|
@@ -20,8 +19,16 @@ module Ixtlan
|
|
20
19
|
end
|
21
20
|
|
22
21
|
class Manager
|
23
|
-
|
24
|
-
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'slf4r'
|
25
|
+
include Slf4r::Logger
|
26
|
+
rescue LoadError
|
27
|
+
require 'logger'
|
28
|
+
def logger
|
29
|
+
@logger ||= Logger.new(STDERR)
|
30
|
+
end
|
31
|
+
end
|
25
32
|
|
26
33
|
private
|
27
34
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Ixtlan::Core::Heartbeat
|
2
|
+
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_reader :local, :remote
|
6
|
+
attr_accessor :count, :failure
|
7
|
+
|
8
|
+
def initialize(local, remote)
|
9
|
+
@count = 0
|
10
|
+
@failures = 0
|
11
|
+
@local = local
|
12
|
+
@remote = remote
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_log
|
16
|
+
"update #{@local} - total: #{@count + @failures} success: #{@count} failures: #{@failures}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@count = 0
|
22
|
+
@failures = 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def reg
|
26
|
+
@reg ||= {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def register(local, remote)
|
30
|
+
reg[local] = Resource.new(local, remote)
|
31
|
+
end
|
32
|
+
|
33
|
+
def beat(resource = nil)
|
34
|
+
resources = resource.nil? ? reg.values : [reg[resource]]
|
35
|
+
resources.each do |res|
|
36
|
+
last_date = res.local.maximum(:updated_at) || 2000.years.ago
|
37
|
+
last_update = last_date.strftime('%Y-%m-%d %H:%M:%S.') + ("%06d" % last_date.usec)
|
38
|
+
res.remote.get(:last_changes, :updated_at => last_update).each do |remote|
|
39
|
+
id = remote.delete('id')
|
40
|
+
u = res.local.find_by_id(id)
|
41
|
+
result = if u
|
42
|
+
u.update_attributes(remote)
|
43
|
+
else
|
44
|
+
u = res.local.new(remote)
|
45
|
+
u.id = id
|
46
|
+
u.save
|
47
|
+
end
|
48
|
+
if result
|
49
|
+
res.count = res.count + 1
|
50
|
+
else
|
51
|
+
res.failures = res.failures + 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
def to_log
|
57
|
+
reg.values.collect { |r| r.to_log }.join("\n\t")
|
58
|
+
end
|
59
|
+
alias :to_s :to_log
|
60
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ixtlan-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- mkristian
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-01-30 00:00:00 +05:30
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 0.4.2
|
25
|
-
type: :
|
25
|
+
type: :development
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ixtlan-generators
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/ixtlan/core/cache_headers.rb
|
106
106
|
- lib/ixtlan/core/optimistic_data_mapper.rb~
|
107
107
|
- lib/ixtlan/core/data_mapper.rb
|
108
|
+
- lib/ixtlan/core/heartbeat.rb
|
108
109
|
- lib/ixtlan/core/x_xss_protection_headers.rb
|
109
110
|
- lib/ixtlan/core/optimistic_active_record.rb~
|
110
111
|
- lib/ixtlan/core/railtie.rb
|