-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DocumentDB support #2
base: master
Are you sure you want to change the base?
Changes from 5 commits
d0ff49a
b936d3b
9e14bd6
d90ea5f
32b3687
a76b9e5
53e2739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ module.exports = function (agenda, options) { | |
if (job) { | ||
preMatch.name = job; | ||
} | ||
|
||
if (options.query && options.property) { | ||
if (options.isObjectId) { | ||
preMatch[options.property] = ObjectId(options.query); | ||
|
@@ -48,6 +48,7 @@ module.exports = function (agenda, options) { | |
} else { | ||
preMatch[options.property] = { $regex: options.query, $options: "i" }; | ||
} | ||
|
||
} | ||
|
||
const postMatch = {}; | ||
|
@@ -56,69 +57,117 @@ module.exports = function (agenda, options) { | |
} | ||
|
||
const collection = agenda._collection.collection || agenda._collection; | ||
return collection | ||
.aggregate([ | ||
{ $match: preMatch }, | ||
{ | ||
$sort: { | ||
nextRunAt: -1, | ||
lastRunAt: -1, | ||
lastFinishedAt: -1, | ||
}, | ||
const aggregateQuery = [ | ||
{ $match: preMatch }, | ||
{ | ||
$sort: { | ||
nextRunAt: -1, | ||
lastRunAt: -1, | ||
lastFinishedAt: -1, | ||
}, | ||
{ | ||
$project: { | ||
job: "$$ROOT", | ||
_id: "$$ROOT._id", | ||
running: { | ||
$and: ["$lastRunAt", { $gt: ["$lastRunAt", "$lastFinishedAt"] }], | ||
}, | ||
scheduled: { | ||
$and: ["$nextRunAt", { $gte: ["$nextRunAt", new Date()] }], | ||
}, | ||
queued: { | ||
$and: [ | ||
"$nextRunAt", | ||
{ $gte: [new Date(), "$nextRunAt"] }, | ||
{ $gte: ["$nextRunAt", "$lastFinishedAt"] }, | ||
], | ||
}, | ||
completed: { | ||
$and: [ | ||
"$lastFinishedAt", | ||
{ $gt: ["$lastFinishedAt", "$failedAt"] }, | ||
], | ||
}, | ||
failed: { | ||
$and: [ | ||
"$lastFinishedAt", | ||
"$failedAt", | ||
{ $eq: ["$lastFinishedAt", "$failedAt"] }, | ||
], | ||
}, | ||
repeating: { | ||
$and: ["$repeatInterval", { $ne: ["$repeatInterval", null] }], | ||
}, | ||
}, | ||
{ | ||
$project: { | ||
job: "$$ROOT", | ||
_id: "$$ROOT._id", | ||
running: { | ||
$and: ["$lastRunAt", { $gt: ["$lastRunAt", "$lastFinishedAt"] }], | ||
}, | ||
scheduled: { | ||
$and: ["$nextRunAt", { $gte: ["$nextRunAt", new Date()] }], | ||
}, | ||
queued: { | ||
$and: [ | ||
"$nextRunAt", | ||
{ $gte: [new Date(), "$nextRunAt"] }, | ||
{ $gte: ["$nextRunAt", "$lastFinishedAt"] }, | ||
], | ||
}, | ||
completed: { | ||
$and: [ | ||
"$lastFinishedAt", | ||
{ $gt: ["$lastFinishedAt", "$failedAt"] }, | ||
], | ||
}, | ||
failed: { | ||
$and: [ | ||
"$lastFinishedAt", | ||
"$failedAt", | ||
{ $eq: ["$lastFinishedAt", "$failedAt"] }, | ||
], | ||
}, | ||
repeating: { | ||
$and: ["$repeatInterval", { $ne: ["$repeatInterval", null] }], | ||
}, | ||
}, | ||
{ $match: postMatch }, | ||
{ | ||
$facet: { | ||
pages: [ | ||
{ $count: "totalMatchs" }, | ||
{ | ||
$project: { | ||
totalPages: { | ||
$ceil: { $divide: ["$totalMatchs", options.limit] }, | ||
}, | ||
}, | ||
{ $match: postMatch } | ||
|
||
|
||
]; | ||
const standardMongoDBQuery = [ | ||
|
||
{ | ||
$facet: { | ||
pages: [ | ||
{ $count: "totalMatchs" }, | ||
{ | ||
$project: { | ||
totalPages: { | ||
$ceil: { $divide: ["$totalMatchs", options.limit] }, | ||
}, | ||
}, | ||
], | ||
filtered: [{ $skip: options.skip }, { $limit: options.limit }], | ||
}, | ||
], | ||
filtered: [{ $skip: options.skip }, { $limit: options.limit }], | ||
} | ||
} | ||
] | ||
const awsDocumentDBQuery = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we explain the limitation with this query, for some reason we're trying to run a query, failing and then trying to run another query that's docDB compatible. |
||
{ | ||
$group: { | ||
_id: null, | ||
totalMatchs: { | ||
$sum: 1 | ||
}, | ||
}, | ||
]) | ||
.toArray(); | ||
results: { | ||
$push: '$$ROOT' | ||
} | ||
} | ||
}, | ||
{ | ||
$project: { | ||
pages: [{totalPages: '$totalMatchs'}], | ||
filtered: { | ||
$slice: [ | ||
'$results', | ||
options.skip, | ||
options.limit | ||
] | ||
} | ||
} | ||
} | ||
] | ||
return collection | ||
.aggregate([...aggregateQuery,...standardMongoDBQuery]) | ||
.toArray() | ||
.then((result) => { | ||
return result; | ||
}) | ||
.catch((error) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is gross, it's an extra round trip to AWS every time we run this query, and I'm not sure amazon will thank us for that. Can we just make this a configuration option (or somehow smartly detect the version of Mongo, rather than this awful thing?) We're not even looking at the error response to detect why it failed 😮💨 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hoping to avoid us maintaining our own code until upstream implements this properly. This works and it's only doing this query every so and so seconds. I hardly think AWS will notice. We can reimplement this patch but I'm going to postpone it after staging migration, if ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify the reason for not spending engineering time now: when upstream implements documentdb support, we're going to want to use that implementation anyway, not whatever we came up with. As such I'd avoid making anything fancy at this stage. Given we only need documentdb support, I could simplify the pr - but that carries the issue if the upstream patch gets new commits, we'll be in a merge conflict against that. |
||
return collection.aggregate([...aggregateQuery,...awsDocumentDBQuery]) | ||
.toArray() | ||
.then((result) => { | ||
result[0].pages[0].totalPages = Math.ceil(result[0].pages[0].totalPages / options.limit); | ||
return result; | ||
}) | ||
.catch((error) => { | ||
return error; | ||
}) | ||
|
||
|
||
}); | ||
|
||
}; | ||
|
||
const getOverview = async () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const popupmessage = Vue.component("popup-message", { | ||
props: ["job", "deletec", "requeuec", "createc"], | ||
template: ` | ||
<div v-if="deletec" class="alert alert-success popupmessage">Job Deleted successfull</div> | ||
<div v-else-if="requeuec" class="alert alert-success popupmessage">Job Requeue successfull</div> | ||
<div v-else-if="createc" class="alert alert-success popupmessage">Job Created successfull</div> | ||
<div v-if="deletec" class="alert alert-success popupmessage">Job Deleted successful</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Job Deleted successfully, surely? |
||
<div v-else-if="requeuec" class="alert alert-success popupmessage">Job Requeue successful</div> | ||
<div v-else-if="createc" class="alert alert-success popupmessage">Job Created successful</div> | ||
`, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whitespace changes make this difficult to review