Skip to main content

Phase 3.2 — Use Cases

This page lists every flow that changes when a Careers job buys a Careers::JobPosting with placement credits.

WordMeaning
The model Careers::JobPostingPriceOne price for a Careers::JobPosting: name, duration_days, unit_cost, is_active
The model Careers::JobPostingOne paid period of one Careers::Job, with starts_at and ends_at
Existing Careers::JobA Careers::Job created before Billing Phase 3.2 ships, which has no Careers::JobPosting
RenewA new Careers::JobPosting that a Careers::Job buys after it is posted
Own accountThe Billing::Account whose billing_accounts.org_company_id is the company of the Careers::Job
The class Billing::SpendValidatorThe public Billing class that checks a spend before the transaction
The class Billing::SpendServiceThe public Billing class that writes a spend, which Careers calls with consume_now
HQ managerA person with an Org::Membership on the company who posts Careers jobs in the Employer Dashboard

Summary​

IDUse caseActorSegment
UC-1Sales manages the job posting pricesSales (Identities::Admin)Team Portal
UC-2An HQ manager posts a jobHQ managerEmployer Dashboard
UC-3A parent HQ manager posts a job for a child companyHQ manager of the parent companyEmployer Dashboard
UC-4An HQ manager edits a job during its periodHQ managerEmployer Dashboard
UC-5An HQ manager renews a jobHQ managerEmployer Dashboard
UC-6The system closes a job whose period has endedSystem (Careers::Jobs::CloseJob, every hour)Background job
UC-7Finance reads a job posting on the ledgerFinance (Identities::Admin)Team Portal
UC-8Finance opens a Careers job from the ledgerFinance or Sales (Identities::Admin)Team Portal

UC-1: Sales manages the job posting prices​

FieldDetails
ActorSales (Identities::Admin)
TriggerSales sets up the first prices, or Alvin and marketing decide new prices
EndpointsGET, POST /team/careers/job_posting_prices, and GET, PATCH /team/careers/job_posting_prices/:id, /activate, /deactivate

System behaviour:

  1. Sales opens the list of Careers::JobPostingPrice rows in the Team Portal.
  2. Sales creates a price with name, duration_days and unit_cost.
    • The database sets instrument: 'placement', its default, and Sales does not edit it.
    • The price starts with is_active: true.
  3. Sales can edit a price, or deactivate it.
  4. The job form and the renew dialog show every active price.

Business rules:

  • duration_days and unit_cost are whole numbers greater than 0.
  • name is unique among the Careers prices.
  • Editing a price never changes a Careers::JobPosting that the system already created.
  • When no price is active, no company can post or renew a job.

UC-2: An HQ manager posts a job​

FieldDetails
ActorHQ manager
EndpointPOST /employers/careers/jobs (exists), with the new fields careers_job_posting_price_uuid and idempotency_key

Preconditions:

  • The trial gate lets the company post: Org::Company#careers_feature_enabled? returns true.
  • At least one Careers::JobPostingPrice is active.

System behaviour:

  1. The form reads the active prices and the company's placement balance.
    • The form makes one idempotency_key when it opens.
  2. The HQ manager picks a period.
    • The form shows the cost, the balance and "Posted until" with the end date.
    • When the balance is lower than the cost, the form shows the "Insufficient Placement Credits" alert and disables the submit.
    • The alert has a WhatsappButton "Chat with us to top up credits".
  3. The HQ manager fills in the job and confirms the cost.
    • The form sends the post with its idempotency_key.
  4. The system looks for the idempotency_key among the Careers::JobPosting rows of the same company, by careers_job_postings.org_company_id.
    • When it finds one, the system answers with the Careers::Job of that Careers::JobPosting.
    • It writes nothing, and the HQ manager pays nothing.
    • It runs this check before the validator, so a repeat with too few credits still gets the first Careers::Job.
  5. The validator checks the trial gate, as today.
  6. The validator checks that careers_job_posting_price_uuid points at an active Careers::JobPostingPrice.
  7. The validator runs Billing::SpendValidator with the price's instrument and unit_cost.
  8. The validator merges the errors of Billing::SpendValidator, so one 422 holds the form errors and the credit error.
  9. In one transaction, the system does the following:
    • it saves the Careers::Job with status: :open;
    • it calls Careers::JobPostings::Shared::CreateService with description_key: :post and the idempotency_key;
    • the service creates the Careers::JobPosting from now;
    • the service calls Billing::SpendService.consume_now with the text "Job post: <title>, <price name>";
    • it syncs the Careers::Job to Listings with Careers::Jobs::SyncService;
    • it starts the trial with Org::Companies::TrialService.start_trial, as today.
  10. The response carries posting_ends_at, the latest Careers::JobPosting.ends_at of the Careers::Job.

