Class: Resque::Reports::BaseReport

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Encodings
Defined in:
lib/resque/reports/base_report.rb

Direct Known Subclasses

CsvReport

Constant Summary collapse

DEFAULT_EXTENSION =

Constants

'txt'

Instance Method Summary collapse

Methods included from Encodings

included

Constructor Details

#initialize(*args) ⇒ BaseReport

Public instance methods



60
61
62
63
64
65
66
67
68
69
# File 'lib/resque/reports/base_report.rb', line 60

def initialize(*args)
  create_block.call(*args) if create_block

  @args = args
  extension ||= DEFAULT_EXTENSION

  @cache_file = CacheFile.new(directory, generate_filename, coding: encoding)

  init_table
end

Instance Method Details

#bg_buildObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/resque/reports/base_report.rb', line 75

def bg_build
  report_class = self.class.to_s
  args_json = @args.to_json

  # Check report if it already in progress and tring return its job_id...
  job_id = ReportJob.enqueued?(report_class, args_json).try(:meta_id)
  
  # ...and start new job otherwise
  ReportJob.enqueue(report_class, args_json) unless job_id
end

#buildObject



71
72
73
# File 'lib/resque/reports/base_report.rb', line 71

def build
  @cache_file.open { |file| write file }
end