From e5b3e56ed9d863b1d12caa84ac78f454c3b75484 Mon Sep 17 00:00:00 2001 From: Matthew Wright Date: Mon, 11 Jan 2021 08:00:32 -0700 Subject: [PATCH] newPico rulesets now install after the pico is fully setup --- src/Pico.ts | 27 ++++++++++++++++----------- src/PicoFramework.ts | 1 + src/PicoFrameworkEvent.ts | 10 ++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Pico.ts b/src/Pico.ts index fa558f5..1a917bc 100644 --- a/src/Pico.ts +++ b/src/Pico.ts @@ -170,17 +170,6 @@ export class Pico { childChannel.toDbPut(), ]; - if (conf && conf.rulesets) { - for (const rs of conf.rulesets) { - const { instance, dbPut } = await child.installBase(rs.rs, rs.config); - dbOps.push(dbPut); - child.rulesets[rs.rs.rid] = { - config: rs.config || {}, - instance, - }; - } - } - try { await this.pf.db.batch(dbOps); } catch (err) { @@ -191,6 +180,22 @@ export class Pico { this.channels[parentChannel.id] = parentChannel; this.pf.addPico(child); + if (conf && conf.rulesets) { + for (const rs of conf.rulesets) { + try { + await child.install(rs.rs, rs.config); + } catch (err) { + this.pf.emit({ + type: "newPicoInstallError", + picoId: child.id, + rid: rs.rs.rid, + config: rs.config, + error: err, + }); + } + } + } + return childChannel.id; } diff --git a/src/PicoFramework.ts b/src/PicoFramework.ts index 7cc8bf8..74600c3 100644 --- a/src/PicoFramework.ts +++ b/src/PicoFramework.ts @@ -287,6 +287,7 @@ export class PicoFramework { picoId: pico.id, rid: rs.rid, config: pico.rulesets[rs.rid]?.config, + error: err, }); }); } diff --git a/src/PicoFrameworkEvent.ts b/src/PicoFrameworkEvent.ts index 51eca9e..0b497fc 100644 --- a/src/PicoFrameworkEvent.ts +++ b/src/PicoFrameworkEvent.ts @@ -11,6 +11,7 @@ export type PicoFrameworkEvent = | PicoFrameworkEvent_txnDone | PicoFrameworkEvent_txnError | PicoFrameworkEvent_reInitRulesetError + | PicoFrameworkEvent_newPicoInstallError | PicoFrameworkEvent_eventScheduleAdded | PicoFrameworkEvent_eventScheduleCleared | PicoFrameworkEvent_picoDeleted; @@ -65,6 +66,15 @@ export interface PicoFrameworkEvent_reInitRulesetError { picoId: string; rid: string; config?: RulesetConfig; + error: any; +} + +export interface PicoFrameworkEvent_newPicoInstallError { + type: "newPicoInstallError"; + picoId: string; + rid: string; + config?: RulesetConfig; + error: any; } export interface PicoFrameworkEvent_eventScheduleAdded {