Careers::JobPosting
Purpose
Careers::JobPosting is one period in which a Careers::Job is posted on Careers, from starts_at to ends_at.
- A post creates the first
Careers::JobPostingof aCareers::Job, and each renew creates one more. - Every
Careers::JobPostingpays with placement credits, through oneconsumeledger entry in Billing. - A
Careers::Jobwith aCareers::JobPostingstays open or hidden only while its latestCareers::JobPosting.ends_atis in the future. - An existing
Careers::Job, created before Billing Phase 3.2 ships, has noCareers::JobPosting.- An existing
Careers::Jobhas noCareers::JobPostingexplains it.
- An existing
The model serves four user stories.
- As an HQ manager, I want to see the period and its cost before I post.
- As an HQ manager, I want to close, hide and open my job again for free during its period.
- As an HQ manager, I want to renew my job, so it stays posted with the same page and applicants.
- As Finance, I want each
Careers::JobPostingon the company's ledger, so revenue for Careers is exact.
The decisions behind this model are in Billing D17 — A Careers job post buys a job posting.
Schema truth: jodapp-api/docs/db/careers.dbml, table careers_job_postings.
Why Careers::JobPosting is its own table
A Careers::Job can buy many periods, and each payment needs its own record.
- The
consumeledger entry needs one deliverable per payment, and aCareers::Jobhas one row for all its payments. Careers::JobPostingkeeps the copied cost and the period dates out ofcareers_jobs.Careers::JobPosting.ends_atlives only here, socareers_jobshas no copy that could disagree with it.
An existing Careers::Job has no Careers::JobPosting
An existing Careers::Job is a Careers::Job created before Billing Phase 3.2 ships, and it has no Careers::JobPosting.
- It has no end date, and no rule on this page closes it.
- The hourly Sidekiq job
Careers::Jobs::CloseJobselects only aCareers::Jobthat has aCareers::JobPosting.
- The hourly Sidekiq job
- Its HQ manager hides it and opens it again any number of times, with no payment.
closedis its end state.- After its HQ manager closes it, it cannot open or hide again.
- It never gets a renew, so it never gets a
Careers::JobPosting.- A renew of a
Careers::Jobwith noCareers::JobPostingfails with a 422. - So an existing
Careers::Jobnever writes a ledger entry.
- A renew of a
- To hire again, the HQ manager posts a new
Careers::Job, which pays like any post. - Billing D17 — A Careers job post buys a job posting holds the decision.
What Careers::JobPosting does not store
Careers::JobPosting stores no paying account and no revenue.
- Billing records both on the
consumeledger entry, whose source is theCareers::JobPosting. Billing::SpendService.consume_nowfinds the account from the company of theCareers::Job, so Careers never reads aBilling::Account.- The company of the
Careers::Jobalways names the account.- Billing D16 — A company spends only its own billing account holds the rule.
Model Context
Legend:
- The orange node is the subject of this page.
- Lavender nodes belong to the Careers domain, and grey nodes belong to other domains.
- The dotted arrow is a reference back from Billing.
| Context | Details |
|---|---|
| Aggregate | Careers::JobPosting belongs to the Careers::Job aggregate, and it has no children. |
| Layer | The deliverable of a Careers spend |
| Upstream dependencies | The Careers::Job, the Careers::JobPostingPrice, and the Org::Membership of the HQ manager |
| Downstream dependents | The consume Billing::LedgerEntry that names the Careers::JobPosting as its source |
State Machine
A Careers::JobPosting has no status column, and its row never changes after it is created.
The time decides where a Careers::JobPosting stands.
| Where it stands | When |
|---|---|
| Not started | starts_at is in the future, after a renew of a running Careers::Job |
| Running | starts_at is in the past and ends_at is in the future |
| Ended | ends_at is in the past |
Worked example: Acme's Barista job
Acme Pte Ltd has 170 placement credits.
- The prices are "1 Month" for 50 credits and "3 Months" for 100 credits.
The diagram shows the steps below, in time order from top to bottom.
- On 14 Oct, Acme's HQ manager posts the Barista job with "1 Month".
- The system creates
Careers::JobPosting#1 withstarts_at: 14 Oct,ends_at: 13 Novandunit_cost_snapshot: 50. - The latest
Careers::JobPosting.ends_atof theCareers::Jobis 13 Nov, and Acme has 120 credits left.
- The system creates
- Acme hides the job on 20 Oct and opens it again on 25 Oct.
- The system creates no
Careers::JobPosting, and Acme pays nothing. Careers::JobPosting.ends_atstays 13 Nov, because hiding does not pause the period.
- The system creates no
- On 10 Nov, Acme renews the job with "3 Months".
- The system creates
Careers::JobPosting#2 withstarts_at: 13 Nov,ends_at: 11 Febandunit_cost_snapshot: 100. starts_atis 13 Nov, because that is the latestCareers::JobPosting.ends_atof theCareers::Job.- The latest
Careers::JobPosting.ends_atof theCareers::Jobbecomes 11 Feb, and Acme has 20 credits left. - Billing recognises the revenue of
Careers::JobPosting#2 on 10 Nov, although it starts on 13 Nov.
- The system creates
- On 11 Feb, the hourly Sidekiq job
Careers::Jobs::CloseJobsets theCareers::Jobtostatus: :closed. - The ledger of Acme shows two
consumeentries.- "Job post: Barista, 1 Month", for 50 credits.
- "Job renew: Barista, 3 Months", for 100 credits.
Worked example: Acme's Cashier job has no Careers::JobPosting
Acme's Cashier job is an existing Careers::Job, so it has no Careers::JobPosting.
The diagram shows the steps below, in time order from top to bottom.
- After Billing Phase 3.2 ships, the Cashier job is still
open, and it has no end date.- The hourly Sidekiq job
Careers::Jobs::CloseJobnever closes it.
- The hourly Sidekiq job
- On 20 Nov, Acme hides the job and opens it again.
- The system creates no
Careers::JobPosting, and Acme pays nothing.
- The system creates no
- On 1 Dec, a request to renew the job with "1 Month" fails with a 422.
- The Cashier job has no
Careers::JobPosting, so it cannot be renewed. - The system writes nothing, and Acme pays nothing.
- The job list shows the renew button of the Cashier job as disabled, with the text "Cannot renew".
- The Cashier job has no
- On 5 Dec, Acme closes the Cashier job.
- On 6 Dec, a request to open the Cashier job fails with a 422.
closedis the end state of an existingCareers::Job.- To hire a cashier again, Acme posts a new
Careers::Job, which pays like the Barista job.
Use Cases
| ID | Use Case | Trigger | Actor |
|---|---|---|---|
| UC-1 | Create the first Careers::JobPosting when an employer posts a job | An HQ manager posts a job with a price | HQ manager |
| UC-2 | Create a new Careers::JobPosting when an employer renews a job | An HQ manager renews a job with a price | HQ manager |
| UC-3 | View the Careers::JobPosting rows of a Careers::Job on the company's ledger | Finance or Sales opens the billing account | Finance |
UC-1: Create the first Careers::JobPosting when an employer posts a job
| Field | Details |
|---|---|
| Actor | Org::Membership (HQ manager) |
| Trigger | An HQ manager posts a job with a price |
Preconditions:
- The careers trial gate lets the company post.
- The picked
Careers::JobPostingPriceis active. Billing::SpendValidatorfinds enough placement credits on the company's own account.
System Behaviour:
- The system opens one database transaction, and saves the
Careers::Jobin it. - The system locks the
careers_jobsrow. - The system sets
starts_atto now. - The system sets
ends_attostarts_atplus the price'sduration_daysdays. - The system creates the
Careers::JobPostingwith these values:careers_job_idandcareers_job_posting_price_id;org_company_id, copied fromcareers_jobs.org_company_id;created_by_type: 'Org::Membership'and the HQ manager'screated_by_id;duration_days_snapshotandunit_cost_snapshot, copied from the price;idempotency_key, the key that the job form sent, and none for a renew;starts_atandends_at.
- The system pays with
Billing::SpendService.consume_now.unitsisunit_cost_snapshot, anddeliverableis theCareers::JobPosting.- The description is "Job post:
<job title>,<price name>".
Business Rules:
- A parent HQ manager who posts for a child company spends the child's own account.
consume_nowchecks the credits again under the balance row lock.- When credits are too low, it raises
Billing::InsufficientCreditsError, and the transaction leaves noCareers::JobPosting.
- When credits are too low, it raises
- The whole cost becomes revenue on the day the
Careers::Jobpays.- A trial lot recognises SGD 0.
- A post with no
idempotency_keyfails with a 422. - A second post with the same
idempotency_keycreates noCareers::Joband noCareers::JobPosting.- The system answers with the
Careers::Jobof the first post. - It looks for the key only among the
Careers::JobPostingrows of the same company, byorg_company_idandidempotency_key. - It checks the key before the preconditions, so a repeat with too few credits still gets the first
Careers::Job.
- The system answers with the
- The same key from two companies creates two
Careers::JobPostingrows, because the unique index is on(org_company_id, idempotency_key).
Postconditions:
- The
Careers::Jobhas oneCareers::JobPosting, and itsends_atis the latestCareers::JobPosting.ends_atof theCareers::Job. - The company's own account has one new
consumeledger entry, withsource_type: 'Careers::JobPosting'.
UC-2: Create a new Careers::JobPosting when an employer renews a job
| Field | Details |
|---|---|
| Actor | Org::Membership (HQ manager) |
| Trigger | An HQ manager renews a job with a price |
Preconditions:
- The preconditions of UC-1 hold.
- The
Careers::Jobhas at least oneCareers::JobPosting.- A renew of a
Careers::Jobwith noCareers::JobPostingfails with a 422, so an existingCareers::Jobnever renews.
- A renew of a
- The request carries the number of
Careers::JobPostingrows that the renew dialog showed.
System Behaviour:
- The system opens one database transaction and locks the
careers_jobsrow. - The system counts the
Careers::JobPostingrows of theCareers::Job, and compares the count with the number in the request.- When they differ, the request fails with a 422, and the system writes nothing.
- The system sets
starts_atfrom the latestCareers::JobPosting.ends_atof theCareers::Job.
The latest Careers::JobPosting.ends_at of the Careers::Job | starts_at | The status of the Careers::Job |
|---|---|---|
| In the future | The latest Careers::JobPosting.ends_at | Does not change |
| In the past | Now | Becomes open |
- The system runs UC-1 steps 4 to 6, with the description "Job renew:
<job title>,<price name>".
Business Rules:
- A renew of a running
Careers::Jobadds days at the end, so no paid day is lost. - A renew of an ended
Careers::Jobstarts now. - The whole cost becomes revenue on the renew day, also when the new period starts later.
- Two renews sent at the same moment run one after the other, because of the row lock.
- The second one carries an old number of
Careers::JobPostingrows, so it fails and pays nothing.
- The second one carries an old number of
- A renew on purpose opens the dialog again, which reads the new number.
Postconditions:
- The
Careers::Jobhas one moreCareers::JobPosting, and itsends_atis now the latestCareers::JobPosting.ends_atof theCareers::Job. - The
Careers::Jobkeeps its slug and its applicants.
UC-3: View the Careers::JobPosting rows of a Careers::Job on the company's ledger
| Field | Details |
|---|---|
| Actor | Identities::Admin (finance) |
| Trigger | Finance or Sales opens the billing account |
Preconditions:
- None.
System Behaviour:
- The ledger list shows one
consumeentry perCareers::JobPosting. - The source cell shows the description of the entry, such as "Job renew: Barista, 3 Months".
- The description links to
/team/careers/job-postings/<id>, which redirects to the Team Portal page of theCareers::Job.- That page shows the
Careers::Joband all itsCareers::JobPostingrows.
- That page shows the
Business Rules:
- A consume from a paid lot recognises revenue, and a consume from a trial or goodwill lot recognises SGD 0.
- A
Careers::Jobwith noCareers::JobPostinghas no ledger entry, so the ledger does not show it.
Postconditions:
- Read-only operation — no data changes.
Invariants
- A
Careers::JobPostingis created only together with itsconsume_now, in one database transaction.- A
Careers::JobPostingwith noconsumeentry would be a period nobody paid.
- A
- A
Careers::JobPostingis paid exactly once.- A second
consume_nowfor the sameCareers::JobPostingraises a 500, and its transaction rolls back.
- A second
- Every
Careers::JobPostinghas a price, becausecareers_job_posting_price_idis NOT NULL. unit_cost_snapshotis greater than 0, by a CHECK constraint.- A row never changes and is never deleted.
ends_atis afterstarts_at, by the CHECKends_at > starts_at, and it equalsstarts_atplusduration_days_snapshotdays.- Two periods of one
Careers::Jobnever start at the same moment, by the unique index on(careers_job_id, starts_at). - A
Careers::Jobnever changes company, also before it has aCareers::JobPosting.- Otherwise a
Careers::Jobpaid by one company's account could move to another company.
- Otherwise a
- Closing or hiding the
Careers::Jobnever changes aCareers::JobPosting, and it gives no credits back.- So close and hide are not a pause: a
Careers::Jobhidden for 10 days still ends on the sameends_at.
- So close and hide are not a pause: a
- One submit of the job form creates one
Careers::Jobat most, by the unique index on(org_company_id, idempotency_key). - One renew dialog buys one period at most, by the count check under the row lock.
org_company_idalways equals theorg_company_idof theCareers::Job.
- Invariant 8 keeps it true, because the company of the
Careers::Jobcannot change.
- An existing
Careers::Jobnever gets aCareers::JobPosting, because a renew of aCareers::Jobwith noCareers::JobPostingfails.
Model Interactions
| Related Model | Relationship | Interaction |
|---|---|---|
Careers::Job | belongs_to | A Careers::JobPosting decides when the Careers::Job closes, and a renew opens an ended Careers::Job |
Careers::JobPostingPrice | belongs_to | A Careers::JobPosting copies the price's duration_days and unit_cost when it is created |
Org::Company | belongs_to | The company of the Careers::Job, copied so the key of the job form is unique per company |
Org::Membership | polymorphic created_by | The HQ manager who posted or renewed the Careers::Job, and an Identities::Admin in a later phase |
Billing::SpendService | none | consume_now pays for a Careers::JobPosting and finds the company's own account |
Billing::LedgerEntry | referenced as its source | One consume entry per Careers::JobPosting records the account, the units and the revenue |
Related pages:
Careers::JobPostingPrice, the price that aCareers::JobPostingcopies.- Billing interface for product domains, the rules of
consume_now. - Billing Integration Phase 3.2 — Use Cases, the flows step by step.