Class: Syncinator

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Userstamp::User
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



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

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

#error!(sync_log, message) ⇒ Object



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

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

#errored_changesetsObject



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

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



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

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



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

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



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

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

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

#startable_changesetsObject



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

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



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

def to_s
  name
end

#unfinished_changesetsObject



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

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