Skip to main content

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::JobPosting of a Careers::Job, and each renew creates one more.
  • Every Careers::JobPosting pays with placement credits, through one consume ledger entry in Billing.
  • A Careers::Job with a Careers::JobPosting stays open or hidden only while its latest Careers::JobPosting.ends_at is in the future.
  • An existing Careers::Job, created before Billing Phase 3.2 ships, has no Careers::JobPosting.

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::JobPosting on 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 consume ledger entry needs one deliverable per payment, and a Careers::Job has one row for all its payments.
  • Careers::JobPosting keeps the copied cost and the period dates out of careers_jobs.
  • Careers::JobPosting.ends_at lives only here, so careers_jobs has 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::CloseJob selects only a Careers::Job that has a Careers::JobPosting.
  • Its HQ manager hides it and opens it again any number of times, with no payment.
  • closed is 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::Job with no Careers::JobPosting fails with a 422.
    • So an existing Careers::Job never writes a ledger entry.
  • 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 consume ledger entry, whose source is the Careers::JobPosting.
  • Billing::SpendService.consume_now finds the account from the company of the Careers::Job, so Careers never reads a Billing::Account.
  • The company of the Careers::Job always names the account.

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.
ContextDetails
AggregateCareers::JobPosting belongs to the Careers::Job aggregate, and it has no children.
LayerThe deliverable of a Careers spend
Upstream dependenciesThe Careers::Job, the Careers::JobPostingPrice, and the Org::Membership of the HQ manager
Downstream dependentsThe 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 standsWhen
Not startedstarts_at is in the future, after a renew of a running Careers::Job
Runningstarts_at is in the past and ends_at is in the future
Endedends_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.

  1. On 14 Oct, Acme's HQ manager posts the Barista job with "1 Month".
    • The system creates Careers::JobPosting #1 with starts_at: 14 Oct, ends_at: 13 Nov and unit_cost_snapshot: 50.
    • The latest Careers::JobPosting.ends_at of the Careers::Job is 13 Nov, and Acme has 120 credits left.
  2. 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_at stays 13 Nov, because hiding does not pause the period.
  3. On 10 Nov, Acme renews the job with "3 Months".
    • The system creates Careers::JobPosting #2 with starts_at: 13 Nov, ends_at: 11 Feb and unit_cost_snapshot: 100.
    • starts_at is 13 Nov, because that is the latest Careers::JobPosting.ends_at of the Careers::Job.
    • The latest Careers::JobPosting.ends_at of the Careers::Job becomes 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.
  4. On 11 Feb, the hourly Sidekiq job Careers::Jobs::CloseJob sets the Careers::Job to status: :closed.
  5. The ledger of Acme shows two consume entries.
    • "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.

  1. After Billing Phase 3.2 ships, the Cashier job is still open, and it has no end date.
    • The hourly Sidekiq job Careers::Jobs::CloseJob never closes it.
  2. On 20 Nov, Acme hides the job and opens it again.
    • The system creates no Careers::JobPosting, and Acme pays nothing.
  3. 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".
  4. On 5 Dec, Acme closes the Cashier job.
  5. On 6 Dec, a request to open the Cashier job fails with a 422.
    • closed is the end state of an existing Careers::Job.
    • To hire a cashier again, Acme posts a new Careers::Job, which pays like the Barista job.

Use Cases​

IDUse CaseTriggerActor
UC-1Create the first Careers::JobPosting when an employer posts a jobAn HQ manager posts a job with a priceHQ manager
UC-2Create a new Careers::JobPosting when an employer renews a jobAn HQ manager renews a job with a priceHQ manager
UC-3View the Careers::JobPosting rows of a Careers::Job on the company's ledgerFinance or Sales opens the billing accountFinance

UC-1: Create the first Careers::JobPosting when an employer posts a job​

FieldDetails
ActorOrg::Membership (HQ manager)
TriggerAn HQ manager posts a job with a price

Preconditions:

  • The careers trial gate lets the company post.
  • The picked Careers::JobPostingPrice is active.
  • Billing::SpendValidator finds enough placement credits on the company's own account.

System Behaviour:

  1. The system opens one database transaction, and saves the Careers::Job in it.
  2. The system locks the careers_jobs row.
  3. The system sets starts_at to now.
  4. The system sets ends_at to starts_at plus the price's duration_days days.
  5. The system creates the Careers::JobPosting with these values:
    • careers_job_id and careers_job_posting_price_id;
    • org_company_id, copied from careers_jobs.org_company_id;
    • created_by_type: 'Org::Membership' and the HQ manager's created_by_id;
    • duration_days_snapshot and unit_cost_snapshot, copied from the price;
    • idempotency_key, the key that the job form sent, and none for a renew;
    • starts_at and ends_at.
  6. The system pays with Billing::SpendService.consume_now.
    • units is unit_cost_snapshot, and deliverable is the Careers::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_now checks the credits again under the balance row lock.
    • When credits are too low, it raises Billing::InsufficientCreditsError, and the transaction leaves no Careers::JobPosting.
  • The whole cost becomes revenue on the day the Careers::Job pays.
    • A trial lot recognises SGD 0.
  • A post with no idempotency_key fails with a 422.
  • A second post with the same idempotency_key creates no Careers::Job and no Careers::JobPosting.
    • The system answers with the Careers::Job of the first post.
    • It looks for the key only among the Careers::JobPosting rows of the same company, by org_company_id and idempotency_key.
    • It checks the key before the preconditions, so a repeat with too few credits still gets the first Careers::Job.
  • The same key from two companies creates two Careers::JobPosting rows, because the unique index is on (org_company_id, idempotency_key).

