Kaizen
Browse modulesBackground jobsClasses

Class: BackgroundJobRunRepository

Defined in: server/background-jobs/background-job-run-repository.ts:29

Repository for background_job_runs rows — the opt-in job-runs audit table.

Extends BaseRepository<PrismaClient, Tx<PrismaClient>> so this.tx resolves to the active transaction handle when called inside a TransactionManager scope, and falls back to the raw client otherwise. Audit columns are populated via the inherited auditCreate / auditUpdate getters (sourced from the constructor-time actor), not direct actorId access.

Extends BaseRepository directly rather than CrudRepository / WriteRepository: this is a status-tracking audit log written from the lifecycle subscriber (upsert-on-queue, then monotonic status updates by jobId). One row per (queueName, jobId) represents the latest run — a reused custom jobId (BullMQ's dedup pattern) resets the row to a fresh run rather than accumulating duplicates. It has no read/ownership/soft-delete lifecycle, so the CRUD template machinery would be unused.

NOTE: this repo requires the consumer's Prisma client to expose the backgroundJobRun model (run taproot db:setup). Audit writes are best-effort — the lifecycle subscriber catches and logs failures rather than throwing — so a misconfigured consumer surfaces as a per-job console.error rather than failing fast. Pass repo only when the model is present.

Extends

Constructors

Constructor

new BackgroundJobRunRepository(prismaClient: PrismaClientLike<Tx<PrismaClient<PrismaClientOptions, never, DefaultArgs>>> & PrismaClient<PrismaClientOptions, never, DefaultArgs>, options?: RepositoryOptions): BackgroundJobRunRepository;

Defined in: server/persistence/base-repository.ts:68

Parameters

ParameterType
prismaClientPrismaClientLike<Tx<PrismaClient<PrismaClientOptions, never, DefaultArgs>>> & PrismaClient<PrismaClientOptions, never, DefaultArgs>
optionsRepositoryOptions

Returns

BackgroundJobRunRepository

Inherited from

BaseRepository.constructor

Properties

ENTITY_TYPE?

protected readonly optional ENTITY_TYPE?: string;

Defined in: server/persistence/base-repository.ts:61

Set ENTITY_TYPE in child repositories to enable automatic activity logging. When set, create/update/delete operations auto-log unless silenced with .silent. Requires an activity model on the consumer's Prisma schema.

Inherited from

BaseRepository.ENTITY_TYPE


logger?

protected readonly optional logger?: Logger;

Defined in: server/persistence/base-repository.ts:64

Inherited from

BaseRepository.logger


prismaClient

protected prismaClient: PrismaClientLike<Tx<PrismaClient<PrismaClientOptions, never, DefaultArgs>>> & PrismaClient<PrismaClientOptions, never, DefaultArgs>;

Defined in: server/persistence/base-repository.ts:69

Inherited from

BaseRepository.prismaClient

Accessors

actorId

Get Signature

get protected actorId(): string | null | undefined;

Defined in: server/persistence/base-repository.ts:76

Returns

string | null | undefined

Inherited from

BaseRepository.actorId


auditCreate

Get Signature

get protected auditCreate(): {
  createdBy: string | null | undefined;
  updatedBy: string | null | undefined;
};

Defined in: server/persistence/base-repository.ts:90

Returns
{
  createdBy: string | null | undefined;
  updatedBy: string | null | undefined;
}
createdBy
createdBy: string | null | undefined = actorId;
updatedBy
updatedBy: string | null | undefined = actorId;

Inherited from

BaseRepository.auditCreate


auditDelete

Get Signature

get protected auditDelete(): {
  deletedAt: Date;
  deletedBy: string | null | undefined;
};

Defined in: server/persistence/base-repository.ts:99

Returns
{
  deletedAt: Date;
  deletedBy: string | null | undefined;
}
deletedAt
deletedAt: Date;
deletedBy
deletedBy: string | null | undefined;

Inherited from

BaseRepository.auditDelete


auditUpdate

Get Signature

get protected auditUpdate(): {
  updatedBy: string | null | undefined;
};

Defined in: server/persistence/base-repository.ts:95

Returns
{
  updatedBy: string | null | undefined;
}
updatedBy
updatedBy: string | null | undefined;

Inherited from

BaseRepository.auditUpdate


silent

Get Signature

get silent(): this;

Defined in: server/persistence/base-repository.ts:115

Suppress activity logging for the next mutation call. One-shot: the flag is consumed by the next create/update/delete.

Example
await repo.silent.update(id, data);   // no activity logged
await repo.update(id, data);          // activity logged normally
Returns

this

Inherited from

BaseRepository.silent


tx

Get Signature

get protected tx(): TTx;

Defined in: server/persistence/base-repository.ts:86

The current Prisma handle: the active transaction if one is running on this async context, otherwise the raw client.

Returns

TTx

Inherited from

BaseRepository.tx

Methods

consumeSilent()

protected consumeSilent(): boolean;

Defined in: server/persistence/base-repository.ts:128

Consume and reset the silent flag. Called by template methods.

Returns

boolean

Inherited from

BaseRepository.consumeSilent


logActivity()

protected logActivity(
   _entityId: string, 
   _action: string, 
   _metadata?: Record<string, unknown>
): Promise<void>;

Defined in: server/persistence/base-repository.ts:140

Log an activity entry.

NOTE: This is not implemented because there's no activity model implemented in taproot yet! https://linear.app/kaizenlabs/issue/ENG-7846/add-activity-log-tables

Parameters

ParameterType
_entityIdstring
_actionstring
_metadata?Record<string, unknown>

Returns

Promise<void>

Inherited from

BaseRepository.logActivity


recordCompletion()

recordCompletion(queueName: string, jobId: string): Promise<void>;

Defined in: server/background-jobs/background-job-run-repository.ts:64

Parameters

ParameterType
queueNamestring
jobIdstring

Returns

Promise<void>


recordFailure()

recordFailure(
   queueName: string, 
   jobId: string, 
   error: string
): Promise<void>;

Defined in: server/background-jobs/background-job-run-repository.ts:76

Parameters

ParameterType
queueNamestring
jobIdstring
errorstring

Returns

Promise<void>


recordQueued()

recordQueued(params: {
  jobId: string;
  jobName: string;
  organizationId?: string;
  queueName: string;
}): Promise<void>;

Defined in: server/background-jobs/background-job-run-repository.ts:33

Parameters

ParameterType
params{ jobId: string; jobName: string; organizationId?: string; queueName: string; }
params.jobIdstring
params.jobNamestring
params.organizationId?string
params.queueNamestring

Returns

Promise<void>


recordStalled()

recordStalled(queueName: string, jobId: string): Promise<void>;

Defined in: server/background-jobs/background-job-run-repository.ts:93

Parameters

ParameterType
queueNamestring
jobIdstring

Returns

Promise<void>

On this page