@trafficgroup/knex-rel 0.1.18 → 0.1.20
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.
|
@@ -16,6 +16,16 @@ export declare class BatchDAO implements IBaseDAO<IBatch> {
|
|
|
16
16
|
* Update batch progress
|
|
17
17
|
*/
|
|
18
18
|
updateProgress(id: number, completedVideos: number, failedVideos: number): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Atomically increment completedVideos counter with row-level locking.
|
|
21
|
+
* Returns the updated batch with fresh counters.
|
|
22
|
+
*/
|
|
23
|
+
incrementCompleted(id: number): Promise<IBatch>;
|
|
24
|
+
/**
|
|
25
|
+
* Atomically increment failedVideos counter with row-level locking.
|
|
26
|
+
* Returns the updated batch with fresh counters.
|
|
27
|
+
*/
|
|
28
|
+
incrementFailed(id: number): Promise<IBatch>;
|
|
19
29
|
/**
|
|
20
30
|
* Mark batch as completed
|
|
21
31
|
*/
|
|
@@ -108,6 +108,44 @@ class BatchDAO {
|
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Atomically increment completedVideos counter with row-level locking.
|
|
113
|
+
* Returns the updated batch with fresh counters.
|
|
114
|
+
*/
|
|
115
|
+
incrementCompleted(id) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return this._knex.transaction((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const batch = yield trx("video_batch").where({ id }).forUpdate().first();
|
|
119
|
+
if (!batch)
|
|
120
|
+
throw new Error(`Batch ${id} not found`);
|
|
121
|
+
const newCompleted = batch.completedVideos + 1;
|
|
122
|
+
yield trx("video_batch").where({ id }).update({
|
|
123
|
+
completedVideos: newCompleted,
|
|
124
|
+
updated_at: trx.fn.now(),
|
|
125
|
+
});
|
|
126
|
+
return Object.assign(Object.assign({}, batch), { completedVideos: newCompleted });
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Atomically increment failedVideos counter with row-level locking.
|
|
132
|
+
* Returns the updated batch with fresh counters.
|
|
133
|
+
*/
|
|
134
|
+
incrementFailed(id) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
return this._knex.transaction((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const batch = yield trx("video_batch").where({ id }).forUpdate().first();
|
|
138
|
+
if (!batch)
|
|
139
|
+
throw new Error(`Batch ${id} not found`);
|
|
140
|
+
const newFailed = batch.failedVideos + 1;
|
|
141
|
+
yield trx("video_batch").where({ id }).update({
|
|
142
|
+
failedVideos: newFailed,
|
|
143
|
+
updated_at: trx.fn.now(),
|
|
144
|
+
});
|
|
145
|
+
return Object.assign(Object.assign({}, batch), { failedVideos: newFailed });
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
111
149
|
/**
|
|
112
150
|
* Mark batch as completed
|
|
113
151
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.dao.js","sourceRoot":"","sources":["../../../src/dao/batch/batch.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"batch.dao.js","sourceRoot":"","sources":["../../../src/dao/batch/batch.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA4JpE,CAAC;IA1JO,MAAM,CAAC,IAAY;;YACvB,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;iBACnD,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,O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DAO<IBatch> {
|
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Atomically increment completedVideos counter with row-level locking.
|
|
104
|
+
* Returns the updated batch with fresh counters.
|
|
105
|
+
*/
|
|
106
|
+
async incrementCompleted(id: number): Promise<IBatch> {
|
|
107
|
+
return this._knex.transaction(async (trx) => {
|
|
108
|
+
const batch = await trx("video_batch").where({ id }).forUpdate().first();
|
|
109
|
+
|
|
110
|
+
if (!batch) throw new Error(`Batch ${id} not found`);
|
|
111
|
+
|
|
112
|
+
const newCompleted = batch.completedVideos + 1;
|
|
113
|
+
|
|
114
|
+
await trx("video_batch").where({ id }).update({
|
|
115
|
+
completedVideos: newCompleted,
|
|
116
|
+
updated_at: trx.fn.now(),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return { ...batch, completedVideos: newCompleted };
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Atomically increment failedVideos counter with row-level locking.
|
|
125
|
+
* Returns the updated batch with fresh counters.
|
|
126
|
+
*/
|
|
127
|
+
async incrementFailed(id: number): Promise<IBatch> {
|
|
128
|
+
return this._knex.transaction(async (trx) => {
|
|
129
|
+
const batch = await trx("video_batch").where({ id }).forUpdate().first();
|
|
130
|
+
|
|
131
|
+
if (!batch) throw new Error(`Batch ${id} not found`);
|
|
132
|
+
|
|
133
|
+
const newFailed = batch.failedVideos + 1;
|
|
134
|
+
|
|
135
|
+
await trx("video_batch").where({ id }).update({
|
|
136
|
+
failedVideos: newFailed,
|
|
137
|
+
updated_at: trx.fn.now(),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return { ...batch, failedVideos: newFailed };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
102
144
|
/**
|
|
103
145
|
* Mark batch as completed
|
|
104
146
|
*/
|