Skip to content

Instantly share code, notes, and snippets.

@tatyshev
Last active October 21, 2021 08:58
Show Gist options
  • Select an option

  • Save tatyshev/3fe40b6ce883807125c8ebbad268c517 to your computer and use it in GitHub Desktop.

Select an option

Save tatyshev/3fe40b6ce883807125c8ebbad268c517 to your computer and use it in GitHub Desktop.
stalled groups
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 })
@girokon
Copy link

girokon commented Oct 21, 2021

const hoursFromNow = hours => moment().subtract(hours, 'hour').toDate()

можно так

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment