Phase 3.2 — Use Cases
This page lists every flow that changes when a Careers job buys a Careers::JobPosting with placement credits.
- The rule is Billing D17 — A Careers job post buys a job posting, paid by a direct consume.
- The rules table and the code that changes are on the Design Plan.
| Word | Meaning |
|---|---|
The model Careers::JobPostingPrice | One price for a Careers::JobPosting: name, duration_days, unit_cost, is_active |
The model Careers::JobPosting | One paid period of one Careers::Job, with starts_at and ends_at |
Existing Careers::Job | A Careers::Job created before Billing Phase 3.2 ships, which has no Careers::JobPosting |
| Renew | A new Careers::JobPosting that a Careers::Job buys after it is posted |
| Own account | The Billing::Account whose billing_accounts.org_company_id is the company of the Careers::Job |
The class Billing::SpendValidator | The public Billing class that checks a spend before the transaction |
The class Billing::SpendService | The public Billing class that writes a spend, which Careers calls with consume_now |
| HQ manager | A person with an Org::Membership on the company who posts Careers jobs in the Employer Dashboard |
Summary
| ID | Use case | Actor | Segment |
|---|---|---|---|
| UC-1 | Sales manages the job posting prices | Sales (Identities::Admin) | Team Portal |
| UC-2 | An HQ manager posts a job | HQ manager | Employer Dashboard |
| UC-3 | A parent HQ manager posts a job for a child company | HQ manager of the parent company | Employer Dashboard |
| UC-4 | An HQ manager edits a job during its period | HQ manager | Employer Dashboard |
| UC-5 | An HQ manager renews a job | HQ manager | Employer Dashboard |
| UC-6 | The system closes a job whose period has ended | System (Careers::Jobs::CloseJob, every hour) | Background job |
| UC-7 | Finance reads a job posting on the ledger | Finance (Identities::Admin) | Team Portal |
| UC-8 | Finance opens a Careers job from the ledger | Finance or Sales (Identities::Admin) | Team Portal |
UC-1: Sales manages the job posting prices
| Field | Details |
|---|---|
| Actor | Sales (Identities::Admin) |
| Trigger | Sales sets up the first prices, or Alvin and marketing decide new prices |
| Endpoints | GET, POST /team/careers/job_posting_prices, and GET, PATCH /team/careers/job_posting_prices/:id, /activate, /deactivate |
System behaviour:
- Sales opens the list of
Careers::JobPostingPricerows in the Team Portal. - Sales creates a price with
name,duration_daysandunit_cost.- The database sets
instrument: 'placement', its default, and Sales does not edit it. - The price starts with
is_active: true.
- The database sets
- Sales can edit a price, or deactivate it.
- The job form and the renew dialog show every active price.
Business rules:
duration_daysandunit_costare whole numbers greater than 0.nameis unique among the Careers prices.- Editing a price never changes a
Careers::JobPostingthat 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
| Field | Details |
|---|---|
| Actor | HQ manager |
| Endpoint | POST /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?returnstrue. - At least one
Careers::JobPostingPriceis active.
System behaviour:
- The form reads the active prices and the company's placement balance.
- The form makes one
idempotency_keywhen it opens.
- The form makes one
- 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".
- The HQ manager fills in the job and confirms the cost.
- The form sends the post with its
idempotency_key.
- The form sends the post with its
- The system looks for the
idempotency_keyamong theCareers::JobPostingrows of the same company, bycareers_job_postings.org_company_id.- When it finds one, the system answers with the
Careers::Jobof thatCareers::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.
- When it finds one, the system answers with the
- The validator checks the trial gate, as today.
- The validator checks that
careers_job_posting_price_uuidpoints at an activeCareers::JobPostingPrice. - The validator runs
Billing::SpendValidatorwith the price'sinstrumentandunit_cost. - The validator merges the errors of
Billing::SpendValidator, so one 422 holds the form errors and the credit error. - In one transaction, the system does the following:
- it saves the
Careers::Jobwithstatus: :open; - it calls
Careers::JobPostings::Shared::CreateServicewithdescription_key: :postand theidempotency_key; - the service creates the
Careers::JobPostingfrom now; - the service calls
Billing::SpendService.consume_nowwith the text "Job post:<title>,<price name>"; - it syncs the
Careers::Jobto Listings withCareers::Jobs::SyncService; - it starts the trial with
Org::Companies::TrialService.start_trial, as today.
- it saves the
- The response carries
posting_ends_at, the latestCareers::JobPosting.ends_atof theCareers::Job.
Postconditions:
- The
Careers::Jobhas oneCareers::JobPosting. - The
ends_atof thatCareers::JobPostingis the latestCareers::JobPosting.ends_atof theCareers::Job. - The own account has one new
consumeledger entry withavailable_deltaequal 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::Jobat most, by the unique index oncareers_job_postings (org_company_id, idempotency_key).- A second request with the same key gets the first
Careers::Jobback, with no error. - The same key from another company creates that company's own
Careers::Job, because the key is unique per company.
- A second request with the same key gets the first
- A post with no
idempotency_keyfails, because the form always sends one.
Error messages:
| Case | Message |
|---|---|
The post has no idempotency_key | A 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 account | A 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
| Field | Details |
|---|---|
| Actor | HQ manager of the parent company |
| Trigger | FairPrice HQ posts a job for FairPrice Supermarkets (North) |
System behaviour:
- The flow is the same as UC-2.
- The
Careers::Jobbelongs to the child company. Billing::SpendValidatorandconsume_nowfind the child's own account fromorg_company:.- 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::Jobbelongs to the child. - A renew of the child's
Careers::Jobalso spends the child's own account.
UC-4: An HQ manager edits a job during its period
| Field | Details |
|---|---|
| Actor | HQ manager |
| Endpoint | PATCH /employers/careers/jobs/*slug (exists) |
System behaviour:
- The HQ manager closes, hides, opens or edits the job.
- An update of a
Careers::Jobnever pays. - When the request sets
statustoopenorhidden, the validator checks theCareers::Job:- a
Careers::Jobwith aCareers::JobPostingneeds its latestCareers::JobPosting.ends_atin the future; - an existing
Careers::Jobthat isopenorhiddenpasses, because no period rule applies to it; - an existing
Careers::Jobthat isclosedfails, becauseclosedis its end state.
- a
- The validator checks that the company does not change, for every
Careers::Job.
Business rules:
- Closing or hiding a
Careers::Jobdoes not pause its period. - Closing a
Careers::Jobgives no credits back. - A
Careers::Jobcan close and open again any number of times during its period, for free. - An existing
Careers::Jobthat isopenorhiddencan 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.
- To hire again, the HQ manager posts a new
Close and hide are not a pause:
- The clock of a
Careers::JobPostingruns fromstarts_attoends_at, whatever the status of theCareers::Jobis. - Closing or hiding the
Careers::Jobdoes not moveends_at, and opening it again does not add days. statusand the latestCareers::JobPosting.ends_atare two different things.statusdecides whether theCareers::Jobshows in the job search, and only anopenCareers::Jobshows.- The latest
Careers::JobPosting.ends_atdecides whether the HQ manager may setopenorhidden.
Example: Acme posts the Barista job on 14 Oct with "1 Month", so its latest Careers::JobPosting.ends_at is 13 Nov.
| Date | Action | Status after | Shown in the job search | Latest Careers::JobPosting.ends_at |
|---|---|---|---|---|
| 14 Oct | Post | open | Yes | 13 Nov |
| 20 Oct | Hide | hidden | No | 13 Nov |
| 30 Oct | Open again, after 10 days hidden | open | Yes | 13 Nov, not 23 Nov |
| 1 Nov | Close | closed | No | 13 Nov |
| 5 Nov | Open again, after 4 days closed | open | Yes | 13 Nov |
| 13 Nov | Careers::Jobs::CloseJob runs | closed | No | 13 Nov |
| 20 Nov | Open again | Fails with the message for an ended period | No | 13 Nov |
| 20 Nov | Renew with "1 Month" | open | Yes | 20 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_postingsrow never changes, soends_atcannot move; - Billing recognises the revenue of the whole period on the day of payment;
- the latest
Careers::JobPosting.ends_atstays one query, with no history of status changes.
Error messages:
| Case | Message |
|---|---|
| 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
| Field | Details |
|---|---|
| Actor | HQ manager |
| Endpoint | POST /employers/careers/jobs/*slug/renew (new), with careers_job_posting_price_uuid and job_postings_count |
Preconditions:
- The
Careers::Jobhas at least oneCareers::JobPosting.- An existing
Careers::Jobnever renews, and its renew button is disabled with the text "Cannot renew".
- An existing
- The request carries
job_postings_count, the number ofCareers::JobPostingrows that the job detail returned.
System behaviour:
- The HQ manager clicks "Renew" on the job list or the job page.
- 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.
- The HQ manager picks a period and confirms.
- The validator checks that the
Careers::Jobhas at least oneCareers::JobPosting, before any other check.- An existing
Careers::Jobfails here, also when its company is blocked or has too few credits.
- An existing
- The validator runs the same checks as UC-2, steps 5 to 8.
- In one transaction, the system locks the
careers_jobsrow and counts theCareers::JobPostingrows of theCareers::Job.- When the count differs from
job_postings_count, the request fails with a 422, and the system writes nothing.
- When the count differs from
- Then, in the same transaction, the system does the following:
- it calls
Careers::JobPostings::Shared::CreateServicewithdescription_key: :renew; - when the latest
Careers::JobPosting.ends_atis in the future, the new period starts at thatends_at; - when the latest
Careers::JobPosting.ends_atis in the past, the new period starts now, and theCareers::Jobgetsstatus: :open; - it syncs the
Careers::Jobto Listings.
- it calls
Postconditions:
- The
Careers::Jobkeeps its slug and its applicants. - The
Careers::Jobhas one moreCareers::JobPosting. - The latest
Careers::JobPosting.ends_atof theCareers::Jobis theends_atof the newCareers::JobPosting.
Business rules:
- A renew of a running
Careers::Jobadds days at the end, so no paid day is lost. - An existing
Careers::Jobnever gets a renew, so it never gets aCareers::JobPostingor a ledger entry. - A renew of a running
Careers::Jobdoes not change itsstatus. - 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:
| Case | Message |
|---|---|
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 few | The same messages as UC-2 |
UC-6: The system closes a job whose period has ended
| Field | Details |
|---|---|
| Actor | System |
| Sidekiq job | Careers::Jobs::CloseJob, every hour in sidekiq-scheduler |
System behaviour:
Careers::Jobs::CloseJobfinds everyCareers::Jobwithstatusopenorhiddenwhose latestCareers::JobPostinghasends_atin the past.- An existing
Careers::Jobhas noCareers::JobPosting, so the query never selects it.
- An existing
- For each
Careers::Job, it locks thecareers_jobsrow and reads the latestCareers::JobPosting.ends_atagain.- It skips the
Careers::Jobwhen a renew moved the latestCareers::JobPosting.ends_atinto the future after the query.
- It skips the
- For each
Careers::Jobthat it does not skip, it setsstatus: :closed. - For each closed
Careers::Job, it syncs theCareers::Jobto Listings withCareers::Jobs::SyncService.- An
openCareers::Jobleaves the job search. - A
hiddenCareers::Jobis already out of the job search, because only anopenCareers::Jobshows.
- An
Business rules:
Careers::Jobs::CloseJobwrites noCareers::JobPostingand no ledger entry.- A
Careers::Jobcan stay posted up to 1 hour after its latestCareers::JobPosting.ends_at. - Applicants keep their applications, and the HQ manager still sees them.
UC-7: Finance reads a job posting on the ledger
| Field | Details |
|---|---|
| Actor | Finance (Identities::Admin) |
| Segment | Team Portal, the billing account's ledger list |
System behaviour:
- Finance opens the company's billing account.
- The ledger list shows one
consumeentry perCareers::JobPosting, withsource_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.
- 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
| Field | Details |
|---|---|
| Actor | Finance or Sales (Identities::Admin) |
| Segment | Team Portal |
| Routes | /team/careers/job-postings/<id> (deliverable route) and /team/careers/jobs/<slug> (the Careers job page) |
| Endpoints | GET /team/careers/job_postings/:id and GET /team/careers/jobs/*slug (new) |
System behaviour:
- Finance clicks the text "Job post: Barista, 1 Month" in the ledger list.
- A new tab opens
/team/careers/job-postings/88, where 88 is thesource_idof the entry. - The deliverable route reads
Careers::JobPosting88, and gets the slug of itsCareers::Job. - The route redirects to
/team/careers/jobs/acme/hq/barista-weekends-1a2b3c4d. - The Careers job page shows the
Careers::Job: title, company,statusand the latestCareers::JobPosting.ends_at. - The page shows one row per
Careers::JobPostingof theCareers::Job:starts_atandends_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::JobPostingor aCareers::Jobthat is not found shows the Team error page.
| Case | What the admin sees |
|---|---|
The Careers::JobPosting id does not exist | The Team error page, with a 404 |
The slug of the Careers::Job does not exist | The 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.
| Job | status on 1 Dec |
|---|---|
| Cashier | open |
| Waiter | hidden |
| Cook | closed |
- On 1 Dec, shipping Billing Phase 3.2 creates nothing for these
Careers::Jobrows.- Each one is an existing
Careers::Job, with noCareers::JobPostingand no end date. - The rake task of the free credits gives Acme 50 free credits, so Acme's own account has
units_available = 50.
- Each one is an existing
- Within the hour, the hourly Sidekiq job
Careers::Jobs::CloseJobruns (UC-6).- None of the three has a
Careers::JobPosting, soCareers::Jobs::CloseJobleaves them as they are.
- None of the three has a
- On 10 Dec, Acme hides Cashier and opens it again, and pays nothing.
- 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_atis 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.
- The job list shows no "Posted until" and no "Posting ended" for the three jobs, because their
- On 22 Dec, Acme closes Cashier.
- 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::Jobthat isclosed, andclosedis its end state.
- On 6 Jan, Acme posts a new Cook
Careers::Jobfor "1 Month" (UC-2).- It pays 50 credits like any post, and its first
Careers::JobPostingruns from 6 Jan to 5 Feb. - Acme's own account:
units_available = 0. - The old Cook job stays
closed.
- It pays 50 credits like any post, and its first
- Waiter is still
hiddenon 5 Feb, with no end date, andCareers::Jobs::CloseJobnever 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, withstatus: :closed. - FairPrice Supermarkets (North) is a child company with 100 credits on its own account.
- 1 credit = SGD 1.
- On 1 Oct, the rake task creates one
Billing::CreditActionthat gives Acme 50 free credits.- The credits pay one
Careers::JobPostingof "1 Month". - Acme's own account:
units_available = 50.
- The credits pay one
- 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, withunit_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.
- The system creates
- 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::Jobthat isclosed, so it cannot open again.
- 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.
- 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.
- Acme's own account:
- 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.
- The renew dialog sends
- On 1 Dec, Acme posts a new Cashier
Careers::Jobfor "1 Month" (UC-2).Careers::JobPosting#3 runs from 1 Dec to 31 Dec, and it is the firstCareers::JobPostingof the new Cashier job.- The old Cashier job stays
closed. - The consume recognises SGD 60, and Acme has 40 credits left.
- On 31 Dec, the hourly Sidekiq job
Careers::Jobs::CloseJobcloses the new Cashier job (UC-6).- Finance sees three
consumeentries on Acme's ledger (UC-7).
- Finance sees three
- 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.