[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:
find_byonidentities_users— if found, the existing flow continues.- If not found, call the talent JIT — if it returns a user, continue.
- New step. Call a lightweight
JodGig::Users::EmployerJitDetectServicethat:- Looks up
JodGig::Userbyemailorcontact_number(matching the identifier). - Confirms
user_typeis in the employer set,is_deleted = 0,status = 1. - Confirms the password matches (
JodGig::PasswordService.valid?). - If all true: enqueue
JodGig::Users::EmployerSingleUserSyncJobwith the jodgig user id, and raiseErrors::MigrationInProgress(HTTP 409) with a stablecode: 'migration_in_progress'. - If any false: return
nil, and login falls through to the standard rejection.
- Looks up
EmployerSingleUserSyncJobruns in the background, callsJodGig::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; anEmployerSingleUserSyncJobis 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::CompanyorOrg::Outletwork happens inside the request thread.
Depends on
- 5.1 (the shared upsert service the single-user job calls)