{"action":"created","issue":{"url":"https://api.github.com/repos/rschmukler/agenda/issues/370","repository_url":"https://api.github.com/repos/rschmukler/agenda","labels_url":"https://api.github.com/repos/rschmukler/agenda/issues/370/labels{/name}","comments_url":"https://api.github.com/repos/rschmukler/agenda/issues/370/comments","events_url":"https://api.github.com/repos/rschmukler/agenda/issues/370/events","html_url":"https://github.com/rschmukler/agenda/issues/370","id":179939115,"number":370,"title":"[URGENT] agenda jobs causing mongodb to keep query and update","user":{"login":"shengrong1987","id":6395496,"avatar_url":"https://avatars.githubusercontent.com/u/6395496?v=3","gravatar_id":"","url":"https://api.github.com/users/shengrong1987","html_url":"https://github.com/shengrong1987","followers_url":"https://api.github.com/users/shengrong1987/followers","following_url":"https://api.github.com/users/shengrong1987/following{/other_user}","gists_url":"https://api.github.com/users/shengrong1987/gists{/gist_id}","starred_url":"https://api.github.com/users/shengrong1987/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shengrong1987/subscriptions","organizations_url":"https://api.github.com/users/shengrong1987/orgs","repos_url":"https://api.github.com/users/shengrong1987/repos","events_url":"https://api.github.com/users/shengrong1987/events{/privacy}","received_events_url":"https://api.github.com/users/shengrong1987/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-09-29T02:38:44Z","updated_at":"2016-11-21T05:44:07Z","closed_at":null,"body":"I have a total of 6 jobs created with agenda. Two of them, \"MealJob\" and \"OrderJob\" are looped every 30 seconds, other 4 jobs are one time job( all with \"run at\" equals to \"null\" ) in database.\n\nEvery time my server is up for 4 to 5 hours on ec2( node app run with mongodb), the server stops responding. Upon checking, I found there are infinite agenda job-query and job-update in the mongodb log that causing high CPU usage.\n\nHere's the log I found: \n\n`2016-09-29T00:33:36.968+0000 [conn28] query sails.dish_dishes_dish__meal_dishes query: { meal_dishes: ObjectId('57e5ceff92bdc8bf0e98187c') } planSummary: COLLSCAN ntoreturn:1000 ntoskip:0 nscanned:34 nscannedObjects:34 keyUpdates:0 numYields:0 locks(micros) r:129299 nreturned:4 reslen:328 120ms\n\n2016-09-29T00:33:39.775+0000 [conn31] query sails.dish query: { _id: { $in: [ ObjectId('57e5c5dc92bdc8bf0e981853'), ObjectId('57e59f0a92bdc8bf0e98182e'), ObjectId('57e5c60792bdc8bf0e981854'), ObjectId('57e59e7e92bdc8bf0e98182c') ] } } planSummary: IXSCAN { _id: 1 } ntoreturn:1000 ntoskip:0 nscanned:6 nscannedObjects:4 keyUpdates:0 numYields:5 locks(micros) r:4080973 nreturned:4 reslen:1596 2359ms\n\n2016-09-29T00:33:40.735+0000 [conn37] query jobs.agendaJobs query: { query: { $or: [ { name: \"MealJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109227267) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109227267) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $lte: new Date(1475109207273) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt:$\n\n2016-09-29T00:33:42.755+0000 [conn37] update jobs.agendaJobs query: { _id: ObjectId('57ec2ca90ab9be9605050a7d'), $or: [ { name: \"MealJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109227267) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109227267) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $lte: new Date(1475109207273) }, disabled: { $ne: true } } ] } update: { $set: { lockedAt: new Date(1475109217273) } } nscanned:1 nscannedObjects:1 nMatched:1 nModified:1 keyUpdates:2 numYields:0 1423ms\n\n2016-09-29T00:33:43.764+0000 [conn37] query jobs.agendaJobs query: { _id: ObjectId('57ec2ca90ab9be9605050a7d') } planSummary: IDHACK ntoreturn:1 ntoskip:0 nscanned:1 nscannedObjects:1 idhack:1 keyUpdates:0 numYields:0 nreturned:1 reslen:257 352ms\n\n2016-09-29T00:33:44.226+0000 [conn37] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"MealJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109227267) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109227267) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $lte: new Date(1475109207273) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109217273) } } } keyUpdates:0 numYields:0 locks(micros) w:5739188 reslen:390 5801ms\n\n2016-09-29T00:33:45.524+0000 [conn38] query jobs.agendaJobs query: { query: { $or: [ { name: \"MealScheduleEndJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109227874) }, disabled: { $ne: true } }, { name: \"MealScheduleEndJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109227874) }, disabled: { $ne: true } }, { name: \"MealScheduleEndJob\", lockedAt: { $lte: new Date(1475109207926) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, prio$\n\n2016-09-29T00:33:45.924+0000 [conn38] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"MealScheduleEndJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109227874) }, disabled: { $ne: true } }, { name: \"MealScheduleEndJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109227874) }, disabled: { $ne: true } }, { name: \"MealScheduleEndJob\", lockedAt: { $lte: new Date(1475109207926) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109217926) } } } keyUpdates:0 numYields:0 locks(micros) w:161662$\n\n2016-09-29T00:33:47.170+0000 [conn35] query jobs.agendaJobs query: { query: { $or: [ { name: \"OrderDeliveringReminderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109230155) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109230155) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $lte: new Date(1475109210196) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }$\n\n2016-09-29T00:33:47.554+0000 [conn35] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"OrderDeliveringReminderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109230155) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109230155) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $lte: new Date(1475109210196) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109220196) } } } keyUpdates:0 numYields:$\n\n2016-09-29T00:33:48.776+0000 [conn37] query jobs.agendaJobs query: { query: { $or: [ { name: \"OrderPickupReminderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109231221) }, disabled: { $ne: true } }, { name: \"OrderPickupReminderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109231221) }, disabled: { $ne: true } }, { name: \"OrderPickupReminderJob\", lockedAt: { $lte: new Date(1475109211240) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { n$\n\n2016-09-29T00:33:49.224+0000 [conn37] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"OrderPickupReminderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109231221) }, disabled: { $ne: true } }, { name: \"OrderPickupReminderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109231221) }, disabled: { $ne: true } }, { name: \"OrderPickupReminderJob\", lockedAt: { $lte: new Date(1475109211240) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109221240) } } } keyUpdates:0 numYields:0 locks(micr$\n\n2016-09-29T00:33:50.860+0000 [conn36] query jobs.agendaJobs query: { query: { $or: [ { name: \"OrderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109230655) }, disabled: { $ne: true } }, { name: \"OrderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109230655) }, disabled: { $ne: true } }, { name: \"OrderJob\", lockedAt: { $lte: new Date(1475109210675) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRun$\n\n2016-09-29T00:33:52.665+0000 [conn36] update jobs.agendaJobs query: { _id: ObjectId('57ec2ca90ab9be9605050a7e'), $or: [ { name: \"OrderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109230655) }, disabled: { $ne: true } }, { name: \"OrderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109230655) }, disabled: { $ne: true } }, { name: \"OrderJob\", lockedAt: { $lte: new Date(1475109210675) }, disabled: { $ne: true } } ] } update: { $set: { lockedAt: new Date(1475109220675) } } nscanned:1 nscannedObjects:1 nMatched:1 nModified:1 keyUpdates:2 numYields:0 1295ms\n\n2016-09-29T00:33:53.252+0000 [conn36] command jobs.$cmd command: getLastError { getlasterror: 1 } ntoreturn:1 keyUpdates:0 numYields:0 reslen:112 164ms\n\n2016-09-29T00:33:53.876+0000 [conn36] query jobs.agendaJobs query: { _id: ObjectId('57ec2ca90ab9be9605050a7e') } planSummary: IDHACK ntoreturn:1 ntoskip:0 nscanned:1 nscannedObjects:1 idhack:1 keyUpdates:0 numYields:0 nreturned:1 reslen:258 286ms\n\n2016-09-29T00:33:54.337+0000 [conn36] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"OrderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109230655) }, disabled: { $ne: true } }, { name: \"OrderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109230655) }, disabled: { $ne: true } }, { name: \"OrderJob\", lockedAt: { $lte: new Date(1475109210675) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109220675) } } } keyUpdates:0 numYields:0 locks(micros) w:5013578 reslen:391 5101ms\n\n2016-09-29T00:33:55.870+0000 [conn38] query jobs.agendaJobs query: { query: { $or: [ { name: \"MealJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109238551) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109238551) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $lte: new Date(1475109218555) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt:$\n\n2016-09-29T00:33:57.762+0000 [conn38] update jobs.agendaJobs query: { _id: ObjectId('57ec2ca90ab9be9605050a7d'), $or: [ { name: \"MealJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109238551) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109238551) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $lte: new Date(1475109218555) }, disabled: { $ne: true } } ] } update: { $set: { lockedAt: new Date(1475109228555) } } nscanned:1 nscannedObjects:1 nMatched:1 nModified:1 keyUpdates:2 numYields:0 1309ms\n\n2016-09-29T00:33:58.870+0000 [conn38] query jobs.agendaJobs query: { _id: ObjectId('57ec2ca90ab9be9605050a7d') } planSummary: IDHACK ntoreturn:1 ntoskip:0 nscanned:1 nscannedObjects:1 idhack:1 keyUpdates:0 numYields:0 nreturned:1 reslen:257 336ms\n\n2016-09-29T00:33:59.276+0000 [conn38] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"MealJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109238551) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109238551) }, disabled: { $ne: true } }, { name: \"MealJob\", lockedAt: { $lte: new Date(1475109218555) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109228555) } } } keyUpdates:0 numYields:0 locks(micros) w:4875284 reslen:390 4967ms\n\n2016-09-29T00:34:00.753+0000 [conn37] query jobs.agendaJobs query: { query: { $or: [ { name: \"OrderDeliveringReminderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109243373) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109243373) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $lte: new Date(1475109223414) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }$\n\n2016-09-29T00:34:01.061+0000 [conn37] command jobs.$cmd command: findAndModify { findandmodify: \"agendaJobs\", query: { $or: [ { name: \"OrderDeliveringReminderJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109243373) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109243373) }, disabled: { $ne: true } }, { name: \"OrderDeliveringReminderJob\", lockedAt: { $lte: new Date(1475109223414) }, disabled: { $ne: true } } ] }, sort: { priority: -1 }, new: true, remove: false, upsert: false, update: { $set: { lockedAt: new Date(1475109233414) } } } keyUpdates:0 numYields:$\n\n2016-09-29T00:34:03.579+0000 [conn36] query jobs.agendaJobs query: { query: { $or: [ { name: \"MealStartJob\", lockedAt: null, nextRunAt: { $lte: new Date(1475109242960) }, disabled: { $ne: true } }, { name: \"MealStartJob\", lockedAt: { $exists: false }, nextRunAt: { $lte: new Date(1475109242960) }, disabled: { $ne: true } }, { name: \"MealStartJob\", lockedAt: { $lte: new Date(1475109222974) }, disabled: { $ne: true } } ] }, orderby: { priority: -1 } } planSummary: IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, IXSCAN { name: 1, priority: -1, lockedAt$`\n\nPlease help me. I am desperate to find a solution.\n"},"comment":{"url":"https://api.github.com/repos/rschmukler/agenda/issues/comments/261848962","html_url":"https://github.com/rschmukler/agenda/issues/370#issuecomment-261848962","issue_url":"https://api.github.com/repos/rschmukler/agenda/issues/370","id":261848962,"user":{"login":"Kuraturpa","id":603669,"avatar_url":"https://avatars.githubusercontent.com/u/603669?v=3","gravatar_id":"","url":"https://api.github.com/users/Kuraturpa","html_url":"https://github.com/Kuraturpa","followers_url":"https://api.github.com/users/Kuraturpa/followers","following_url":"https://api.github.com/users/Kuraturpa/following{/other_user}","gists_url":"https://api.github.com/users/Kuraturpa/gists{/gist_id}","starred_url":"https://api.github.com/users/Kuraturpa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kuraturpa/subscriptions","organizations_url":"https://api.github.com/users/Kuraturpa/orgs","repos_url":"https://api.github.com/users/Kuraturpa/repos","events_url":"https://api.github.com/users/Kuraturpa/events{/privacy}","received_events_url":"https://api.github.com/users/Kuraturpa/received_events","type":"User","site_admin":false},"created_at":"2016-11-21T05:44:07Z","updated_at":"2016-11-21T05:44:07Z","body":"+1"}}
{"actor":{"display_login":"Kuraturpa"}}