Skip to main content

End Trial

To keep Org::Company's careers_access_status flow consistent we've added a TrialService (Org::Companies::TrialService) so we only interact with the TrialService instead of touching the careers_access_status attributes directly. TrialService.end_trial will be called by Org::Companies::EndTrialJob.perform_at(...) which was scheduled when a company made their first careers job post, then when the scheduled time come, TrialService.end_trial will:

  1. update careers_access_status to blocked
  2. set careers_trial_ended_notified_at to Time.current
  3. sent generic email to the company, cc to Sairin and Justin
  4. sent slack message to #careers-trial-ended-report channel, containing company name, number of job posted, total careers job applications for all jobs

Notification (point 3 and 4) will be sent only if careers_trial_ended_notified_at is null

Code

# typed: true

module Org
module Companies
# Service class related to Org::Company TrialEndDate
class TrialService

extend T::Sig

sig {
}
def self.start_trial(org_company:, careers_job:)
end

sig {
params(
org_company_id: Integer
).void
}
def self.end_trial(org_company_id:)
org_company = Org::Company.find_by!(id: org_company_id)
is_company_careers_access_trial = org_company.careers_access_status == Org::Company.careers_access_statuses[:trial]
is_company_trial_period_overdue = org_company.careers_trial_ends_at&.past?

return unless is_company_careers_access_trial && is_company_trial_period_overdue

org_company.assign_attributes(
careers_access_status: Org::Company.careers_access_statuses[:blocked],
)

is_company_already_notified_previously = org_company.careers_trial_ended_notified_at.present?
if is_company_already_notified_previously
# only notify if company has never notified before
# need to set careers_trial_ended_notified_at to nil if we want to give more trial period to `blocked` company
Org::Companies::CareersTrialEndedMailer.new(org_company: org_company).send()
Notifications::CompanyCareersTrialEndedReportJob.perform_async(org_company.id)

org_company.assign_attributes(
careers_trial_ended_notified_at: Time.current
)
end
org_company.save
end

end
end
end

Rule

Any action that should trigger the end of a careers trial should call TrialService.end_trial passing org_company_id which is the id of the Org::Company. per June 2026, this is implemented in:

  1. Org::Companies::EndTrialJob
     module Org
    module Companies
    class EndTrialJob

    include Sidekiq::Worker
    sidekiq_options queue: :default

    def perform(params)
    org_company_id = params['org_company_id']
    Org::Companies::TrialService.end_trial(org_company_id: org_company_id)
    end

    end
    end
    end