trogdir_models 0.2.1 → 0.3.0

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: 23c13d865e352b7bd365cba6686d41dc43d16c11
4
- data.tar.gz: 7fef16feb5166d694e45a74e6a5dfab9e7bc1008
3
+ metadata.gz: 81d87720d663131edba6072fab87909a42d4d377
4
+ data.tar.gz: 4dd28c82748f6bf10f83dc259b3cce4f69a36b96
5
5
  SHA512:
6
- metadata.gz: 8957e5d5b86a82ad66357049a567945fcbe608bbf4f8923b057c72f9ceb25bff6fa1e05719ea5ec61b207cf356c04072559dc79df7b7045087fb68c029b8d3ed
7
- data.tar.gz: cc95856729be3016bca9f850d766a37a39701522c50f4d269eeebe0a78f88b16e5e4bc88267354de62da7786bdad8e75d70d5253a76971f28cb57b7efc120089
6
+ metadata.gz: 28dd7d986223671e7f0a4762c0ed893075fa862a020a12ce9ba18b946c6c0f5bebea9171643f81bae5122976548e2f17ebee9de58c559480909f591908f08f1d
7
+ data.tar.gz: a8d7e94a1c1e4669b89d59587350b75a2b015d2e0c33ce4c6adf96839ea50a721c9db6e89576a5618a1d19ef215a36503d5449e2ce131da48c0c0cb2a9bf48f9
@@ -10,4 +10,6 @@ class SyncLog
10
10
  field :message, type: String
11
11
 
12
12
  validates :started_at, presence: true
13
- end
13
+
14
+ delegate :changeset, to: :change_sync
15
+ end
@@ -23,8 +23,39 @@ class Syncinator
23
23
  name
24
24
  end
25
25
 
26
+ def startable_changesets(retry_after = nil)
27
+ retry_after ||= 1.hour.ago
28
+
29
+ Changeset.where(
30
+ :'change_syncs.syncinator_id' => id
31
+ ).or(
32
+ {:'change_syncs.sync_logs'.with_size => nil},
33
+ {:'change_syncs.sync_logs'.elem_match => {:started_at.lt => retry_after, succeeded_at: nil}}
34
+ )
35
+ end
36
+
37
+ def start!(changeset)
38
+ return false unless change_sync = change_sync_for(changeset)
39
+
40
+ change_sync.sync_logs.create! started_at: Time.now
41
+ end
42
+
43
+ def error!(sync_log, message)
44
+ sync_log.update_attributes errored_at: Time.now, message: message
45
+ sync_log
46
+ end
47
+
48
+ def finish!(sync_log, action, message = nil)
49
+ sync_log.update_attributes succeeded_at: Time.now, action: action, message: message
50
+ sync_log
51
+ end
52
+
26
53
  private
27
54
 
55
+ def change_sync_for(changeset)
56
+ changeset.change_syncs.find_by(syncinator: self)
57
+ end
58
+
28
59
  def set_default_slug
29
60
  self.slug ||= name.parameterize
30
61
  end
@@ -36,4 +67,4 @@ class Syncinator
36
67
  def set_secret_key
37
68
  self.secret_key = ApiAuth.generate_secret_key
38
69
  end
39
- end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module TrogdirModels
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api-auth