Postconditions:

  • The Careers::Job has one Careers::JobPosting, and its ends_at is the latest Careers::JobPosting.ends_at of the Careers::Job.
  • The company's own account has one new consume ledger entry, with source_type: 'Careers::JobPosting'.

UC-2: Create a new Careers::JobPosting when an employer renews a job​

FieldDetails
ActorOrg::Membership (HQ manager)
TriggerAn HQ manager renews a job with a price

Preconditions:

  • The preconditions of UC-1 hold.
  • The Careers::Job has at least one Careers::JobPosting.
    • A renew of a Careers::Job with no Careers::JobPosting fails with a 422, so an existing Careers::Job never renews.
  • The request carries the number of Careers::JobPosting rows that the renew dialog showed.

System Behaviour:

  1. The system opens one database transaction and locks the careers_jobs row.
  2. The system counts the Careers::JobPosting rows of the Careers::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.
  3. The system sets starts_at from the latest Careers::JobPosting.ends_at of the Careers::Job.
The latest Careers::JobPosting.ends_at of the Careers::Jobstarts_atThe status of the Careers::Job
In the futureThe latest Careers::JobPosting.ends_atDoes not change
In the pastNowBecomes open
  1. 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::Job adds days at the end, so no paid day is lost.
  • A renew of an ended Careers::Job starts 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::JobPosting rows, so it fails and pays nothing.
  • A renew on purpose opens the dialog again, which reads the new number.

Postconditions:

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

UC-3: View the Careers::JobPosting rows of a Careers::Job on the company's ledger​

FieldDetails
ActorIdentities::Admin (finance)
TriggerFinance or Sales opens the billing account

Preconditions:

  • None.

System Behaviour:

  1. The ledger list shows one consume entry per Careers::JobPosting.
  2. The source cell shows the description of the entry, such as "Job renew: Barista, 3 Months".
  3. The description links to /team/careers/job-postings/<id>, which redirects to the Team Portal page of the Careers::Job.
    • That page shows the Careers::Job and all its Careers::JobPosting rows.

Business Rules:

  • A consume from a paid lot recognises revenue, and a consume from a trial or goodwill lot recognises SGD 0.
  • A Careers::Job with no Careers::JobPosting has no ledger entry, so the ledger does not show it.

Postconditions:

  • Read-only operation — no data changes.

Invariants​

  1. A Careers::JobPosting is created only together with its consume_now, in one database transaction.
    • A Careers::JobPosting with no consume entry would be a period nobody paid.
  2. A Careers::JobPosting is paid exactly once.
    • A second consume_now for the same Careers::JobPosting raises a 500, and its transaction rolls back.
  3. Every Careers::JobPosting has a price, because careers_job_posting_price_id is NOT NULL.
  4. unit_cost_snapshot is greater than 0, by a CHECK constraint.
  5. A row never changes and is never deleted.
  6. ends_at is after starts_at, by the CHECK ends_at > starts_at, and it equals starts_at plus duration_days_snapshot days.
  7. Two periods of one Careers::Job never start at the same moment, by the unique index on (careers_job_id, starts_at).
  8. A Careers::Job never changes company, also before it has a Careers::JobPosting.
    • Otherwise a Careers::Job paid by one company's account could move to another company.
  9. Closing or hiding the Careers::Job never changes a Careers::JobPosting, and it gives no credits back.
    • So close and hide are not a pause: a Careers::Job hidden for 10 days still ends on the same ends_at.
  10. One submit of the job form creates one Careers::Job at most, by the unique index on (org_company_id, idempotency_key).
  11. One renew dialog buys one period at most, by the count check under the row lock.
  12. org_company_id always equals the org_company_id of the Careers::Job.
  • Invariant 8 keeps it true, because the company of the Careers::Job cannot change.
  1. An existing Careers::Job never gets a Careers::JobPosting, because a renew of a Careers::Job with no Careers::JobPosting fails.

Model Interactions​

Related ModelRelationshipInteraction
Careers::Jobbelongs_toA Careers::JobPosting decides when the Careers::Job closes, and a renew opens an ended Careers::Job
Careers::JobPostingPricebelongs_toA Careers::JobPosting copies the price's duration_days and unit_cost when it is created
Org::Companybelongs_toThe company of the Careers::Job, copied so the key of the job form is unique per company
Org::Membershippolymorphic created_byThe HQ manager who posted or renewed the Careers::Job, and an Identities::Admin in a later phase
Billing::SpendServicenoneconsume_now pays for a Careers::JobPosting and finds the company's own account
Billing::LedgerEntryreferenced as its sourceOne consume entry per Careers::JobPosting records the account, the units and the revenue

Related pages: