@cleverbrush/scheduler 1.1.3 → 1.1.5
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/dist/index.js +9 -7
- package/dist/jobRepository.d.ts +0 -4
- package/dist/jobRepository.js +0 -6
- package/dist/types.d.ts +12 -0
- package/dist/types.js +6 -2
- package/package.json +3 -9
package/dist/index.js
CHANGED
|
@@ -10,8 +10,7 @@ import { InMemoryJobRepository } from './jobRepository.js';
|
|
|
10
10
|
export { ScheduleCalculator, Schemas };
|
|
11
11
|
const MAX_BUFFER_SIZE = 10 * 1024 * 1024; // 10MB
|
|
12
12
|
const CHECK_INTERVAL = 1000 * 10; // every 10 seconds
|
|
13
|
-
|
|
14
|
-
const SCHEDULE_JOB_SPAN = 1000 * 60; // 1 hour
|
|
13
|
+
const SCHEDULE_JOB_SPAN = 1000 * 60; // 1 minute
|
|
15
14
|
const DEFAULT_JOB_TIMEOUT = 1000 * 20; // 20 seconds
|
|
16
15
|
const DEFAULT_MAX_CONSEQUENT_FAILS = 3;
|
|
17
16
|
const DEFAULT_MAX_RETRIES = 2;
|
|
@@ -296,6 +295,12 @@ export class JobScheduler extends EventEmitter {
|
|
|
296
295
|
const { date: nextRun, index } = schedule.next();
|
|
297
296
|
if (nextRun < new Date())
|
|
298
297
|
continue;
|
|
298
|
+
if (jobs[i].noConcurrentRuns) {
|
|
299
|
+
const runingInstances = await this._jobsRepository.getInstancesWithStatus(jobs[i].id, 'running');
|
|
300
|
+
if (runingInstances.length > 0) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
299
304
|
const alreadyScheduled = scheduledInstances.find((i) => i.index === index);
|
|
300
305
|
if (alreadyScheduled)
|
|
301
306
|
continue;
|
|
@@ -375,7 +380,8 @@ export class JobScheduler extends EventEmitter {
|
|
|
375
380
|
: DEFAULT_MAX_CONSEQUENT_FAILS,
|
|
376
381
|
maxRetries: typeof job.maxRetries === 'number'
|
|
377
382
|
? job.maxRetries
|
|
378
|
-
: DEFAULT_MAX_RETRIES
|
|
383
|
+
: DEFAULT_MAX_RETRIES,
|
|
384
|
+
noConcurrentRuns: job.noConcurrentRuns || false
|
|
379
385
|
});
|
|
380
386
|
}
|
|
381
387
|
/**
|
|
@@ -394,10 +400,6 @@ export class JobScheduler extends EventEmitter {
|
|
|
394
400
|
this._jobsRepository = props.persistRepository;
|
|
395
401
|
}
|
|
396
402
|
this._rootFolder = props.rootFolder;
|
|
397
|
-
setInterval(() => {
|
|
398
|
-
this._jobsRepository.dumpJobs();
|
|
399
|
-
this._jobsRepository.dumpInstances();
|
|
400
|
-
}, 10 * 1000);
|
|
401
403
|
}
|
|
402
404
|
on(name, callback) {
|
|
403
405
|
super.on(name, callback);
|
package/dist/jobRepository.d.ts
CHANGED
|
@@ -10,8 +10,6 @@ export interface IJobRepository {
|
|
|
10
10
|
getInstancesWithStatus(jobId: string, status: JobInstanceStatus): Promise<JobInstance[]>;
|
|
11
11
|
addInstance(jobId: string, instance: AddJobInstanceRequest): Promise<JobInstance>;
|
|
12
12
|
saveInstance(instance: JobInstance): Promise<JobInstance>;
|
|
13
|
-
dumpJobs(): void;
|
|
14
|
-
dumpInstances(): void;
|
|
15
13
|
}
|
|
16
14
|
export declare class InMemoryJobRepository implements IJobRepository {
|
|
17
15
|
private _jobs;
|
|
@@ -28,7 +26,5 @@ export declare class InMemoryJobRepository implements IJobRepository {
|
|
|
28
26
|
getInstancesWithStatus(jobId: string, status: JobInstanceStatus): Promise<JobInstance[]>;
|
|
29
27
|
getInstanceById(id: number): Promise<JobInstance>;
|
|
30
28
|
saveInstance(instance: JobInstance): Promise<JobInstance>;
|
|
31
|
-
dumpJobs(): void;
|
|
32
|
-
dumpInstances(): void;
|
|
33
29
|
}
|
|
34
30
|
export {};
|
package/dist/jobRepository.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -226,6 +226,10 @@ declare const CreateJobRequestSchema: import("@cleverbrush/schema").ObjectSchema
|
|
|
226
226
|
* Job will be retried right away this times. Job will be retried on next schedule run if this number is exceeded.
|
|
227
227
|
*/
|
|
228
228
|
maxRetries: import("@cleverbrush/schema").NumberSchemaBuilder<number, false>;
|
|
229
|
+
/**
|
|
230
|
+
* If true, job will not be runned if previous run is not finished yet.
|
|
231
|
+
*/
|
|
232
|
+
noConcurrentRuns: import("@cleverbrush/schema").BooleanSchemaBuilder<boolean, false, undefined, boolean>;
|
|
229
233
|
}, true, undefined>;
|
|
230
234
|
/**
|
|
231
235
|
* Schedule for job. Can be one of:
|
|
@@ -288,6 +292,10 @@ export type Job = {
|
|
|
288
292
|
* next schedule run if this number is exceeded.
|
|
289
293
|
*/
|
|
290
294
|
maxRetries: number;
|
|
295
|
+
/**
|
|
296
|
+
* If true, job will not be runned if previous run is not finished yet.
|
|
297
|
+
*/
|
|
298
|
+
noConcurrentRuns?: boolean;
|
|
291
299
|
};
|
|
292
300
|
export type JobInstance = {
|
|
293
301
|
/** Id of job instance */
|
|
@@ -578,6 +586,10 @@ export declare const Schemas: {
|
|
|
578
586
|
* Job will be retried right away this times. Job will be retried on next schedule run if this number is exceeded.
|
|
579
587
|
*/
|
|
580
588
|
maxRetries: import("@cleverbrush/schema").NumberSchemaBuilder<number, false>;
|
|
589
|
+
/**
|
|
590
|
+
* If true, job will not be runned if previous run is not finished yet.
|
|
591
|
+
*/
|
|
592
|
+
noConcurrentRuns: import("@cleverbrush/schema").BooleanSchemaBuilder<boolean, false, undefined, boolean>;
|
|
581
593
|
}, true, undefined>;
|
|
582
594
|
ScheduleMinuteSchema: import("@cleverbrush/schema").ObjectSchemaBuilder<Omit<Omit<{
|
|
583
595
|
/** Number of intervals (days, months, minutes or weeks)
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { array, boolean, date, func, number, object, string, union } from '@cleverbrush/schema';
|
|
2
2
|
const ScheduleSchemaBase = object({
|
|
3
3
|
/** Number of intervals (days, months, minutes or weeks)
|
|
4
4
|
* between repeats. Interval type depends of `every` value */
|
|
@@ -97,7 +97,11 @@ const CreateJobRequestSchema = object({
|
|
|
97
97
|
/**
|
|
98
98
|
* Job will be retried right away this times. Job will be retried on next schedule run if this number is exceeded.
|
|
99
99
|
*/
|
|
100
|
-
maxRetries: number().optional().min(1)
|
|
100
|
+
maxRetries: number().optional().min(1),
|
|
101
|
+
/**
|
|
102
|
+
* If true, job will not be runned if previous run is not finished yet.
|
|
103
|
+
*/
|
|
104
|
+
noConcurrentRuns: boolean().optional()
|
|
101
105
|
});
|
|
102
106
|
export const Schemas = {
|
|
103
107
|
ScheduleSchemaBase,
|
package/package.json
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
"email": "andrew_zol@cleverbrush.com"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@cleverbrush/schema": "1.1.
|
|
8
|
+
"@cleverbrush/schema": "1.1.5"
|
|
9
9
|
},
|
|
10
10
|
"description": "Job Scheduler for NodeJS",
|
|
11
11
|
"files": [
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://docs.cleverbrush.com/
|
|
14
|
+
"homepage": "https://docs.cleverbrush.com/modules/_cleverbrush_scheduler.html",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"task scheduler",
|
|
17
17
|
"task runner",
|
|
@@ -31,12 +31,6 @@
|
|
|
31
31
|
"build": "tsc"
|
|
32
32
|
},
|
|
33
33
|
"type": "module",
|
|
34
|
-
"typedoc": {
|
|
35
|
-
"entryPoint": "./src/index.ts",
|
|
36
|
-
"readmeFile": "./README.md",
|
|
37
|
-
"displayName": "Job Scheduler",
|
|
38
|
-
"tsconfig": "./tsconfig.json"
|
|
39
|
-
},
|
|
40
34
|
"types": "./dist/index.d.ts",
|
|
41
|
-
"version": "1.1.
|
|
35
|
+
"version": "1.1.5"
|
|
42
36
|
}
|