Class: ReportRunner

Inherits:
JobRunner show all
Includes:
JSONModel
Defined in:
backend/app/lib/job_runners/reports_runner.rb

Constant Summary

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSONModel

JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository

Methods inherited from JobRunner

#add_success_hook, #cancelation_signaler, #canceled?, for, #initialize, #parse_job_params_string, register_for_job_type, registered_job_types, registered_runner_for, #success!, #symbol_keys

Constructor Details

This class inherits a constructor from JobRunner

Class Method Details

.reportsObject



11
12
13
# File 'backend/app/lib/job_runners/reports_runner.rb', line 11

def self.reports
  ReportManager.registered_reports
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'backend/app/lib/job_runners/reports_runner.rb', line 16

def run
  @job.write_output('Generating report')
  file = ASUtils.tempfile('report_job_')
  begin
    job_data = @json.job

    # we need to massage the json sometimes..
    begin
      params = ASUtils.json_parse(@json.job_params[1..-2].delete('\\'))
    rescue JSON::ParserError
      params = {}
    end
    params[:format] = job_data['format'] || 'pdf'
    params[:repo_id] = @json.repo_id

    report_model = ReportRunner.reports[job_data['report_type']][:model]

    report = DB.open do |db|
      report_model.new(params, @job, db)
    end

    file = ASUtils.tempfile('report_job_')
    ReportGenerator.new(report).generate(file)

    file.rewind
    @job.write_output('Adding report file.')

    @job.add_file(file)

    self.success!
  rescue Exception => e
    @job.write_output(e.message)
    @job.write_output(e.backtrace)
    raise e
  ensure
    file.close
    file.unlink
    @job.write_output('Done.')
  end
end