Last active
October 21, 2021 08:58
-
-
Save tatyshev/3fe40b6ce883807125c8ebbad268c517 to your computer and use it in GitHub Desktop.
stalled groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hoursFromNow = hours => moment().subtract(hours, 'hour').toDate() | |
| // Stalled groups table | |
| db.jobgroups.aggregate() | |
| .match({ | |
| 'jobs.1': { $exists: true }, | |
| $or: [ | |
| { | |
| lastPulledAt: { $lte: hoursFromNow(2) }, | |
| }, | |
| { | |
| $and: [{ lastPulledAt: null }, { updatedAt: { $lte: hoursFromNow(6) } }], | |
| } | |
| ] | |
| }) | |
| .unwind("$jobs") | |
| .lookup({ | |
| from: "jobs", | |
| localField: "jobs", | |
| foreignField: "_id", | |
| as: "_job" | |
| }) | |
| .unwind("$_job") | |
| .addFields({ | |
| groupKey: "$key", | |
| jobId: "$_job._id", | |
| jobName: "$_job.name", | |
| jobCreatedAt: "$_job.createdAt", | |
| jobLastEventType: "$_job.lastEventType" | |
| }) | |
| .project({ | |
| groupKey: 1, | |
| jobId: 1, | |
| jobName: 1, | |
| jobCreatedAt: 1, | |
| jobLastEventType: 1 | |
| }) | |
| .sort({ "_job.createdAt": -1 }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
можно так