ensure info/apps is published to when docker events happen

Signed-off-by: Alexis Tyler <xo@wvvw.me>
This commit is contained in:
Alexis Tyler
2019-09-01 09:56:50 +09:30
parent f93531dcbe
commit 882dbbf5cc
4 changed files with 101 additions and 21 deletions

View File

@@ -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',

View File

@@ -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);