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.
maestro/app/services/routines.service.js

34 lines
1008 B

const { Service } = require('flitter-di')
const Routine = require('../classes/routine/Routine')
/*
* routines Service
* -------------------------------------------------------------
* This is a service file that will be made available through Flitter's
* dependency injector to the rest of the application based on its given
* canonical name.
*
* e.g. app.di().service("routines")
*/
class RoutinesService extends Service {
static get services() {
return [...super.services, 'injector', 'configs', 'hosts']
}
async get(name) {
const config = this.configs.get(`routines:${name}`)
if ( !config ) {
throw new Error(`Unable to find a routine with the name: ${name}`)
}
const hosts = {}
for ( const host_name of config.hosts ) {
hosts[host_name] = await this.hosts.get(host_name)
}
return this.injector.make(Routine, hosts, config, config.type)
}
}
module.exports = exports = RoutinesService