Postconditions:

  • The Careers::Job has one Careers::JobPosting.
  • The ends_at of that Careers::JobPosting is the latest Careers::JobPosting.ends_at of the Careers::Job.
  • The own account has one new consume ledger entry with available_delta equal to minus the credit cost.
  • The ledger entry has source_type: 'Careers::JobPosting' and the text "Job post: <title>, <price name>".

Business rules:

  • One submit of the job form creates one Careers::Job at most, by the unique index on careers_job_postings (org_company_id, idempotency_key).
    • A second request with the same key gets the first Careers::Job back, with no error.
    • The same key from another company creates that company's own Careers::Job, because the key is unique per company.
  • A post with no idempotency_key fails, because the form always sends one.

Error messages:

CaseMessage
The post has no idempotency_keyA 422 on idempotency_key, because the form always sends one
The company is blocked"Company trial period has ended, please contact sales for assistance" (exists)
No price is active, or the picked price is not active"Posting a job is not available right now. Please contact Jod support."
Not enough credits"You need <cost> placement credits, but you only have <available> available. Please contact us to top up your placement credits." (Billing writes it, under the key placement_credits)
The company has no own accountA 500 with code: 'billing_account_missing', because every company is created with its own account, so this is a data bug

UC-3: A parent HQ manager posts a job for a child company​

FieldDetails
ActorHQ manager of the parent company
TriggerFairPrice HQ posts a job for FairPrice Supermarkets (North)

System behaviour:

  1. The flow is the same as UC-2.
  2. The Careers::Job belongs to the child company.
  3. Billing::SpendValidator and consume_now find the child's own account from org_company:.
  4. The balance check and the direct consume use the child's own account.

Business rules:

  • The parent's account is never read.
  • The form shows the child company's balance, because the Careers::Job belongs to the child.
  • A renew of the child's Careers::Job also spends the child's own account.

UC-4: An HQ manager edits a job during its period​

