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

#changesetsObject



26
27
28
# File 'lib/trogdir/syncinator.rb', line 26

def changesets
  Changeset.where('change_syncs.syncinator_id' => id).order_by(created_at: :asc)
end

#error!(sync_log, message) ⇒ Object



67
68
69
70
# File 'lib/trogdir/syncinator.rb', line 67

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

#errored_changesetsObject



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

def errored_changesets
  Changeset.where(
    :change_syncs.elem_match => {
      syncinator_id: id, :run_after.ne => nil, :'sync_logs.errored_at'.exists => true
    }
  ).order_by(created_at: :asc)
end

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



72
73
74
75
# File 'lib/trogdir/syncinator.rb', line 72

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

#pending_changesetsObject

have started but haven’t errored or succeeded



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

def pending_changesets
  Changeset.where(
    :change_syncs.elem_match => {
      syncinator_id: id, :run_after.ne => nil, :sync_logs.elem_match => {
        :started_at.ne => nil, errored_at: nil, succeeded_at: nil
      }
    }
  ).order_by(created_at: :asc)
end

#start!(changeset) ⇒ Object



61
62
63
64
65
# File 'lib/trogdir/syncinator.rb', line 61

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

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

#startable_changesetsObject



55
56
57
58
59
# File 'lib/trogdir/syncinator.rb', line 55

def startable_changesets
  Changeset.where(
    :change_syncs.elem_match => {syncinator_id: id, :run_after.lt => Time.now }
  ).order_by(created_at: :asc)
end

#to_sObject



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

def to_s
  name
end

#unfinished_changesetsObject



30
31
32
33
34
# File 'lib/trogdir/syncinator.rb', line 30

def unfinished_changesets
  Changeset.where(
    :change_syncs.elem_match => {syncinator_id: id, :run_after.ne => nil}
  ).order_by(created_at: :asc)
end