Skip to content

Commit

Permalink
newPico rulesets now install after the pico is fully setup
Browse files Browse the repository at this point in the history
  • Loading branch information
farskipper committed Jan 11, 2021
1 parent 7c215c4 commit e5b3e56
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Pico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/PicoFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class PicoFramework {
picoId: pico.id,
rid: rs.rid,
config: pico.rulesets[rs.rid]?.config,
error: err,
});
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/PicoFrameworkEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type PicoFrameworkEvent =
| PicoFrameworkEvent_txnDone
| PicoFrameworkEvent_txnError
| PicoFrameworkEvent_reInitRulesetError
| PicoFrameworkEvent_newPicoInstallError
| PicoFrameworkEvent_eventScheduleAdded
| PicoFrameworkEvent_eventScheduleCleared
| PicoFrameworkEvent_picoDeleted;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e5b3e56

Please sign in to comment.