FieldDetails
ActorHQ manager
EndpointPATCH /employers/careers/jobs/*slug (exists)

System behaviour:

  1. The HQ manager closes, hides, opens or edits the job.
  2. An update of a Careers::Job never pays.
  3. When the request sets status to open or hidden, the validator checks the Careers::Job:
    • a Careers::Job with a Careers::JobPosting needs its latest Careers::JobPosting.ends_at in the future;
    • an existing Careers::Job that is open or hidden passes, because no period rule applies to it;
    • an existing Careers::Job that is closed fails, because closed is its end state.
  4. The validator checks that the company does not change, for every Careers::Job.

Business rules:

  • Closing or hiding a Careers::Job does not pause its period.
  • Closing a Careers::Job gives no credits back.
  • A Careers::Job can close and open again any number of times during its period, for free.
  • An existing Careers::Job that is open or hidden can be hidden and opened again any number of times, for free.
    • It has no end date, so it stays posted until its HQ manager closes it.
  • After its HQ manager closes an existing Careers::Job, it cannot open, hide or renew again.
    • To hire again, the HQ manager posts a new Careers::Job.

Close and hide are not a pause:

  • The clock of a Careers::JobPosting runs from starts_at to ends_at, whatever the status of the Careers::Job is.
  • Closing or hiding the Careers::Job does not move ends_at, and opening it again does not add days.
  • status and the latest Careers::JobPosting.ends_at are two different things.
    • status decides whether the Careers::Job shows in the job search, and only an open Careers::Job shows.
    • The latest Careers::JobPosting.ends_at decides whether the HQ manager may set open or hidden.

Example: Acme posts the Barista job on 14 Oct with "1 Month", so its latest Careers::JobPosting.ends_at is 13 Nov.

DateActionStatus afterShown in the job searchLatest Careers::JobPosting.ends_at
14 OctPostopenYes13 Nov
20 OctHidehiddenNo13 Nov
30 OctOpen again, after 10 days hiddenopenYes13 Nov, not 23 Nov
1 NovCloseclosedNo13 Nov
5 NovOpen again, after 4 days closedopenYes13 Nov
13 NovCareers::Jobs::CloseJob runsclosedNo13 Nov
20 NovOpen againFails with the message for an ended periodNo13 Nov
20 NovRenew with "1 Month"openYes20 Dec
  • Acme hid or closed the job for 14 days, and got no days and no credits back.
  • Why there is no pause:
    • a company buys calendar days, like an ad slot, not days of being shown;
    • a careers_job_postings row never changes, so ends_at cannot move;
    • Billing recognises the revenue of the whole period on the day of payment;
    • the latest Careers::JobPosting.ends_at stays one query, with no history of status changes.

Error messages:

CaseMessage
The period has ended"This job's posting has ended. Renew it to open it again."
It is an existing Careers::Job that is closed"This job is closed. Post a new job to hire again."
The company changes on any Careers::Job"You cannot move this job to another company. Post a new job for the other company."

UC-5: An HQ manager renews a job​

FieldDetails
ActorHQ manager
EndpointPOST /employers/careers/jobs/*slug/renew (new), with careers_job_posting_price_uuid and job_postings_count

Preconditions:

  • The Careers::Job has at least one Careers::JobPosting.
    • An existing Careers::Job never renews, and its renew button is disabled with the text "Cannot renew".
  • The request carries job_postings_count, the number of Careers::JobPosting rows that the job detail returned.

System behaviour:

  1. The HQ manager clicks "Renew" on the job list or the job page.
  2. The renew dialog shows the active prices, the cost, the balance and the new end date.
    • When the balance is too low, the dialog shows the same alert and WhatsApp button as UC-2.
  3. The HQ manager picks a period and confirms.
  4. The validator checks that the Careers::Job has at least one Careers::JobPosting, before any other check.
    • An existing Careers::Job fails here, also when its company is blocked or has too few credits.
  5. The validator runs the same checks as UC-2, steps 5 to 8.
  6. In one transaction, the system locks the careers_jobs row and counts the Careers::JobPosting rows of the Careers::Job.
    • When the count differs from job_postings_count, the request fails with a 422, and the system writes nothing.
  7. Then, in the same transaction, the system does the following:
    • it calls Careers::JobPostings::Shared::CreateService with description_key: :renew;
    • when the latest Careers::JobPosting.ends_at is in the future, the new period starts at that ends_at;
    • when the latest Careers::JobPosting.ends_at is in the past, the new period starts now, and the Careers::Job gets status: :open;
    • it syncs the Careers::Job to Listings.

Postconditions:

  • The Careers::Job keeps its slug and its applicants.
  • The Careers::Job has one more Careers::JobPosting.
  • The latest Careers::JobPosting.ends_at of the Careers::Job is the ends_at of the new Careers::JobPosting.

Business rules:

  • A renew of a running Careers::Job adds days at the end, so no paid day is lost.
  • An existing Careers::Job never gets a renew, so it never gets a Careers::JobPosting or a ledger entry.
  • A renew of a running Careers::Job does not change its status.
  • One renew dialog buys one period at most.
    • Two renews sent at the same moment run one after the other, because of the row lock.
    • The second one carries an old job_postings_count, so it fails and pays nothing.
    • A renew on purpose opens the dialog again, which reads the new count.

Error messages:

CaseMessage
The Careers::Job has no Careers::JobPosting, so it is an existing Careers::Job"This job cannot be renewed. Post a new job to hire again."
job_postings_count is not the count of Careers::JobPosting rows of the Careers::Job"This job is already renewed until <posting end>."
The company is blocked, no price is active, or the credits are too fewThe same messages as UC-2

UC-6: The system closes a job whose period has ended​

FieldDetails
ActorSystem
Sidekiq jobCareers::Jobs::CloseJob, every hour in sidekiq-scheduler

System behaviour:

  1. Careers::Jobs::CloseJob finds every Careers::Job with status open or hidden whose latest Careers::JobPosting has ends_at in the past.
    • An existing Careers::Job has no Careers::JobPosting, so the query never selects it.
  2. For each Careers::Job, it locks the careers_jobs row and reads the latest Careers::JobPosting.ends_at again.
    • It skips the Careers::Job when a renew moved the latest Careers::JobPosting.ends_at into the future after the query.
  3. For each Careers::Job that it does not skip, it sets status: :closed.
  4. For each closed Careers::Job, it syncs the Careers::Job to Listings with Careers::Jobs::SyncService.
    • An open Careers::Job leaves the job search.
    • A hidden Careers::Job is already out of the job search, because only an open Careers::Job shows.

Business rules:

  • Careers::Jobs::CloseJob writes no Careers::JobPosting and no ledger entry.
  • A Careers::Job can stay posted up to 1 hour after its latest Careers::JobPosting.ends_at.
  • Applicants keep their applications, and the HQ manager still sees them.

UC-7: Finance reads a job posting on the ledger​

FieldDetails
ActorFinance (Identities::Admin)
SegmentTeam Portal, the billing account's ledger list

System behaviour:

  1. Finance opens the company's billing account.
  2. The ledger list shows one consume entry per Careers::JobPosting, with source_type: 'Careers::JobPosting'.
    • The source cell shows the text that Careers passed, such as "Job renew: Barista, 3 Months".
    • An Ads placement shows its text in the same way.
    • The text links to the Careers job page in a new tab, see UC-8.
  3. The lot list shows which lots the consume took units from.

Business rules:

  • A consume from a paid lot recognises revenue.
  • A consume from a trial lot or a goodwill lot recognises SGD 0.
  • The consume recognises the whole cost on the day the company pays, also for a 3-month period.
  • A renew recognises its whole cost on the renew day, also when its period starts later.

UC-8: Finance opens a Careers job from the ledger​

FieldDetails
ActorFinance or Sales (Identities::Admin)
SegmentTeam Portal
Routes/team/careers/job-postings/<id> (deliverable route) and /team/careers/jobs/<slug> (the Careers job page)
EndpointsGET /team/careers/job_postings/:id and GET /team/careers/jobs/*slug (new)

System behaviour:

  1. Finance clicks the text "Job post: Barista, 1 Month" in the ledger list.
  2. A new tab opens /team/careers/job-postings/88, where 88 is the source_id of the entry.
  3. The deliverable route reads Careers::JobPosting 88, and gets the slug of its Careers::Job.
  4. The route redirects to /team/careers/jobs/acme/hq/barista-weekends-1a2b3c4d.
  5. The Careers job page shows the Careers::Job: title, company, status and the latest Careers::JobPosting.ends_at.
  6. The page shows one row per Careers::JobPosting of the Careers::Job:
    • starts_at and ends_at;
    • the price name and unit_cost_snapshot;
    • created_by.

Business rules:

  • The page is read-only.
  • The "Jobs" entry of the Team sidebar stays disabled, because there is no list page.
  • A Careers::JobPosting or a Careers::Job that is not found shows the Team error page.
CaseWhat the admin sees
The Careers::JobPosting id does not existThe Team error page, with a 404
The slug of the Careers::Job does not existThe Team error page, with a 404

Worked example: Acme's existing Careers::Job rows when Billing Phase 3.2 ships​

Billing Phase 3.2 ships on 1 Dec, and Acme has three existing Careers::Job rows.

Jobstatus on 1 Dec
Cashieropen
Waiterhidden
Cookclosed
  1. On 1 Dec, shipping Billing Phase 3.2 creates nothing for these Careers::Job rows.
    • Each one is an existing Careers::Job, with no Careers::JobPosting and no end date.
    • The rake task of the free credits gives Acme 50 free credits, so Acme's own account has units_available = 50.
  2. Within the hour, the hourly Sidekiq job Careers::Jobs::CloseJob runs (UC-6).
    • None of the three has a Careers::JobPosting, so Careers::Jobs::CloseJob leaves them as they are.
  3. On 10 Dec, Acme hides Cashier and opens it again, and pays nothing.
  4. On 20 Dec, the job list shows the renew button of Cashier as disabled, with the text "Cannot renew".
    • The job list shows no "Posted until" and no "Posting ended" for the three jobs, because their posting_ends_at is null.
    • A renew request sent by hand fails with "This job cannot be renewed. Post a new job to hire again." (UC-5).
    • Acme pays nothing.
  5. On 22 Dec, Acme closes Cashier.
  6. On 5 Jan, Acme tries to open Cook (UC-4).
    • It fails with "This job is closed. Post a new job to hire again."
    • Cook is an existing Careers::Job that is closed, and closed is its end state.
  7. On 6 Jan, Acme posts a new Cook Careers::Job for "1 Month" (UC-2).
    • It pays 50 credits like any post, and its first Careers::JobPosting runs from 6 Jan to 5 Feb.
    • Acme's own account: units_available = 0.
    • The old Cook job stays closed.
  8. Waiter is still hidden on 5 Feb, with no end date, and Careers::Jobs::CloseJob never closes it.

Worked example: Acme and FairPrice North​

Billing Phase 3.2 ships on 1 Oct.

  • Sales has created two prices, "1 Month" for 50 credits and "3 Months" for 100 credits.
  • Acme Pte Ltd is a root company that is not blocked, with 0 placement credits.
  • Acme has a Cashier job that is an existing Careers::Job, with status: :closed.
  • FairPrice Supermarkets (North) is a child company with 100 credits on its own account.
  • 1 credit = SGD 1.
  1. On 1 Oct, the rake task creates one Billing::CreditAction that gives Acme 50 free credits.
    • The credits pay one Careers::JobPosting of "1 Month".
    • Acme's own account: units_available = 50.
  2. On 14 Oct, Acme posts a Barista job for "1 Month" (UC-2).
    • The system creates Careers::JobPosting #1 from 14 Oct to 13 Nov, with unit_cost_snapshot: 50.
    • The consume takes 50 free units and recognises SGD 0.
    • Acme's own account: units_available = 0.
    • The network drops, and the form sends the post again with the same idempotency_key.
    • The second request gets the Barista job back, and creates nothing.
  3. On 15 Oct, Sales changes "1 Month" to 60 credits.
    • Careers::JobPosting #1 still says 50 credits.
    • On 16 Oct, Acme tries to open the Cashier job, and it fails (UC-4).
    • Cashier is an existing Careers::Job that is closed, so it cannot open again.
  4. On 20 Oct, Acme hides the Barista job, and opens it again on 25 Oct.
    • Acme pays nothing, because the period runs until 13 Nov.
  5. On 5 Nov, Acme pays an invoice for 200 credits at SGD 1 each.
    • Acme's own account: units_available = 200, with SGD 200 deferred revenue.
  6. On 10 Nov, Acme renews the Barista job for "3 Months" (UC-5).
    • The renew dialog sends job_postings_count: 1.
    • Careers::JobPosting #2 runs from 13 Nov to 11 Feb.
    • The consume takes 100 units from the paid lot and recognises SGD 100 on 10 Nov.
    • Acme's own account: units_available = 100.
  7. On 1 Dec, Acme posts a new Cashier Careers::Job for "1 Month" (UC-2).
    • Careers::JobPosting #3 runs from 1 Dec to 31 Dec, and it is the first Careers::JobPosting of the new Cashier job.
    • The old Cashier job stays closed.
    • The consume recognises SGD 60, and Acme has 40 credits left.
  8. On 31 Dec, the hourly Sidekiq job Careers::Jobs::CloseJob closes the new Cashier job (UC-6).
    • Finance sees three consume entries on Acme's ledger (UC-7).
  9. FairPrice HQ posts a Stocker job for FairPrice North for "1 Month" (UC-3).
    • The consume takes 60 credits from North's own account, and North has 40 left.
    • FairPrice's own account does not change.