Skip to content
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

Fix memory issues #5733

Merged
merged 4 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ export default function createJobClass() {
let cb = rest[adjustedLength - 1];

[options, cb] = Array.from(optionsHelp(options, cb));
if (typeof options.timeout !== "number") { options.timeout = 60 * 1000; }
return methodCall(root, "shutdownJobServer", [options], cb);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,42 +463,38 @@ export default function createJobCollectionClass({ Job, later }) {

// eslint-disable-next-line camelcase
_DDPMethod_startJobServer() {
// The client can't actually do this, so skip it
if (!this.isSimulation) {
if (this.stopped && (this.stopped !== true)) { clearTimeout(this.stopped); }
this.stopped = false;
}
this.stopped = false;
return true;
}

// eslint-disable-next-line camelcase
_DDPMethod_shutdownJobServer(options = {}) {
if (!options.timeout) {
options.timeout = 60 * 1000;
}
async _DDPMethod_shutdownJobServer() {
this.stopped = true;

// The client can"t actually do any of this, so skip it
if (!this.isSimulation) {
if (this.stopped && (this.stopped !== true)) { clearTimeout(this.stopped); }
this.stopped = setTimeout(
async () => {
const cursor = this.collection.find({ status: "running" });
const failedJobs = await cursor.count();
// Fail all currently running jobs
if (this.collection) {
const runningJobs = await this.collection.find({
status: "running"
}, {
projection: {
_id: 1,
runId: 1
}
}).toArray();

if (failedJobs !== 0) {
console.warn(`Failing ${failedJobs} jobs on queue stop.`);
}
if (runningJobs.length > 0) {
console.warn(`Failing ${runningJobs.length} jobs on queue stop.`);

await Promise.all(cursor.map((doc) => this._DDPMethod_jobFail(doc._id, doc.runId, "Running at Job Server shutdown.")));
await Promise.all(runningJobs.map((doc) => this._DDPMethod_jobFail(doc._id, doc.runId, "Running at Job Server shutdown.")));
}
}

if (this.logStream !== null) { // Shutting down closes the logStream!
this.logStream.end();
this.logStream = null;
}
},
options.timeout
);
// Close the log stream
if (this.logStream !== null) {
this.logStream.end();
this.logStream = null;
}

return true;
}

Expand Down
4 changes: 4 additions & 0 deletions imports/test-utils/setupJestIntegrationTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
process.on("unhandledRejection", (err) => {
console.error("unhandledRejection:", err); // eslint-disable-line no-console
process.exit(10); // eslint-disable-line no-process-exit
});
3 changes: 2 additions & 1 deletion jest-mongodb-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
version: "3.6.14",
skipMD5: true
},
autoStart: false
autoStart: false,
debug: true
}
};
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const jestConfig = {
// integration tests as opposed to unit tests, which don't need MongoDB running.
if (process.env.JEST_MONGO) {
delete jestConfig.testEnvironment;
jestConfig.setupFilesAfterEnv = ["<rootDir>/imports/test-utils/setupJestIntegrationTests.js"];
jestConfig.preset = "@shelf/jest-mongodb";
}

Expand Down
Loading