@orion-js/dogs 4.6.7 → 4.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +186 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +186 -25
- package/dist/index.js.map +1 -1
- package/dist/repos/JobsRepo.d.ts +1 -0
- package/dist/services/Executor.d.ts +6 -0
- package/dist/services/WorkerService.d.ts +3 -0
- package/dist/services/jobFilters.d.ts +21 -0
- package/dist/types/JobsDefinition.d.ts +7 -0
- package/dist/types/StartConfig.d.ts +39 -0
- package/package.json +1 -1
package/dist/repos/JobsRepo.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare class JobsRepo {
|
|
|
40
40
|
priority: number;
|
|
41
41
|
lockId?: string;
|
|
42
42
|
}): Promise<boolean>;
|
|
43
|
+
rescheduleAfterExecutionGuardAcquisitionFailure(jobId: string, lockId: string, nextRunAt: Date): Promise<boolean>;
|
|
43
44
|
deleteEventJob(jobId: string, lockId?: string): Promise<boolean>;
|
|
44
45
|
/**
|
|
45
46
|
* Marks an event job as having reached its maximum tries limit.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Blackbox } from '@orion-js/schema';
|
|
2
2
|
import { EventJobDefinition, JobDefinition, JobsDefinition } from '../types/JobsDefinition';
|
|
3
|
+
import { WorkerExecutionGuard, WorkerExecutionGuardLease } from '../types/StartConfig';
|
|
3
4
|
import { ExecutionContext, JobToRun } from '../types/Worker';
|
|
4
5
|
/**
|
|
5
6
|
* Configuration for job execution including max tries settings.
|
|
@@ -9,6 +10,8 @@ export interface ExecuteJobConfig {
|
|
|
9
10
|
maxTries?: number;
|
|
10
11
|
maxTriesReachedRetentionMs?: number | null;
|
|
11
12
|
onMaxTriesReached?: (job: JobToRun) => Promise<void>;
|
|
13
|
+
executionGuard?: WorkerExecutionGuard;
|
|
14
|
+
executionGuardRetryDelayMs?: number;
|
|
12
15
|
}
|
|
13
16
|
export declare class Executor {
|
|
14
17
|
private readonly jobsRepo;
|
|
@@ -40,5 +43,8 @@ export declare class Executor {
|
|
|
40
43
|
jobToRun: JobToRun;
|
|
41
44
|
}): Promise<void>;
|
|
42
45
|
afterExecutionSuccess(job: JobDefinition, jobToRun: JobToRun, context: ExecutionContext): Promise<boolean>;
|
|
46
|
+
handleExecutionGuardAcquisitionFailure(error: unknown, config: ExecuteJobConfig, jobToRun: JobToRun, context: ExecutionContext): Promise<void>;
|
|
47
|
+
releaseExecutionGuardLease(lease: WorkerExecutionGuardLease, jobToRun: JobToRun, context: ExecutionContext): Promise<void>;
|
|
48
|
+
runGuardedResolver(job: JobDefinition, jobToRun: JobToRun, context: ExecutionContext, lease: WorkerExecutionGuardLease): Promise<any>;
|
|
43
49
|
executeJob(config: ExecuteJobConfig, jobToRun: JobToRun, onExecutionStale: () => void): Promise<void>;
|
|
44
50
|
}
|
|
@@ -3,6 +3,7 @@ import { JobDefinitionWithName, JobsDefinition } from '../types/JobsDefinition';
|
|
|
3
3
|
import { StartWorkersConfig } from '../types/StartConfig';
|
|
4
4
|
import { JobToRun, WorkersInstance } from '../types/Worker';
|
|
5
5
|
import { ExecuteJobConfig } from './Executor';
|
|
6
|
+
import { PendingFilterChecks } from './jobFilters';
|
|
6
7
|
interface TrackedExecution {
|
|
7
8
|
job: JobToRun;
|
|
8
9
|
promise: Promise<void>;
|
|
@@ -14,6 +15,7 @@ interface InternalWorkersInstance extends WorkersInstance {
|
|
|
14
15
|
activeExecutions: Map<string, TrackedExecution>;
|
|
15
16
|
staleExecutions: Map<string, TrackedExecution>;
|
|
16
17
|
runningJobsByName: Map<string, number>;
|
|
18
|
+
pendingFilterChecks: PendingFilterChecks;
|
|
17
19
|
jobAcquisitionHint: JobAcquisitionHint;
|
|
18
20
|
jobAcquisitionHintProbeCycle: number;
|
|
19
21
|
hasCompletedInitialJobAcquisitionHintProbe: boolean;
|
|
@@ -38,6 +40,7 @@ export declare class WorkerService {
|
|
|
38
40
|
private partitionReconcilerJitterMs;
|
|
39
41
|
private partitionReconcilerBatchPauseMs;
|
|
40
42
|
private partitionReconcilerBatchSize;
|
|
43
|
+
private jobsFilterTimeoutMs;
|
|
41
44
|
private jobsRepo;
|
|
42
45
|
private executor;
|
|
43
46
|
getJobNames(jobs: JobsDefinition): string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JobsDefinition } from '../types/JobsDefinition';
|
|
2
|
+
import { GetJobsFilter } from '../types/StartConfig';
|
|
3
|
+
export declare const DEFAULT_JOBS_FILTER_TIMEOUT_MS = 5000;
|
|
4
|
+
/**
|
|
5
|
+
* Checks that are still running, keyed by check name. A timed out check stays here until it
|
|
6
|
+
* settles so later claims skip it immediately instead of waiting for the timeout again.
|
|
7
|
+
*/
|
|
8
|
+
export type PendingFilterChecks = Map<string, Promise<unknown>>;
|
|
9
|
+
interface TakeableJobNamesOptions {
|
|
10
|
+
jobs: JobsDefinition;
|
|
11
|
+
getJobsFilter?: GetJobsFilter;
|
|
12
|
+
jobNames: string[];
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
pendingChecks?: PendingFilterChecks;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Applies the global getJobsFilter and each job's canTakeJobs to decide which jobs can be claimed.
|
|
18
|
+
* Any error or timeout excludes the affected jobs.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getTakeableJobNames(inputOptions: TakeableJobNamesOptions): Promise<string[]>;
|
|
21
|
+
export {};
|
|
@@ -37,6 +37,13 @@ export interface BaseJobDefinition {
|
|
|
37
37
|
* If not set, the defaultLockTime from config will be used.
|
|
38
38
|
*/
|
|
39
39
|
lockTime?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Optional function evaluated before each claim to decide if this server can take this job,
|
|
42
|
+
* for example to stop taking a heavy job while the server is under load.
|
|
43
|
+
* Must resolve to true to take the job. If it throws or takes more than 5 seconds, the job is not taken.
|
|
44
|
+
* Running jobs are not affected. It runs before every claim without caching, so keep it cheap.
|
|
45
|
+
*/
|
|
46
|
+
canTakeJobs?: () => Promise<boolean>;
|
|
40
47
|
}
|
|
41
48
|
export interface RecurrentJobDefinition extends BaseJobDefinition {
|
|
42
49
|
/**
|
|
@@ -2,6 +2,32 @@ import { JobsDefinition } from './JobsDefinition';
|
|
|
2
2
|
import { JobToRun } from './Worker';
|
|
3
3
|
export type LogLevels = 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
4
4
|
export declare const DEFAULT_MAX_TRIES_REACHED_RETENTION_MS: number;
|
|
5
|
+
/**
|
|
6
|
+
* A lease held for the duration of one job resolver execution.
|
|
7
|
+
*/
|
|
8
|
+
export interface WorkerExecutionGuardLease {
|
|
9
|
+
release(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Acquires infrastructure protection for a claimed job before its resolver starts.
|
|
13
|
+
*/
|
|
14
|
+
export interface WorkerExecutionGuard {
|
|
15
|
+
acquire(job: JobToRun): Promise<WorkerExecutionGuardLease>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Job names this server can take. Undefined properties are ignored; an empty allow list takes nothing.
|
|
19
|
+
*/
|
|
20
|
+
export interface JobsFilter {
|
|
21
|
+
/**
|
|
22
|
+
* Only these jobs can be taken.
|
|
23
|
+
*/
|
|
24
|
+
allow?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* These jobs can't be taken.
|
|
27
|
+
*/
|
|
28
|
+
deny?: string[];
|
|
29
|
+
}
|
|
30
|
+
export type GetJobsFilter = () => Promise<JobsFilter>;
|
|
5
31
|
export interface StartWorkersConfig {
|
|
6
32
|
/**
|
|
7
33
|
* Object map of the jobs that this scheduler will execute.
|
|
@@ -24,6 +50,19 @@ export interface StartWorkersConfig {
|
|
|
24
50
|
* configured retention period expires.
|
|
25
51
|
*/
|
|
26
52
|
onMaxTriesReached?: (job: JobToRun) => Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Optional infrastructure guard acquired after a job is claimed and before its resolver starts.
|
|
55
|
+
* The returned lease is held until the resolver's Promise settles, including late stale
|
|
56
|
+
* executions. Acquisition failures safely requeue the job without consuming a business try.
|
|
57
|
+
*/
|
|
58
|
+
executionGuard?: WorkerExecutionGuard;
|
|
59
|
+
/**
|
|
60
|
+
* Optional function evaluated before each claim to decide which jobs this server can take,
|
|
61
|
+
* for example to stop taking heavy jobs while the server is under load.
|
|
62
|
+
* If it throws or takes more than 5 seconds, no jobs are taken on that claim.
|
|
63
|
+
* Running jobs are not affected. It runs before every claim without caching, so keep it cheap.
|
|
64
|
+
*/
|
|
65
|
+
getJobsFilter?: GetJobsFilter;
|
|
27
66
|
/**
|
|
28
67
|
* Time in milliseconds to wait between each look without results for a job
|
|
29
68
|
* to run at the database. Default is 3000.
|