Incremental

This commit is contained in:
2020-06-10 17:56:08 -05:00
parent 20e152f6e3
commit 44fd5a0830
6 changed files with 30 additions and 24 deletions
+5 -5
View File
@@ -13,16 +13,16 @@ type JSONResult {
#
type Query {
app_log: JSONResult!
app_log(incremental: Boolean): JSONResult!
app_status: JSONResult!
ipfs_log: JSONResult!
ipfs_log(incremental: Boolean): JSONResult!
ipfs_status: JSONResult!
ipfs_swarm_log: JSONResult!
ipfs_swarm_log(incremental: Boolean): JSONResult!
ipfs_swarm_status: JSONResult!
signal_log: JSONResult!
signal_log(incremental: Boolean): JSONResult!
signal_status: JSONResult!
system_status: JSONResult!
wns_log: JSONResult!
wns_log(incremental: Boolean): JSONResult!
wns_status: JSONResult!
}
+15 -12
View File
@@ -29,6 +29,7 @@ class LogCache {
}
const _caches = new Map();
const getLogCache = (name) => {
let cache = _caches.get(name);
if (!cache) {
@@ -38,48 +39,50 @@ const getLogCache = (name) => {
return cache;
}
const getLogs = async (name, lines = 100) => {
const getLogs = async (name, incremental = false, lines = 100) => {
const command = 'wire';
const args = ['service', 'logs', '--lines', lines, name];
const child = spawnSync(command, args, { encoding: 'utf8' });
const logLines = child.stdout.split(/\n/);
const cache = getLogCache(name);
return cache.append(logLines);
const added = cache.append(logLines);
return incremental ? added : Array.from(cache.buffer);
};
export const logResolvers = {
Query: {
wns_log: async () => {
const logs = await getLogs('wns-lite');
wns_log: async (_, { incremental }) => {
const logs = await getLogs('wns-lite', incremental);
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
signal_log: async () => {
const logs = await getLogs('signal');
signal_log: async (_, { incremental }) => {
const logs = await getLogs('signal', incremental);
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
ipfs_log: async () => {
const logs = await getLogs('ipfs');
ipfs_log: async (_, { incremental }) => {
const logs = await getLogs('ipfs', incremental);
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
ipfs_swarm_log: async () => {
const logs = await getLogs('ipfs');
ipfs_swarm_log: async (_, { incremental }) => {
const logs = await getLogs('ipfs-swarm-connect', incremental);
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
app_log: async () => {
const logs = await getLogs('ipfs');
app_log: async (_, { incremental }) => {
const logs = await getLogs('app', incremental);
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)