powr-sdk-api 4.3.10 → 4.3.11
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 +55 -0
- package/dist/routes/tasks.js +26 -0
- package/package.json +1 -1
package/dist/managers/tasks.js
CHANGED
|
@@ -602,6 +602,61 @@ class TasksManager {
|
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
|
|
605
|
+
// Get execution history for a task
|
|
606
|
+
async getTaskExecutions(taskId, userId, projectId, isAdmin = false) {
|
|
607
|
+
try {
|
|
608
|
+
const db = await getDb();
|
|
609
|
+
|
|
610
|
+
// First verify the task exists and user has access
|
|
611
|
+
let taskQuery = {
|
|
612
|
+
_id: new ObjectId(taskId)
|
|
613
|
+
};
|
|
614
|
+
if (isAdmin) {
|
|
615
|
+
taskQuery.projectId = projectId;
|
|
616
|
+
} else {
|
|
617
|
+
taskQuery.userId = userId;
|
|
618
|
+
taskQuery.projectId = projectId;
|
|
619
|
+
}
|
|
620
|
+
const task = await db.collection("tasks").findOne(taskQuery);
|
|
621
|
+
if (!task) {
|
|
622
|
+
return {
|
|
623
|
+
success: false,
|
|
624
|
+
message: "Task not found"
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Get execution history based on task type
|
|
629
|
+
let executions = [];
|
|
630
|
+
if (task.type === 'workflow') {
|
|
631
|
+
// Get workflow executions
|
|
632
|
+
executions = await db.collection("workflow_executions").find({
|
|
633
|
+
workflowId: new ObjectId(taskId)
|
|
634
|
+
}).sort({
|
|
635
|
+
executedAt: -1
|
|
636
|
+
}).limit(50) // Limit to last 50 executions
|
|
637
|
+
.toArray();
|
|
638
|
+
} else {
|
|
639
|
+
// Get task executions
|
|
640
|
+
executions = await db.collection("task_executions").find({
|
|
641
|
+
taskId: new ObjectId(taskId)
|
|
642
|
+
}).sort({
|
|
643
|
+
executedAt: -1
|
|
644
|
+
}).limit(50) // Limit to last 50 executions
|
|
645
|
+
.toArray();
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
success: true,
|
|
649
|
+
executions
|
|
650
|
+
};
|
|
651
|
+
} catch (error) {
|
|
652
|
+
console.error("❌ Failed to get task executions:", error);
|
|
653
|
+
return {
|
|
654
|
+
success: false,
|
|
655
|
+
message: error.message
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
605
660
|
// Check if a string is a valid timestamp
|
|
606
661
|
isTimestamp(value) {
|
|
607
662
|
try {
|
package/dist/routes/tasks.js
CHANGED
|
@@ -275,6 +275,32 @@ router.delete("/:taskId", async (req, res) => {
|
|
|
275
275
|
}
|
|
276
276
|
});
|
|
277
277
|
|
|
278
|
+
// GET /tasks/:taskId/executions - Get execution history for a task
|
|
279
|
+
router.get("/:taskId/executions", async (req, res) => {
|
|
280
|
+
try {
|
|
281
|
+
const taskId = req.params.taskId;
|
|
282
|
+
const isAdmin = req.user.access === 100;
|
|
283
|
+
const result = await tasksManager.getTaskExecutions(taskId, req.user.powrId, req.projectId, isAdmin);
|
|
284
|
+
if (result.success) {
|
|
285
|
+
res.json({
|
|
286
|
+
success: true,
|
|
287
|
+
executions: result.executions
|
|
288
|
+
});
|
|
289
|
+
} else {
|
|
290
|
+
res.status(400).json({
|
|
291
|
+
success: false,
|
|
292
|
+
message: result.message
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.error("❌ Error retrieving task executions:", error);
|
|
297
|
+
res.status(500).json({
|
|
298
|
+
success: false,
|
|
299
|
+
message: "Failed to retrieve task executions"
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
278
304
|
// POST /tasks/execute-scheduled - Execute all scheduled tasks (called by Atlas)
|
|
279
305
|
router.post("/execute-scheduled", async (req, res) => {
|
|
280
306
|
try {
|