mirror of
https://github.com/unraid/api.git
synced 2026-01-10 10:40:04 -06:00
ensure info/apps is published to when docker events happen
Signed-off-by: Alexis Tyler <xo@wvvw.me>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Written by: Alexis Tyler
|
||||
*/
|
||||
|
||||
module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pubsub, setIntervalAsync, PluginManager, log, fromEntries, asyncMap, delay) {
|
||||
module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pubsub, setIntervalAsync, PluginManager, log, fromEntries, asyncMap, delay, dee) {
|
||||
const publish = (channel, mutation, {
|
||||
node = undefined,
|
||||
moduleToRun = undefined,
|
||||
@@ -112,6 +112,24 @@ module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pub
|
||||
}
|
||||
};
|
||||
|
||||
// On Docker event update info with { apps: { installed, started } }
|
||||
const updateIterator = async () => {
|
||||
const { json } = await $injector.resolveModule(`module:info/get-apps`);
|
||||
pubsub.publish('info', {
|
||||
info: {
|
||||
mutation: 'UPDATED',
|
||||
node: {
|
||||
...json
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
dee.on('start', updateIterator);
|
||||
dee.on('stop', updateIterator);
|
||||
|
||||
dee.listen();
|
||||
|
||||
return {
|
||||
Query: {
|
||||
info: () => ({}),
|
||||
@@ -137,18 +155,18 @@ module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pub
|
||||
...createBasicSubscription('docker/networks', 'docker/get-networks')
|
||||
},
|
||||
info: {
|
||||
subscribe: () => pubsub.asyncIterator('info'),
|
||||
close() {
|
||||
console.debug('Clearing info subscription timers');
|
||||
subscribe: () => pubsub.asyncIterator('info')
|
||||
// close() {
|
||||
// console.debug('Clearing info subscription timers');
|
||||
|
||||
// Clear all info subscription timers
|
||||
Object.entries($injector._graph).filter(([ name ]) => {
|
||||
return name.startsWith('timer:info');
|
||||
}).map(([name, timer]) => {
|
||||
console.debug(`Clearing ${name} subscription timer`);
|
||||
clearInterval(timer);
|
||||
});
|
||||
}
|
||||
// // Clear all info subscription timers
|
||||
// Object.entries($injector._graph).filter(([ name ]) => {
|
||||
// return name.startsWith('timer:info');
|
||||
// }).map(([name, timer]) => {
|
||||
// console.debug(`Clearing ${name} subscription timer`);
|
||||
// clearInterval(timer);
|
||||
// });
|
||||
// }
|
||||
// subscribe: async () => {
|
||||
// const infoFields = [
|
||||
// 'apps',
|
||||
|
||||
17
app/index.js
17
app/index.js
@@ -18,15 +18,15 @@ const $injector = new Injector();
|
||||
$injector.registerImports([
|
||||
'net',
|
||||
'http',
|
||||
'express',
|
||||
'apollo-server',
|
||||
'apollo-server-express',
|
||||
'graphql',
|
||||
'apollo-server',
|
||||
'deepmerge',
|
||||
'stoppable',
|
||||
'graphql-tools',
|
||||
'express',
|
||||
'graphql-subscriptions',
|
||||
'set-interval-async/dynamic'
|
||||
'graphql-tools',
|
||||
'graphql',
|
||||
'set-interval-async/dynamic',
|
||||
'stoppable'
|
||||
]);
|
||||
|
||||
// Register modules that need require and not import
|
||||
@@ -36,13 +36,14 @@ $injector.registerRequires([
|
||||
|
||||
// Register the imported modules with custom names.
|
||||
$injector.registerImports({
|
||||
dee: '@gridplus/docker-events',
|
||||
get: 'lodash.get',
|
||||
gql: 'graphql-tag',
|
||||
graphqlDirective: 'graphql-directive',
|
||||
mergeGraphqlSchemas: 'merge-graphql-schemas',
|
||||
GraphQLJSON: 'graphql-type-json',
|
||||
GraphQLLong: 'graphql-type-long',
|
||||
GraphQLUUID: 'graphql-type-uuid',
|
||||
gql: 'graphql-tag'
|
||||
mergeGraphqlSchemas: 'merge-graphql-schemas'
|
||||
});
|
||||
|
||||
$injector.registerValue('setIntervalAsync', $injector.resolve('set-interval-async/dynamic').setIntervalAsync);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"lint": "exit 0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gridplus/docker-events": "^1.0.0",
|
||||
"@unraid/core": "unraid/core#f174fe3",
|
||||
"accesscontrol": "^2.2.1",
|
||||
"am": "^1.0.1",
|
||||
|
||||
62
yarn.lock
62
yarn.lock
@@ -109,6 +109,15 @@
|
||||
lodash "^4.17.13"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@gridplus/docker-events@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@gridplus/docker-events/-/docker-events-1.0.0.tgz#0bb87e7cc90db83bf2d545fb2bb42ba54751ca17"
|
||||
integrity sha512-WtMKFmM9pQ5W594RG+VulhYAWJ3Z95NbHEh1LemFsnm00HE48NkQV1E6NOCwfENJ+h28JU6Dvg+ZjW341RQSrw==
|
||||
dependencies:
|
||||
debug "^3.1.0"
|
||||
llog "^0.1.1"
|
||||
pino "^5.0.4"
|
||||
|
||||
"@kamilkisiela/graphql-tools@4.0.6":
|
||||
version "4.0.6"
|
||||
resolved "https://registry.yarnpkg.com/@kamilkisiela/graphql-tools/-/graphql-tools-4.0.6.tgz#6dcf4d18bedaf34f6ab1d5bad2414e530d0875d1"
|
||||
@@ -1530,7 +1539,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
|
||||
dependencies:
|
||||
ms "2.0.0"
|
||||
|
||||
debug@^3.2.6:
|
||||
debug@^3.1.0, debug@^3.2.6:
|
||||
version "3.2.6"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
|
||||
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
|
||||
@@ -2316,6 +2325,16 @@ fast-levenshtein@~2.0.4:
|
||||
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
|
||||
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=
|
||||
|
||||
fast-redact@^1.4.4:
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/fast-redact/-/fast-redact-1.5.0.tgz#302892f566750c4f5eec7b830bfc9bc473484034"
|
||||
integrity sha512-Afo61CgUjkzdvOKDHn08qnZ0kwck38AOGcMlvSGzvJbIab6soAP5rdoQayecGCDsD69AiF9vJBXyq31eoEO2tQ==
|
||||
|
||||
fast-safe-stringify@^2.0.6:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz#04b26106cc56681f51a044cfc0d76cf0008ac2c2"
|
||||
integrity sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg==
|
||||
|
||||
figures@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
|
||||
@@ -2405,6 +2424,11 @@ flat-cache@^2.0.1:
|
||||
rimraf "2.6.3"
|
||||
write "1.0.3"
|
||||
|
||||
flatstr@^1.0.12, flatstr@^1.0.9:
|
||||
version "1.0.12"
|
||||
resolved "https://registry.yarnpkg.com/flatstr/-/flatstr-1.0.12.tgz#c2ba6a08173edbb6c9640e3055b95e287ceb5931"
|
||||
integrity sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw==
|
||||
|
||||
flatted@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
|
||||
@@ -3678,6 +3702,13 @@ linkify-it@^2.0.0:
|
||||
dependencies:
|
||||
uc.micro "^1.0.1"
|
||||
|
||||
llog@^0.1.1:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/llog/-/llog-0.1.1.tgz#29ce18e06ed74579e71f460de8c0f218d6525a72"
|
||||
integrity sha512-zrFJCg8iHw+szK2h4lyYr/3cA16u5tdzCG2jp0sK1OtOdxTe+UbAm8nM4bQdgcMRmMzU/FPawkdLaAL50M7PBA==
|
||||
dependencies:
|
||||
debug "^3.1.0"
|
||||
|
||||
load-from-cwd-or-npm@^2.2.1:
|
||||
version "2.2.2"
|
||||
resolved "https://registry.yarnpkg.com/load-from-cwd-or-npm/-/load-from-cwd-or-npm-2.2.2.tgz#86d21082f13c7cb4969ddeb90d0261c18b671e42"
|
||||
@@ -4692,6 +4723,23 @@ pinkie@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
|
||||
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=
|
||||
|
||||
pino-std-serializers@^2.3.0:
|
||||
version "2.4.2"
|
||||
resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-2.4.2.tgz#cb5e3e58c358b26f88969d7e619ae54bdfcc1ae1"
|
||||
integrity sha512-WaL504dO8eGs+vrK+j4BuQQq6GLKeCCcHaMB2ItygzVURcL1CycwNEUHTD/lHFHs/NL5qAz2UKrjYWXKSf4aMQ==
|
||||
|
||||
pino@^5.0.4:
|
||||
version "5.13.2"
|
||||
resolved "https://registry.yarnpkg.com/pino/-/pino-5.13.2.tgz#773416c9764634276e7b2ae021357679ff7b5634"
|
||||
integrity sha512-WwOSCy36/gWhinsqWqAnuwIi2WtcH+jvoyeLm3bjUALIrzWIst0AovQjK4jVvSN2l64KFPfi3gd2fjsTovjdLQ==
|
||||
dependencies:
|
||||
fast-redact "^1.4.4"
|
||||
fast-safe-stringify "^2.0.6"
|
||||
flatstr "^1.0.9"
|
||||
pino-std-serializers "^2.3.0"
|
||||
quick-format-unescaped "^3.0.2"
|
||||
sonic-boom "^0.7.5"
|
||||
|
||||
pkg-conf@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/pkg-conf/-/pkg-conf-2.1.0.tgz#2126514ca6f2abfebd168596df18ba57867f0058"
|
||||
@@ -4860,6 +4908,11 @@ qs@~6.5.2:
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
||||
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
|
||||
|
||||
quick-format-unescaped@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-3.0.2.tgz#0137e94d8fb37ffeb70040535111c378e75396fb"
|
||||
integrity sha512-FXTaCkwvpIlkdKeGDNgcq07SXWS383noQUuZjvdE1QcTt+eLuqof6/BDiEPqB59FWLie/l91+HtlJSw7iCViSA==
|
||||
|
||||
quick-lru@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8"
|
||||
@@ -5399,6 +5452,13 @@ snapdragon@^0.8.1:
|
||||
source-map-resolve "^0.5.0"
|
||||
use "^3.1.0"
|
||||
|
||||
sonic-boom@^0.7.5:
|
||||
version "0.7.5"
|
||||
resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-0.7.5.tgz#b383d92cdaaa8e66d1f77bdec71b49806d01b5f1"
|
||||
integrity sha512-1pKrnAV6RfvntPnarY71tpthFTM3pWZWWQdghZY8ARjtDPGzG/inxqSuRwQY/7V1woUjfyxPb437zn4p5phgnQ==
|
||||
dependencies:
|
||||
flatstr "^1.0.12"
|
||||
|
||||
sort-keys@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-2.0.0.tgz#658535584861ec97d730d6cf41822e1f56684128"
|
||||
|
||||
Reference in New Issue
Block a user