Skip to content

Commit

Permalink
Use async job api
Browse files Browse the repository at this point in the history
  • Loading branch information
zodern committed Dec 23, 2024
1 parent 379c384 commit 34d1582
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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');
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 34d1582

Please sign in to comment.