@bgord/bun 1.4.16 → 1.4.18
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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/job-handler.service.d.ts +23 -0
- package/dist/job-handler.service.d.ts.map +1 -0
- package/dist/job-handler.service.js +39 -0
- package/dist/job-handler.service.js.map +1 -0
- package/dist/jobs.service.d.ts +0 -21
- package/dist/jobs.service.d.ts.map +1 -1
- package/dist/jobs.service.js +0 -42
- package/dist/jobs.service.js.map +1 -1
- package/dist/prerequisites/jobs.d.ts +2 -2
- package/dist/prerequisites/jobs.js +3 -3
- package/dist/remote-file-storage-disk.adapter.d.ts +1 -0
- package/dist/remote-file-storage-disk.adapter.d.ts.map +1 -1
- package/dist/remote-file-storage-disk.adapter.js +3 -0
- package/dist/remote-file-storage-disk.adapter.js.map +1 -1
- package/dist/remote-file-storage-noop.adapter.d.ts +4 -2
- package/dist/remote-file-storage-noop.adapter.d.ts.map +1 -1
- package/dist/remote-file-storage-noop.adapter.js +3 -0
- package/dist/remote-file-storage-noop.adapter.js.map +1 -1
- package/dist/remote-file-storage.port.d.ts +1 -0
- package/dist/remote-file-storage.port.d.ts.map +1 -1
- package/dist/temporary-file-absolute.adapter.d.ts +1 -0
- package/dist/temporary-file-absolute.adapter.d.ts.map +1 -1
- package/dist/temporary-file-absolute.adapter.js +3 -0
- package/dist/temporary-file-absolute.adapter.js.map +1 -1
- package/dist/temporary-file-noop.adapter.d.ts +1 -0
- package/dist/temporary-file-noop.adapter.d.ts.map +1 -1
- package/dist/temporary-file-noop.adapter.js +3 -0
- package/dist/temporary-file-noop.adapter.js.map +1 -1
- package/dist/temporary-file.port.d.ts +1 -0
- package/dist/temporary-file.port.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +1 -0
- package/src/index.ts +1 -0
- package/src/job-handler.service.ts +54 -0
- package/src/jobs.service.ts +0 -54
- package/src/prerequisites/jobs.ts +4 -4
- package/src/remote-file-storage-disk.adapter.ts +4 -0
- package/src/remote-file-storage-noop.adapter.ts +6 -2
- package/src/remote-file-storage.port.ts +1 -0
- package/src/temporary-file-absolute.adapter.ts +4 -0
- package/src/temporary-file-noop.adapter.ts +4 -0
- package/src/temporary-file.port.ts +2 -0
package/package.json
CHANGED
package/readme.md
CHANGED
package/src/index.ts
CHANGED
|
@@ -110,6 +110,7 @@ export * from "./image-resizer-noop.adapter";
|
|
|
110
110
|
export * from "./image-resizer-sharp.adapter";
|
|
111
111
|
export * from "./invariant.service";
|
|
112
112
|
export * from "./invariant-error-handler.service";
|
|
113
|
+
export * from "./job-handler.service";
|
|
113
114
|
export * from "./jobs.service";
|
|
114
115
|
export * from "./json-file-reader.port";
|
|
115
116
|
export * from "./json-file-reader-bun.adapter";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import type { Cron } from "croner";
|
|
3
|
+
import type { ClockPort } from "./clock.port";
|
|
4
|
+
import { CorrelationStorage } from "./correlation-storage.service";
|
|
5
|
+
import type { IdProviderPort } from "./id-provider.port";
|
|
6
|
+
import type { JobNameType } from "./jobs.service";
|
|
7
|
+
import type { LoggerPort } from "./logger.port";
|
|
8
|
+
import { formatError } from "./logger-format-error.service";
|
|
9
|
+
|
|
10
|
+
type Dependencies = { Logger: LoggerPort; IdProvider: IdProviderPort; Clock: ClockPort };
|
|
11
|
+
|
|
12
|
+
export interface UnitOfWork {
|
|
13
|
+
label: JobNameType;
|
|
14
|
+
process: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class JobHandler {
|
|
18
|
+
private readonly base = { component: "infra", operation: "job_handler" };
|
|
19
|
+
|
|
20
|
+
constructor(private readonly deps: Dependencies) {}
|
|
21
|
+
|
|
22
|
+
handle(uow: UnitOfWork) {
|
|
23
|
+
const correlationId = this.deps.IdProvider.generate();
|
|
24
|
+
|
|
25
|
+
return async () => {
|
|
26
|
+
const stopwatch = new tools.Stopwatch(this.deps.Clock.now());
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
this.deps.Logger.info({ message: `${uow.label} start`, correlationId, ...this.base });
|
|
30
|
+
|
|
31
|
+
await CorrelationStorage.run(correlationId, uow.process);
|
|
32
|
+
|
|
33
|
+
this.deps.Logger.info({
|
|
34
|
+
message: `${uow.label} success`,
|
|
35
|
+
correlationId,
|
|
36
|
+
metadata: stopwatch.stop(),
|
|
37
|
+
...this.base,
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
this.deps.Logger.error({
|
|
41
|
+
message: `${uow.label} error`,
|
|
42
|
+
correlationId,
|
|
43
|
+
error: formatError(error),
|
|
44
|
+
metadata: { ...stopwatch.stop() },
|
|
45
|
+
...this.base,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protect(cron: Cron) {
|
|
52
|
+
return async () => this.deps.Logger.info({ message: `${cron.name} overrun`, ...this.base });
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/jobs.service.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import * as tools from "@bgord/tools";
|
|
2
1
|
import type { Cron } from "croner";
|
|
3
|
-
import type { ClockPort } from "./clock.port";
|
|
4
|
-
import { CorrelationStorage } from "./correlation-storage.service";
|
|
5
|
-
import type { IdProviderPort } from "./id-provider.port";
|
|
6
|
-
import type { LoggerPort } from "./logger.port";
|
|
7
|
-
import { formatError } from "./logger-format-error.service";
|
|
8
2
|
|
|
9
3
|
export type JobNameType = string;
|
|
10
4
|
export type MultipleJobsType = Record<JobNameType, Cron>;
|
|
11
|
-
export type JobProcessorType = { cron: string; label: JobNameType; process: () => Promise<void> };
|
|
12
|
-
|
|
13
|
-
type Dependencies = { Logger: LoggerPort; IdProvider: IdProviderPort; Clock: ClockPort };
|
|
14
5
|
|
|
15
6
|
export class Jobs {
|
|
16
7
|
static SCHEDULES = { EVERY_MINUTE: "* * * * *", EVERY_HOUR: "0 * * * *" };
|
|
@@ -23,48 +14,3 @@ export class Jobs {
|
|
|
23
14
|
return Object.values(jobs).every((job) => job.isRunning());
|
|
24
15
|
}
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
export class JobHandler {
|
|
28
|
-
private readonly base = { component: "infra", operation: "job_handler" };
|
|
29
|
-
|
|
30
|
-
constructor(private readonly deps: Dependencies) {}
|
|
31
|
-
|
|
32
|
-
handle(jobProcessor: JobProcessorType) {
|
|
33
|
-
const correlationId = this.deps.IdProvider.generate();
|
|
34
|
-
|
|
35
|
-
// biome-ignore lint: lint/complexity/noUselessThisAlias
|
|
36
|
-
const that = this;
|
|
37
|
-
|
|
38
|
-
return async () => {
|
|
39
|
-
const stopwatch = new tools.Stopwatch(this.deps.Clock.now());
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
that.deps.Logger.info({ message: `${jobProcessor.label} start`, correlationId, ...this.base });
|
|
43
|
-
|
|
44
|
-
await CorrelationStorage.run(correlationId, jobProcessor.process);
|
|
45
|
-
|
|
46
|
-
that.deps.Logger.info({
|
|
47
|
-
message: `${jobProcessor.label} success`,
|
|
48
|
-
correlationId,
|
|
49
|
-
metadata: stopwatch.stop(),
|
|
50
|
-
...this.base,
|
|
51
|
-
});
|
|
52
|
-
} catch (error) {
|
|
53
|
-
that.deps.Logger.error({
|
|
54
|
-
message: `${jobProcessor.label} error`,
|
|
55
|
-
correlationId,
|
|
56
|
-
error: formatError(error),
|
|
57
|
-
metadata: { ...stopwatch.stop() },
|
|
58
|
-
...this.base,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
protect(cron: Cron) {
|
|
65
|
-
// biome-ignore lint: lint/complexity/noUselessThisAlias
|
|
66
|
-
const that = this;
|
|
67
|
-
|
|
68
|
-
return async () => that.deps.Logger.info({ message: `${cron.name} overrun`, ...this.base });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -8,20 +8,20 @@ export class PrerequisiteJobs implements prereqs.Prerequisite {
|
|
|
8
8
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
9
9
|
readonly enabled?: boolean = true;
|
|
10
10
|
|
|
11
|
-
private readonly
|
|
11
|
+
private readonly Jobs: MultipleJobsType;
|
|
12
12
|
|
|
13
|
-
constructor(config: prereqs.PrerequisiteConfigType & {
|
|
13
|
+
constructor(config: prereqs.PrerequisiteConfigType & { Jobs: MultipleJobsType }) {
|
|
14
14
|
this.label = config.label;
|
|
15
15
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
16
16
|
|
|
17
|
-
this.
|
|
17
|
+
this.Jobs = config.Jobs;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
21
21
|
const stopwatch = new tools.Stopwatch(clock.now());
|
|
22
22
|
|
|
23
23
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
24
|
-
if (Jobs.areAllRunning(this.
|
|
24
|
+
if (Jobs.areAllRunning(this.Jobs)) return prereqs.Verification.success(stopwatch.stop());
|
|
25
25
|
return prereqs.Verification.failure(stopwatch.stop());
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -70,4 +70,8 @@ export class RemoteFileStorageDiskAdapter implements RemoteFileStoragePort {
|
|
|
70
70
|
async delete(key: tools.ObjectKeyType): Promise<void> {
|
|
71
71
|
await this.deps.FileCleaner.delete(this.resolveKeyToAbsoluteFilePath(key));
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
get root() {
|
|
75
|
+
return this.config.root;
|
|
76
|
+
}
|
|
73
77
|
}
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
RemotePutFromPathResult,
|
|
9
9
|
} from "./remote-file-storage.port";
|
|
10
10
|
|
|
11
|
-
type RemoteFileStorageNoopConfig = { publicBaseUrl?: string };
|
|
11
|
+
type RemoteFileStorageNoopConfig = { root: tools.DirectoryPathAbsoluteType; publicBaseUrl?: string };
|
|
12
12
|
type Dependencies = { Logger: LoggerPort; Clock: ClockPort };
|
|
13
13
|
|
|
14
14
|
export class RemoteFileStorageNoopAdapter implements RemoteFileStoragePort {
|
|
@@ -16,7 +16,7 @@ export class RemoteFileStorageNoopAdapter implements RemoteFileStoragePort {
|
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
18
|
private readonly deps: Dependencies,
|
|
19
|
-
private readonly config
|
|
19
|
+
private readonly config: RemoteFileStorageNoopConfig,
|
|
20
20
|
) {}
|
|
21
21
|
|
|
22
22
|
publicUrl(key: tools.ObjectKeyType): string {
|
|
@@ -66,4 +66,8 @@ export class RemoteFileStorageNoopAdapter implements RemoteFileStoragePort {
|
|
|
66
66
|
...this.base,
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
get root() {
|
|
71
|
+
return this.config.root;
|
|
72
|
+
}
|
|
69
73
|
}
|
|
@@ -24,4 +24,8 @@ export class TemporaryFileAbsoluteAdapter implements TemporaryFilePort {
|
|
|
24
24
|
async cleanup(filename: tools.Filename) {
|
|
25
25
|
await this.deps.FileCleaner.delete(tools.FilePathAbsolute.fromPartsSafe(this.directory, filename));
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
get root() {
|
|
29
|
+
return this.directory;
|
|
30
|
+
}
|
|
27
31
|
}
|