powr-sdk-api 4.3.0 → 4.3.2
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/managers/tasks.js +14 -11
- package/package.json +1 -1
package/dist/managers/tasks.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
const {
|
|
4
4
|
getDb
|
|
5
5
|
} = require("../services/mongo");
|
|
6
|
+
const {
|
|
7
|
+
ObjectId
|
|
8
|
+
} = require("mongodb");
|
|
6
9
|
class ScheduledTasksManager {
|
|
7
10
|
// Create a new scheduled task
|
|
8
11
|
async createTask(taskData) {
|
|
@@ -91,7 +94,7 @@ class ScheduledTasksManager {
|
|
|
91
94
|
|
|
92
95
|
// Build query based on user role
|
|
93
96
|
let query = {
|
|
94
|
-
|
|
97
|
+
_id: new ObjectId(taskId)
|
|
95
98
|
};
|
|
96
99
|
if (isAdmin) {
|
|
97
100
|
// Admin can access any task in the project
|
|
@@ -128,7 +131,7 @@ class ScheduledTasksManager {
|
|
|
128
131
|
|
|
129
132
|
// Build query based on user role
|
|
130
133
|
let query = {
|
|
131
|
-
|
|
134
|
+
_id: new ObjectId(taskId)
|
|
132
135
|
};
|
|
133
136
|
if (isAdmin) {
|
|
134
137
|
// Admin can update any task in the project
|
|
@@ -180,7 +183,7 @@ class ScheduledTasksManager {
|
|
|
180
183
|
|
|
181
184
|
// Build query based on user role
|
|
182
185
|
let query = {
|
|
183
|
-
|
|
186
|
+
_id: new ObjectId(taskId)
|
|
184
187
|
};
|
|
185
188
|
if (isAdmin) {
|
|
186
189
|
// Admin can delete any task in the project
|
|
@@ -225,7 +228,7 @@ class ScheduledTasksManager {
|
|
|
225
228
|
|
|
226
229
|
// Build query based on user role
|
|
227
230
|
let query = {
|
|
228
|
-
|
|
231
|
+
_id: new ObjectId(taskId)
|
|
229
232
|
};
|
|
230
233
|
if (isAdmin) {
|
|
231
234
|
// Admin can toggle any task in the project
|
|
@@ -271,7 +274,7 @@ class ScheduledTasksManager {
|
|
|
271
274
|
|
|
272
275
|
// Build query based on user role
|
|
273
276
|
let query = {
|
|
274
|
-
|
|
277
|
+
_id: new ObjectId(taskId)
|
|
275
278
|
};
|
|
276
279
|
if (isAdmin) {
|
|
277
280
|
// Admin can execute any task in the project
|
|
@@ -319,7 +322,7 @@ class ScheduledTasksManager {
|
|
|
319
322
|
const tasks = await db.collection("tasks").find(query).toArray();
|
|
320
323
|
for (const task of tasks) {
|
|
321
324
|
try {
|
|
322
|
-
console.log(`⏰ Executing: ${task.name} (${task.
|
|
325
|
+
console.log(`⏰ Executing: ${task.name} (${task._id}) for project ${task.projectId}`);
|
|
323
326
|
|
|
324
327
|
// Execute the task directly (we already have the task data)
|
|
325
328
|
const result = await this.executeTaskAction(task);
|
|
@@ -329,20 +332,20 @@ class ScheduledTasksManager {
|
|
|
329
332
|
if (!task.scheduledFor || this.isTimestamp(task.scheduledFor)) {
|
|
330
333
|
// For immediate and one-time tasks, deactivate after execution
|
|
331
334
|
updateData.isActive = false;
|
|
332
|
-
console.log(`✅ Task ${task.
|
|
335
|
+
console.log(`✅ Task ${task._id} completed and deactivated`);
|
|
333
336
|
} else if (this.isCronExpression(task.scheduledFor)) {
|
|
334
337
|
// For recurring tasks, calculate next run time
|
|
335
338
|
updateData.nextRun = this.getNextRunTime(task.scheduledFor);
|
|
336
|
-
console.log(`📅 Updated next run time for task ${task.
|
|
339
|
+
console.log(`📅 Updated next run time for task ${task._id}: ${updateData.nextRun}`);
|
|
337
340
|
}
|
|
338
341
|
await db.collection("tasks").updateOne({
|
|
339
|
-
|
|
342
|
+
_id: task._id
|
|
340
343
|
}, {
|
|
341
344
|
$set: updateData
|
|
342
345
|
});
|
|
343
|
-
console.log(`✅ Task ${task.
|
|
346
|
+
console.log(`✅ Task ${task._id} completed:`, result.success ? 'SUCCESS' : 'FAILED');
|
|
344
347
|
} catch (error) {
|
|
345
|
-
console.error(`❌ Task ${task.
|
|
348
|
+
console.error(`❌ Task ${task._id} failed:`, error.message);
|
|
346
349
|
}
|
|
347
350
|
}
|
|
348
351
|
return {
|