diff --git a/CHANGELOG.md b/CHANGELOG.md index 586c713..cce07a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ * Drop support for Meteor 1.4 - 1.8.2 * Add support for Meteor 3 * Add remote heap snapshots -* ### v1.6.3 March 16, 2022 diff --git a/lib/server.js b/lib/server.js index 4261226..5e3213a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -50,22 +50,22 @@ remoteProfileCPU = async function(timeToProfileSecs, id) { var name = Random.id(); var profile = await getCpuProfile(name, timeToProfileSecs); console.log("Monti APM: Uploding the taken CPU profile."); - Monti.Jobs.set(id, {state: 'profile-taken'}); + await setJob(id, {state: 'profile-taken'}); await uploadProfile(profile, job.data.uploadUrl); console.log("Monti APM: Profiling has been completed. Visit Monti APM to analyze it."); - Monti.Jobs.set(id, {state: 'completed'}); + await setJob(id, {state: 'completed'}); return "CPU Profile has been completed. Check Monti APM to analyze it."; } catch(ex) { console.dir(ex); - Monti.Jobs.set(id, {state: 'errored', data:{errorMessage: ex.message}}); + await setJob(id, {state: 'errored', data:{errorMessage: ex.message}}); throw ex; } }; async function remoteHeapSnapshot (id) { - var job = Monti.Jobs.get(id); + var job = await getJob(id); if (!job) { throw new Meteor.Error(403, "There is no such heap snapshot job: " + id); } else if (job.state != 'created') { @@ -76,7 +76,7 @@ async function remoteHeapSnapshot (id) { console.log("Monti APM: heap snapshot started"); let memoryUsage = process.memoryUsage(); var jobData = { beforeRss: memoryUsage.rss, heapUsed: memoryUsage.heapUsed }; - let { updated } = Monti.Jobs.set(id, { state: 'initiated', data: jobData, expectedState: 'created' }); + let { updated } = await setJob(id, { state: 'initiated', data: jobData, expectedState: 'created' }); if (!updated) { console.log('Monti APM: heap snapshot already started'); @@ -98,17 +98,17 @@ async function remoteHeapSnapshot (id) { }); console.log("Monti APM: Uploading the heap snapshot."); - Monti.Jobs.set(id, { state: 'profile-taken' }); + await setJob(id, { state: 'profile-taken' }); await uploadProfile(content, job.data.uploadUrl); console.log("Monti APM: Recording the heap snapshot has completed. Visit Monti APM to analyze it."); snapshot.delete(); - Monti.Jobs.set(id, { state: 'completed' }); + await setJob(id, { state: 'completed' }); return "Recording the heap snapshot has completed. Check Monti APM to analyze it."; } catch (ex) { console.dir(ex); - Monti.Jobs.set(id, { state: 'errored', data: { errorMessage: ex.message } }); + await setJob(id, { state: 'errored', data: { errorMessage: ex.message } }); throw ex; } }