Skip to content

basalt / prisma/src / crossTenantSweep

Function: crossTenantSweep() ​

> crossTenantSweep(options): Promise<CrossTenantSweepResult>

Defined in: prisma/src/cross-tenant.ts:529

Pages through a cross-tenant scan and processes every row inside its own tenant's context, grouping consecutive rows of the same tenant into one run:

const result = await crossTenantSweep({
  client: db,
  scanFunction: 'stuck_jobs',
  run: (id, fn) => tenancy.run(id, fn),
  handle: (item) => RetryJob.dispatch({ jobId: item.id }),
})

The scan runs as central code (no tenant in scope); handle runs with the tenant set, so the scoped client and the RLS policies apply again and the item can be read and updated normally. A tenant whose rows straddle a page boundary is simply entered once per page.

Bounded by construction: limit rows per page, maxItems rows in total, and the generated function clamps the page size to its own maxRows. handle failures are isolated per item and reported to onError.

Refuses to run inside a tenant context (CrossTenantScanInTenantError).

Parameters ​

options ​

CrossTenantSweepOptions

Returns ​

Promise<CrossTenantSweepResult>

Released under the MIT License.