You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
// core-node-request.js
|
|
// Copyright (C) 2022 DTP Technologies, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
const mongoose = require('mongoose');
|
|
const Schema = mongoose.Schema;
|
|
|
|
const { RequestTokenSchema } = require('./lib/core-request-token');
|
|
|
|
/*
|
|
* Used for authenticating responses received and gathering performance and use
|
|
* metrics for communications with Cores.
|
|
*
|
|
* When a request is created, an authentication token is generated and
|
|
* information about the request is stored. This also provides the request ID.
|
|
*
|
|
* When a resonse is received for a request, this record is fetched. The token
|
|
* claimed status and value are checked. Information about the response is
|
|
* recorded, and request execution time information is recorded.
|
|
*/
|
|
|
|
const CoreNodeRequestSchema = new Schema({
|
|
created: { type: Date, default: Date.now, required: true, index: 1, expires: '7d' },
|
|
core: { type: Schema.ObjectId, required: true, ref: 'CoreNode' },
|
|
token: { type: RequestTokenSchema },
|
|
method: { type: String, required: true },
|
|
url: { type: String, required: true },
|
|
response: {
|
|
received: { type: Date },
|
|
elapsed: { type: Number },
|
|
statusCode: { type: String },
|
|
success: { type: Boolean },
|
|
},
|
|
});
|
|
|
|
module.exports = (conn) => {
|
|
return conn.model('CoreNodeRequest', CoreNodeRequestSchema);
|
|
};
|