Class: CanvasSync::Jobs::BeginSyncChainJob
Instance Attribute Summary collapse
#job_log
Class Method Summary
collapse
Instance Method Summary
collapse
#create_job_log, #report_checker_wait_time, #update_or_create_model
Instance Attribute Details
#globals ⇒ Object
Returns the value of attribute globals.
4
5
6
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 4
def globals
@globals
end
|
Class Method Details
.batch_completed(status, options) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 76
def self.batch_completed(status, options)
sbatch = SyncBatch.find(options['sync_batch_id'])
sbatch.update!(
status: status.success? ? 'completed' : 'failed',
completed_at: DateTime.now,
)
end
|
Instance Method Details
#genre ⇒ Object
72
73
74
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 72
def genre
globals[:batch_genre] || "default"
end
|
#last_full_sync ⇒ Object
68
69
70
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 68
def last_full_sync
last_full_sync_record&.started_at
end
|
#last_full_sync_record ⇒ Object
64
65
66
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 64
def last_full_sync_record
@last_full_sync_record ||= SyncBatch.where(status: 'completed', full_sync: true, batch_genre: genre).last
end
|
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 6
def perform(chain_definition, globals = {})
@globals = globals
if globals[:updated_after] == false
globals[:updated_after] = nil
elsif !globals[:updated_after].present? || globals[:updated_after] == true
last_batch = SyncBatch.where(status: 'completed', batch_genre: genre).last
globals[:full_sync_every] ||= "sunday/2"
globals[:updated_after] = last_batch&.started_at&.iso8601
end
if should_full_sync?(globals[:full_sync_every])
globals[:updated_after] = nil
end
sync_batch = SyncBatch.create!(
started_at: DateTime.now,
full_sync: globals[:updated_after] == nil,
batch_genre: genre,
status: 'processing',
)
JobBatches::Batch.new.tap do |b|
b.description = "CanvasSync Root Batch (SyncBatch##{sync_batch.id})"
b.on(:complete, "#{self.class.to_s}.batch_completed", sync_batch_id: sync_batch.id)
b.on(:success, "#{self.class.to_s}.batch_completed", sync_batch_id: sync_batch.id)
b.context = globals
b.jobs do
JobBatches::SerialBatchJob.perform_now(chain_definition)
end
sync_batch.update(batch_bid: b.bid)
end
end
|
#should_full_sync?(opt) ⇒ Boolean
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/canvas_sync/jobs/begin_sync_chain_job.rb', line 40
def should_full_sync?(opt)
return true unless last_full_sync.present?
return false unless opt.is_a?(String)
case opt.strip
when %r{^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)(?:/(\d+))?$}
m = Regexp.last_match
day = m[1]
skip = m[2] || "1"
Date.new.send(:"#{day}?") && last_full_sync.end_of_day <= (skip.to_i.weeks.ago.end_of_day)
when opt.match?(%r{^(\d+)\%$})
m = Regexp.last_match
rand(100) < m[1].to_i
when opt.match?(%r{^(\d+) ?days$})
m = Regexp.last_match
last_full_sync.end_of_day <= m[1].to_i.days.ago.end_of_day
when opt.match?(%r{^(\d+)$}) m = Regexp.last_match
last_full_sync.end_of_day <= m[1].to_i.seconds.ago.end_of_day
else
false
end
end
|