Class: Renalware::Letters::CalculatePageCountJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/renalware/letters/calculate_page_count_job.rb

Overview

This class is both a Wisper listener (subscribing to ApproveLetter events) and an ActiveJob. Should be configured in the broadcast_subscription_map to listen to events from ApproveLetter and be invoked aysnchronously via a background queue ie delayed_job.

We generate a PDF version of the letter (or retrieve it from the cache) and inspect it using a PDF tool to get the page count. We then save that away to the letters table.

The page count is useful when printing letters; letters with the same page count can be printed together and fed into an envelope stuffer with the same page count setting eg 2 (address cover sheet + duplex printed letter). Most of the time page count will be 1, but the page count setting on the printer will be 2 because of the additional address cover sheet.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.letter_approved(letter) ⇒ Object

This method is the name of an event raised elsewhere by a Wisper publisher. It needs to be a class method in order to be invoked asynchronously by delayed_job



26
27
28
# File 'app/jobs/renalware/letters/calculate_page_count_job.rb', line 26

def self.letter_approved(letter)
  new(letter).call
end

Instance Method Details

#callObject



30
31
32
# File 'app/jobs/renalware/letters/calculate_page_count_job.rb', line 30

def call
  letter.update_column(:page_count, pdf_reader.page_count)
end