Class: Syncinator

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/trogdir/syncinator.rb

Constant Summary collapse

FIXNUM_MAX =
(2**(0.size * 8 -2) -1)

Instance Method Summary collapse

Instance Method Details

#error!(sync_log, message) ⇒ Object



43
44
45
46
# File 'lib/trogdir/syncinator.rb', line 43

def error!(sync_log, message)
  sync_log.update_attributes errored_at: Time.now, message: message
  sync_log
end

#finish!(sync_log, action, message = nil) ⇒ Object



48
49
50
51
# File 'lib/trogdir/syncinator.rb', line 48

def finish!(sync_log, action, message = nil)
  sync_log.update_attributes succeeded_at: Time.now, action: action, message: message
  sync_log
end

#start!(changeset) ⇒ Object



37
38
39
40
41
# File 'lib/trogdir/syncinator.rb', line 37

def start!(changeset)
  return false unless change_sync = change_sync_for(changeset)

  change_sync.sync_logs.create! started_at: Time.now
end

#startable_changesets(retry_after = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/trogdir/syncinator.rb', line 26

def startable_changesets(retry_after = nil)
  retry_after ||= 1.hour.ago

  Changeset.where(
    :'change_syncs.syncinator_id' => id
  ).or(
    {:'change_syncs.sync_logs'.with_size => nil},
    {:'change_syncs.sync_logs'.elem_match => {:started_at.lt => retry_after, succeeded_at: nil}}
  )
end

#to_sObject



22
23
24
# File 'lib/trogdir/syncinator.rb', line 22

def to_s
  name
end