mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 09:48:10 -05:00
better math
This commit is contained in:
@@ -34,7 +34,12 @@ const client = new S3Client({
|
|||||||
|
|
||||||
exports.upload = async function (req, res, next) {
|
exports.upload = async function (req, res, next) {
|
||||||
const tracer = trace.getTracer("upload-service");
|
const tracer = trace.getTracer("upload-service");
|
||||||
const start_time = Date.now();
|
let start_time = Date.now();
|
||||||
|
let validateSystemTime = 0;
|
||||||
|
let readFileTime = 0;
|
||||||
|
let uploadFileTime = 0;
|
||||||
|
let saveCallTime = 0;
|
||||||
|
let cleanupTime = 0;
|
||||||
return context.with(context.active(), async () => {
|
return context.with(context.active(), async () => {
|
||||||
const parentSpan = trace.getActiveSpan(context.active());
|
const parentSpan = trace.getActiveSpan(context.active());
|
||||||
await tracer.startActiveSpan('upload_handler', { parent: parentSpan }, async (span) => {
|
await tracer.startActiveSpan('upload_handler', { parent: parentSpan }, async (span) => {
|
||||||
@@ -109,7 +114,7 @@ exports.upload = async function (req, res, next) {
|
|||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const validateSystemTime = Date.now() - start_time;
|
validateSystemTime = Date.now();
|
||||||
if (item.ignoreUnknownTalkgroup) {
|
if (item.ignoreUnknownTalkgroup) {
|
||||||
const talkgroupExists = await Talkgroup.exists({
|
const talkgroupExists = await Talkgroup.exists({
|
||||||
shortName,
|
shortName,
|
||||||
@@ -152,11 +157,11 @@ exports.upload = async function (req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let fileContent;
|
let fileContent;
|
||||||
let readFileTime=0
|
|
||||||
await tracer.startActiveSpan('upload_to_s3', { parent: trace.getActiveSpan(context.active()) }, async (uploadSpan) => {
|
await tracer.startActiveSpan('upload_to_s3', { parent: trace.getActiveSpan(context.active()) }, async (uploadSpan) => {
|
||||||
try {
|
try {
|
||||||
fileContent = fs.readFileSync(req.file.path);
|
fileContent = fs.readFileSync(req.file.path);
|
||||||
readFileTime = Date.now() - start_time;
|
readFileTime = Date.now();
|
||||||
const command = new PutObjectCommand({
|
const command = new PutObjectCommand({
|
||||||
Bucket: s3_bucket,
|
Bucket: s3_bucket,
|
||||||
Key: object_key,
|
Key: object_key,
|
||||||
@@ -179,7 +184,7 @@ exports.upload = async function (req, res, next) {
|
|||||||
uploadSpan.end();
|
uploadSpan.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const uploadFileTime = Date.now() - start_time;
|
uploadFileTime = Date.now();
|
||||||
await tracer.startActiveSpan('save_call', { parent: trace.getActiveSpan(context.active()) }, async (saveSpan) => {
|
await tracer.startActiveSpan('save_call', { parent: trace.getActiveSpan(context.active()) }, async (saveSpan) => {
|
||||||
try {
|
try {
|
||||||
await call.save();
|
await call.save();
|
||||||
@@ -197,7 +202,7 @@ exports.upload = async function (req, res, next) {
|
|||||||
|
|
||||||
|
|
||||||
sysStats.addCall(call.toObject());
|
sysStats.addCall(call.toObject());
|
||||||
const saveCallTime = Date.now() - start_time;
|
saveCallTime = Date.now();
|
||||||
|
|
||||||
if (call.len >= 1) {
|
if (call.len >= 1) {
|
||||||
req.call = call.toObject();
|
req.call = call.toObject();
|
||||||
@@ -215,8 +220,8 @@ exports.upload = async function (req, res, next) {
|
|||||||
cleanupSpan.end();
|
cleanupSpan.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const cleanupTime = Date.now() - start_time;
|
cleanupTime = Date.now();
|
||||||
console.log(`[${call.shortName}] \t Verify System: ${validateSystemTime } \t Upload: ${uploadFileTime} \t Save: ${saveCallTime} \tCleanup: ${cleanupTime} \t\t Total: ${cleanupTime - start_time}`);
|
console.log(`[${call.shortName}] \t Verify System: ${validateSystemTime - start_time} \t Read file: ${readFileTime - validateSystemTime} \t Upload: ${ uploadFileTime - validateSystemTime} \t Save: ${saveCallTime - uploadFileTime} \tCleanup: ${cleanupTime - saveCallTime} \t\t Total: ${cleanupTime - start_time}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error processing call upload: " + error);
|
console.error("Error processing call upload: " + error);
|
||||||
span.recordException(error);
|
span.recordException(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user