Class: HrLite::DocumentExpiryJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/hr_lite/document_expiry_job.rb

Overview

Tells people before a document lapses. A passport or a visa is somebody's right to work, and the whole problem with an expiry date is finding out about it late.

Warns at 30 days and again at 7, rather than every day for a month.

Constant Summary collapse

WINDOWS =
[ 30, 7 ].freeze

Instance Method Summary collapse

Instance Method Details

#perform(today: Date.current) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/hr_lite/document_expiry_job.rb', line 10

def perform(today: Date.current)
  WINDOWS.each do |days|
    Document.where(expires_on: today + days).includes(:user).find_each do |document|
      Notifications.publish(
        "document.expiring",
        title: "#{document.title} expires in #{days} days",
        body: "#{HrLite.display_name(document.user)}#{document.category.humanize}, " \
              "expiring #{document.expires_on.strftime('%d %b %Y')}.",
        path: "/profile",
        bell_to: [ document.user ],
        email_to: [ document.user ],
        leadership: { title: "#{HrLite.display_name(document.user)}'s #{document.title} " \
                             "expires in #{days} days" }
      )
    end
  end
end