From 7dcf87cf0b36c90ab448ef0ef3da46a6818176b7 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Sun, 13 Dec 2020 00:38:40 +1030 Subject: [PATCH] feat: enable os uptime --- app/core/modules/index.ts | 1 + app/graphql/index.ts | 11 ++++++++++- app/graphql/resolvers/subscription/index.ts | 3 +++ app/graphql/schema/types/uptime/uptime.graphql | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/graphql/schema/types/uptime/uptime.graphql diff --git a/app/core/modules/index.ts b/app/core/modules/index.ts index 02e032110..a909dfb60 100644 --- a/app/core/modules/index.ts +++ b/app/core/modules/index.ts @@ -27,6 +27,7 @@ export * from './get-permissions'; export * from './get-plugins'; export * from './get-services'; export * from './get-unassigned-devices'; +export * from './get-uptime'; export * from './get-users'; export * from './get-vars'; export * from './get-welcome'; diff --git a/app/graphql/index.ts b/app/graphql/index.ts index a8d2adcaf..6c375bb69 100644 --- a/app/graphql/index.ts +++ b/app/graphql/index.ts @@ -344,17 +344,26 @@ dee.on('*', async (data: { Type: string }) => { dee.listen(); -// This needs to be fixed to run from events +// @TODO: This needs to be fixed to run from events setIntervalAsync(async () => { // @todo: Create a system user for this const user = usersState.findOne({ name: 'root' }); + // Services await run('services', 'UPDATED', { moduleToRun: modules.getServices, context: { user } }); + + // OS uptime + await run('uptime', 'UPDATED', { + moduleToRun: modules.getUptime, + context: { + user + } + }); }, 1000); export const graphql = { diff --git a/app/graphql/resolvers/subscription/index.ts b/app/graphql/resolvers/subscription/index.ts index 6b8ac2b60..21350e3f6 100644 --- a/app/graphql/resolvers/subscription/index.ts +++ b/app/graphql/resolvers/subscription/index.ts @@ -51,6 +51,9 @@ export const Subscription = { unassignedDevices: { ...createSubscription('devices/unassigned') }, + uptime: { + ...createSubscription('uptime') + }, users: { ...createSubscription('users') }, diff --git a/app/graphql/schema/types/uptime/uptime.graphql b/app/graphql/schema/types/uptime/uptime.graphql new file mode 100644 index 000000000..0b80744aa --- /dev/null +++ b/app/graphql/schema/types/uptime/uptime.graphql @@ -0,0 +1,12 @@ +type Query { + uptime: Uptime @func(module: "getUptime") +} + +type Subscription { + uptime: Uptime +} + +type Uptime { + milliseconds: Int! + timestamp: String! +} \ No newline at end of file