trogdir_models 0.11.6 → 0.11.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trogdir/change_sync.rb +31 -0
- data/lib/trogdir/sync_log.rb +1 -8
- data/lib/trogdir/syncinator.rb +12 -0
- data/lib/trogdir_models/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c940130b860e29fd8134f62164b096775aedf18
|
4
|
+
data.tar.gz: 65ce7e6716aa92daa54fc1cd7801902b2db5a7be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bc80199f2d63ad57f150cdf345d459e91d73052dcb354f6cad7ef2d371a1e0a9565799be6de59f0ea8fc3693321ecb8eb4d1c62dca43163ba4fb6561e235919
|
7
|
+
data.tar.gz: a1c3eb1be8c7ab4f77b3646a9d9930895a4748b932881eaf77611273b9b10421af681146717111c0c8db17b10b4cd905df40ba55540332cfb2e257b808af201a
|
data/lib/trogdir/change_sync.rb
CHANGED
@@ -5,4 +5,35 @@ class ChangeSync
|
|
5
5
|
belongs_to :syncinator
|
6
6
|
embeds_many :sync_logs
|
7
7
|
field :run_after, type: Time, default: -> { Time.now - 1 }
|
8
|
+
|
9
|
+
before_save :update_run_after
|
10
|
+
|
11
|
+
def status
|
12
|
+
@status ||= if sync_logs.any? { |sl| sl.succeeded_at? }
|
13
|
+
:succeeded
|
14
|
+
elsif sync_logs.to_a.find { |sl| sl.errored_at? }
|
15
|
+
:errored
|
16
|
+
elsif sync_logs.to_a.find { |sl| sl.started_at? }
|
17
|
+
:pending
|
18
|
+
else
|
19
|
+
:unsynced
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def latest_sync_log
|
24
|
+
sync_logs.asc(:started_at).last
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_run_after
|
28
|
+
self.run_after = if sync_logs.any? { |sl| sl.succeeded_at_changed? }
|
29
|
+
nil
|
30
|
+
elsif sync_logs.to_a.find { |sl| sl.errored_at_changed? }
|
31
|
+
# wait exponentially longer between retries the more it fails
|
32
|
+
latest_sync_log.errored_at + (sync_logs.length**4).minutes
|
33
|
+
elsif sync_logs.to_a.find { |sl| sl.started_at_changed? }
|
34
|
+
latest_sync_log.started_at + 1.hour
|
35
|
+
else
|
36
|
+
run_after
|
37
|
+
end
|
38
|
+
end
|
8
39
|
end
|
data/lib/trogdir/sync_log.rb
CHANGED
@@ -26,14 +26,7 @@ class SyncLog
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def update_change_sync
|
29
|
-
change_sync.
|
30
|
-
nil
|
31
|
-
elsif errored_at_changed?
|
32
|
-
# wait exponentially longer between retries the more it fails
|
33
|
-
errored_at + (change_sync.sync_logs.length**4).minutes
|
34
|
-
elsif started_at_changed?
|
35
|
-
started_at + 1.hour
|
36
|
-
end
|
29
|
+
change_sync.update_run_after
|
37
30
|
end
|
38
31
|
|
39
32
|
def save_change_sync
|
data/lib/trogdir/syncinator.rb
CHANGED
@@ -66,6 +66,12 @@ class Syncinator
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def error!(sync_log, message)
|
69
|
+
# Because we have to save the change_sync instead of the sync_log (see below)
|
70
|
+
# we need to make sure we grab the sync_log through the change_sync, other wise
|
71
|
+
# the save on change_sync doesn't catch the changes to sync_log.
|
72
|
+
change_sync = sync_log.change_sync
|
73
|
+
sync_log = change_sync.sync_logs.find_by(id: sync_log.id)
|
74
|
+
|
69
75
|
sync_log.errored_at = Time.now
|
70
76
|
sync_log.message = message
|
71
77
|
# There seems to be a bug in mongoid 4.0.2 that saves two records if you call just
|
@@ -78,6 +84,12 @@ class Syncinator
|
|
78
84
|
end
|
79
85
|
|
80
86
|
def finish!(sync_log, action, message = nil)
|
87
|
+
# Because we have to save the change_sync instead of the sync_log (see below)
|
88
|
+
# we need to make sure we grab the sync_log through the change_sync, other wise
|
89
|
+
# the save on change_sync doesn't catch the changes to sync_log.
|
90
|
+
change_sync = sync_log.change_sync
|
91
|
+
sync_log = change_sync.sync_logs.find_by(id: sync_log.id)
|
92
|
+
|
81
93
|
sync_log.succeeded_at = Time.now
|
82
94
|
sync_log.action = action
|
83
95
|
sync_log.message = message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trogdir_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Crownoble
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: api-auth
|