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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 277860888e824ed5b7c0afc168ad05139041e318
4
- data.tar.gz: 9d7a3d280274887346be62bbaa0ed4eb190e00f9
3
+ metadata.gz: 2c940130b860e29fd8134f62164b096775aedf18
4
+ data.tar.gz: 65ce7e6716aa92daa54fc1cd7801902b2db5a7be
5
5
  SHA512:
6
- metadata.gz: 0033b8c45a72589c0f3fcfd9149e76cbbb8f8eb1be65c3c388c5e678b8ff24b0b73ea2adb8ab78316cd810e8f11f6b6c1d58d7c8f87f9720bcbcf2d731978e38
7
- data.tar.gz: dcee29b97cef7d763507c6a2113e407ced3a3492789afc046e4a8c8de518dd0af56f63e6c76bb1e6b0e935e996029cda1d60562630bf32dd94f487d944313486
6
+ metadata.gz: 0bc80199f2d63ad57f150cdf345d459e91d73052dcb354f6cad7ef2d371a1e0a9565799be6de59f0ea8fc3693321ecb8eb4d1c62dca43163ba4fb6561e235919
7
+ data.tar.gz: a1c3eb1be8c7ab4f77b3646a9d9930895a4748b932881eaf77611273b9b10421af681146717111c0c8db17b10b4cd905df40ba55540332cfb2e257b808af201a
@@ -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
@@ -26,14 +26,7 @@ class SyncLog
26
26
  private
27
27
 
28
28
  def update_change_sync
29
- change_sync.run_after = if succeeded_at_changed?
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TrogdirModels
2
- VERSION = '0.11.6'
2
+ VERSION = '0.11.7'
3
3
  end
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.6
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-10 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api-auth