@punks/backend-entity-manager 0.0.271 → 0.0.273
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/cjs/index.js +14 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/operations.d.ts +3 -3
- package/dist/cjs/types/platforms/nest/extensions/jobs/abstractions/repository.d.ts +8 -8
- package/dist/cjs/types/platforms/nest/services/operations/operation-lock.repository.d.ts +3 -3
- package/dist/esm/index.js +14 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/operations.d.ts +3 -3
- package/dist/esm/types/platforms/nest/extensions/jobs/abstractions/repository.d.ts +8 -8
- package/dist/esm/types/platforms/nest/services/operations/operation-lock.repository.d.ts +3 -3
- package/dist/index.d.ts +14 -14
- package/package.json +1 -4
package/dist/cjs/index.js
CHANGED
|
@@ -21941,14 +21941,14 @@ exports.OperationLockService = OperationLockService_1 = class OperationLockServi
|
|
|
21941
21941
|
this.operations = operations;
|
|
21942
21942
|
this.logger = backendCore.Log.getLogger(OperationLockService_1.name);
|
|
21943
21943
|
this.executeExclusive = async (input) => {
|
|
21944
|
-
const lock = await this.operations.
|
|
21944
|
+
const lock = await this.operations.acquireLock({
|
|
21945
21945
|
lockUid: input.lockUid,
|
|
21946
21946
|
requestedBy: input.requestedBy,
|
|
21947
21947
|
});
|
|
21948
21948
|
if (!lock.available &&
|
|
21949
21949
|
input.lockTimeout &&
|
|
21950
21950
|
this.isLockExpired(lock.lockItem, new Date(), input.lockTimeout)) {
|
|
21951
|
-
await this.operations.
|
|
21951
|
+
await this.operations.releaseLock({
|
|
21952
21952
|
lockUid: input.lockUid,
|
|
21953
21953
|
});
|
|
21954
21954
|
return await this.executeExclusive(input);
|
|
@@ -21966,7 +21966,7 @@ exports.OperationLockService = OperationLockService_1 = class OperationLockServi
|
|
|
21966
21966
|
};
|
|
21967
21967
|
}
|
|
21968
21968
|
finally {
|
|
21969
|
-
await this.operations.
|
|
21969
|
+
await this.operations.releaseLock({
|
|
21970
21970
|
lockUid: input.lockUid,
|
|
21971
21971
|
});
|
|
21972
21972
|
}
|
|
@@ -21990,12 +21990,12 @@ exports.TypeormOperationLockRepository = class TypeormOperationLockRepository {
|
|
|
21990
21990
|
this.repo = repo;
|
|
21991
21991
|
this.entityClass = entityClass;
|
|
21992
21992
|
// todo: fix typing (and remove as any)
|
|
21993
|
-
this.
|
|
21993
|
+
this.getLock = async (lockUid) => (await this.repo.findOne({
|
|
21994
21994
|
where: {
|
|
21995
21995
|
uid: lockUid,
|
|
21996
21996
|
},
|
|
21997
21997
|
})) ?? undefined;
|
|
21998
|
-
this.
|
|
21998
|
+
this.acquireLock = async (input) => {
|
|
21999
21999
|
return await this.repo.manager.transaction(async (manager) => {
|
|
22000
22000
|
const currentLock = await manager.findOne(this.entityClass, {
|
|
22001
22001
|
where: [
|
|
@@ -22022,7 +22022,7 @@ exports.TypeormOperationLockRepository = class TypeormOperationLockRepository {
|
|
|
22022
22022
|
};
|
|
22023
22023
|
});
|
|
22024
22024
|
};
|
|
22025
|
-
this.
|
|
22025
|
+
this.releaseLock = async (input) => {
|
|
22026
22026
|
const result = await this.repo.delete({
|
|
22027
22027
|
uid: input.lockUid,
|
|
22028
22028
|
});
|
|
@@ -33701,7 +33701,7 @@ let JobsSchedulerTask = JobsSchedulerTask_1 = class JobsSchedulerTask {
|
|
|
33701
33701
|
}
|
|
33702
33702
|
async run() {
|
|
33703
33703
|
this.logger.info(`JobsSchedulerTask -> run start`);
|
|
33704
|
-
const jobs = await this.jobDefinitions.
|
|
33704
|
+
const jobs = await this.jobDefinitions.getAllDefinitions();
|
|
33705
33705
|
for (const job of jobs) {
|
|
33706
33706
|
await this.evaluateJob(job);
|
|
33707
33707
|
}
|
|
@@ -33776,7 +33776,7 @@ let JobsMonitorTask = JobsMonitorTask_1 = class JobsMonitorTask {
|
|
|
33776
33776
|
async monitorInstance(instance) {
|
|
33777
33777
|
try {
|
|
33778
33778
|
this.logger.info(`JobsMonitorTask -> evaluating job ${instance.id}`);
|
|
33779
|
-
const job = await this.jobDefinitions.
|
|
33779
|
+
const job = await this.jobDefinitions.getDefinitionByUid(instance.jobUid);
|
|
33780
33780
|
if (!job) {
|
|
33781
33781
|
throw new Error(`Job definition not found -> ${instance.jobUid}`);
|
|
33782
33782
|
}
|
|
@@ -33918,7 +33918,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
|
|
|
33918
33918
|
const instanceId = backendCore.newUuid();
|
|
33919
33919
|
try {
|
|
33920
33920
|
this.logger.info(`JOB DISPATCH -> dispatching started job ${job.uid} -> ${instanceId}`);
|
|
33921
|
-
await this.instances.
|
|
33921
|
+
await this.instances.appendInstance(job, {
|
|
33922
33922
|
id: instanceId,
|
|
33923
33923
|
runType,
|
|
33924
33924
|
scheduleUid: schedule.uid,
|
|
@@ -33929,13 +33929,13 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
|
|
|
33929
33929
|
schedule,
|
|
33930
33930
|
instanceId,
|
|
33931
33931
|
});
|
|
33932
|
-
await this.instances.
|
|
33932
|
+
await this.instances.updateInstance(instanceId, {
|
|
33933
33933
|
status: exports.JobStatus.Ready,
|
|
33934
33934
|
});
|
|
33935
33935
|
this.logger.info(`JOB DISPATCH -> dispatching completed job ${job.uid} -> ${instanceId}`);
|
|
33936
33936
|
}
|
|
33937
33937
|
catch (e) {
|
|
33938
|
-
await this.instances.
|
|
33938
|
+
await this.instances.updateInstance(instanceId, {
|
|
33939
33939
|
status: exports.JobStatus.InitializationError,
|
|
33940
33940
|
error: `${e.message} -> \n\n ${e.stack}`,
|
|
33941
33941
|
});
|
|
@@ -33981,7 +33981,7 @@ let JobStatusMonitorHandler = JobStatusMonitorHandler_1 = class JobStatusMonitor
|
|
|
33981
33981
|
const { input: { job, instanceId }, } = command;
|
|
33982
33982
|
try {
|
|
33983
33983
|
this.logger.info(`JOB STATUS UPDATE -> dispatching started job ${job.uid} -> ${instanceId}`);
|
|
33984
|
-
const current = await this.instances.
|
|
33984
|
+
const current = await this.instances.getById(instanceId);
|
|
33985
33985
|
if (!current) {
|
|
33986
33986
|
throw new Error(`Job instance ${instanceId} not found`);
|
|
33987
33987
|
}
|
|
@@ -33997,7 +33997,7 @@ let JobStatusMonitorHandler = JobStatusMonitorHandler_1 = class JobStatusMonitor
|
|
|
33997
33997
|
this.logger.info(`JOB STATUS UPDATE -> status unchanged ${job.uid} -> ${instanceId}`);
|
|
33998
33998
|
return;
|
|
33999
33999
|
}
|
|
34000
|
-
await this.instances.
|
|
34000
|
+
await this.instances.updateInstance(instanceId, {
|
|
34001
34001
|
status: newStatus,
|
|
34002
34002
|
endTime: !current.endTime && isJobEnded(newStatus) ? new Date() : undefined,
|
|
34003
34003
|
startTime: !current.startTime && isJobStarted(newStatus)
|
|
@@ -34045,7 +34045,7 @@ let JobDefinitionUpdateHandler = JobDefinitionUpdateHandler_1 = class JobDefinit
|
|
|
34045
34045
|
await this.executor.upsertJobDefinition({
|
|
34046
34046
|
definition: job,
|
|
34047
34047
|
});
|
|
34048
|
-
await this.definitions.
|
|
34048
|
+
await this.definitions.ensureDefinition(job);
|
|
34049
34049
|
this.logger.info(`JOB DEFINITION UPDATE -> status update completed job ${job.uid}`);
|
|
34050
34050
|
}
|
|
34051
34051
|
};
|