Skip to main content

[Employer Sync 5.2] JIT detect-and-enqueue on employer login

TL;DR: When login misses, detect a real not-yet-synced jodgig employer (with valid password), enqueue a single-user sync, and raise Errors::MigrationInProgress (HTTP 409) so the frontend (6.3) shows "setting up your account" instead of a false "invalid password."

Context

JodGig employers will keep being created in the JodGig portal until JodGig is fully sunset. Even with the hourly batch (issue 5.3), a brand-new employer waits up to an hour to log in to JodApp — and that hour is exactly when sales is asking them to try it.

Problem

PR #1634 has no JIT path for employers. The current behaviour for a not-yet-synced employer is the generic Invalid email or password, which is wrong (their password is right) and looks broken. A talent JIT exists (JodGig::Users::JitMigrationService) but it is scoped to user_type = 'APP' and would never find an employer.

We cannot run the full employer migration inside a login request — companies and outlets must already exist, and a request thread is the wrong place for that.

Direction

Add a detect-and-enqueue step to Identities::Sessions::CreateManager. The login flow becomes:

  1. find_by on identities_users — if found, the existing flow continues.
  2. If not found, call the talent JIT — if it returns a user, continue.
  3. New step. Call a lightweight JodGig::Users::EmployerJitDetectService that:
    • Looks up JodGig::User by email or contact_number (matching the identifier).
    • Confirms user_type is in the employer set, is_deleted = 0, status = 1.
    • Confirms the password matches (JodGig::PasswordService.valid?).
    • If all true: enqueue JodGig::Users::EmployerSingleUserSyncJob with the jodgig user id, and raise Errors::MigrationInProgress (HTTP 409) with a stable code: 'migration_in_progress'.
    • If any false: return nil, and login falls through to the standard rejection.
  4. EmployerSingleUserSyncJob runs in the background, calls JodGig::Users::UpsertIdentitiesUserService.execute(jodgig_user:, kind: :employer), then runs the membership + outlet upserts for that one user. Companies and outlets must already exist in JodApp — if not, the job fails and the user retries when the next batch covers the dependency.

The frontend (issue 6.3) uses the typed error to render "Setting up your account — please try again in a moment" instead of the generic error.

Acceptance

  • Test: a not-yet-synced employer logs in with the correct password — receives 409 with code: migration_in_progress; an EmployerSingleUserSyncJob is enqueued; a second login attempt a moment later succeeds.
  • Test: a not-yet-synced employer logs in with the wrong password — receives the standard rejection; no job is enqueued.
  • Test: an identifier that is not a jodgig employer — standard rejection; no job is enqueued.
  • No Org::Company or Org::Outlet work happens inside the request thread.

Depends on

  • 5.1 (the shared upsert service the single-user job calls)