Class: CanvasSync::Jobs::ReportSyncTask
- Inherits:
-
Object
- Object
- CanvasSync::Jobs::ReportSyncTask
show all
- Defined in:
- lib/canvas_sync/jobs/report_sync_task.rb
Direct Known Subclasses
LegacyReportShimTask, SyncAccountsJob::ReportTask, SyncAssignmentGroupsJob, SyncAssignmentOverridesJob, SyncAssignmentsJob, SyncContentMigrationsJob, SyncContextModuleItemsJob, SyncContextModulesJob, SyncCourseProgressesJob, SyncProvisioningReportJob, SyncRubricAssessmentsJob, SyncRubricAssociationsJob, SyncRubricsJob, SyncScoresJob, SyncSubmissionsJob
Defined Under Namespace
Classes: CheckerJob, FatalReportError, ProcessJob, ReportTaskJob, StarterJob
Constant Summary
collapse
- REPORT_TIMEOUT =
24.hours
- COMPILATION_TIMEOUT =
3.hours
- MAX_TRIES =
3
- AUTO_MODEL_REGEX =
/Sync(\w+)Job/
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Batch context before initializing the report batch; read-only.
-
#options ⇒ Object
readonly
Hash passed specifically to this report; read-only.
-
#state ⇒ Object
readonly
Escape hatch to store additional state on the report batch.
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options, context, state) ⇒ ReportSyncTask
Returns a new instance of ReportSyncTask.
19
20
21
22
23
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 19
def initialize(options, context, state)
@options = options
@context = context
@state = state
end
|
Instance Attribute Details
#context ⇒ Object
Batch context before initializing the report batch; read-only
15
16
17
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 15
def context
@context
end
|
#options ⇒ Object
Hash passed specifically to this report; read-only
13
14
15
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 13
def options
@options
end
|
#state ⇒ Object
Escape hatch to store additional state on the report batch
17
18
19
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 17
def state
@state
end
|
Class Method Details
.from_context ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 28
def from_context
report_batch = JobBatches::Batch.current
base_context = report_batch.parent.context
state = report_batch.context
cls = state[:report_class].constantize
cls.new(state[:report_options], base_context, state)
end
|
.merge_report_params(options, params = {}, term_scope: true) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 48
def merge_report_params(options, params={}, term_scope: true)
batch_context = JobBatches::Batch.current_context
term_scope = options[:canvas_term_id] || batch_context[:canvas_term_id] if term_scope == true
if term_scope.present?
params[:enrollment_term_id] = term_scope
end
if (updated_after = batch_context[:updated_after]).present?
params[:updated_after] = updated_after
end
params.merge!(options[:report_params]) if options[:report_params].present?
params.merge!(options[:report_parameters]) if options[:report_parameters].present?
{ parameters: params }
end
|
.model(m = nil) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 71
def model(m = nil)
if m.present?
const_set("MODEL", m)
else
mdl = const_get("MODEL") rescue nil
mdl ||= begin
mbits = self.to_s.scan(AUTO_MODEL_REGEX)
if (m = mbits.last) && m[0].present?
model_name = m[0].singularize
model_name
end
end
mdl
end
end
|
36
37
38
39
40
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 36
def perform_later(options)
_with_batch(options) do |batch|
StarterJob.perform_later
end
end
|
42
43
44
45
46
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 42
def perform_now(options)
_with_batch(options) do |batch|
StarterJob.perform_now
end
end
|
.report_name(n = nil) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 62
def report_name(n = nil)
if n.present?
const_set("REPORT_NAME", n)
define_method(:report_name) { n }
else
const_get("REPORT_NAME") rescue nil
end
end
|
Instance Method Details
#caching_key ⇒ Object
129
130
131
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 129
def caching_key
Digest::MD5.hexdigest(report_parameters.to_s)[0..8]
end
|
#check_frequency ⇒ Object
121
122
123
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 121
def check_frequency
Rails.env.development? ? 5.seconds : 1.minute
end
|
#max_tries ⇒ Object
125
126
127
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 125
def max_tries
3
end
|
#process(file) ⇒ Object
117
118
119
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 117
def process(file)
do_bulk_import(file, model_class)
end
|
#report_name ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 103
def report_name
if defined?(self.class::REPORT_NAME)
self.class::REPORT_NAME
else
raise NotImplementedError
end
end
|
#report_parameters ⇒ Object
111
112
113
|
# File 'lib/canvas_sync/jobs/report_sync_task.rb', line 111
def report_parameters
merge_report_params(options)
end
|