Class: PartnerService::ReportProgress

Inherits:
ApplicationService show all
Defined in:
app/services/partner_service/report_progress.rb

Overview

This class is responsible for reporting progress of various types of reports.

Instance Attribute Summary collapse

Attributes inherited from ApplicationService

#object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationService

#execute, #execute!

Constructor Details

#initialize(type, args) ⇒ ReportProgress

Initializes a new instance of ReportProgress.

Parameters:

  • type (Symbol)

    The type of report.

  • args (Hash)

    The arguments for the report.



13
14
15
16
# File 'app/services/partner_service/report_progress.rb', line 13

def initialize(type, args)
  @type = type
  @args = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



7
8
9
# File 'app/services/partner_service/report_progress.rb', line 7

def args
  @args
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'app/services/partner_service/report_progress.rb', line 7

def type
  @type
end

Class Method Details

.generate_name(type, args) ⇒ String

Generates a unique name for the report.

Parameters:

  • type (Symbol)

    The type of report.

  • args (Hash)

    The arguments for the report.

Returns:

  • (String)

    The generated name for the report.



67
68
69
# File 'app/services/partner_service/report_progress.rb', line 67

def self.generate_name(type, args)
  "Report_#{type}_#{args[:type]}_#{SecureRandom.hex(3)}"
end

Instance Method Details

#exportString

Exports the report and returns the job ID.

Returns:

  • (String)

    The job ID of the exported report.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/partner_service/report_progress.rb', line 21

def export
  attachment = Attachment.create(
    restaurant_id: args[:restaurant_id],
    exported_by: :owner_staff,
    report_type: type,
    status: :on_queue,
    name: PartnerService::ReportProgress.generate_name(type, args),
  )

  job_id = run_worker(attachment.id)
  if attachment.present? && attachment.persisted?
    attachment.job_id = job_id
    attachment.save!
  end

  job_id
end