diff --git a/plugins/plugins.go b/plugins/plugins.go index 6fe185d049..34d627b9ba 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -261,20 +261,24 @@ func (m *Manager) RegisterCompilerTrigger(f func(txn storage.Transaction)) { // Start starts the manager. func (m *Manager) Start(ctx context.Context) error { + if m == nil { return nil } - err := storage.Txn(ctx, m.Store, storage.TransactionParams{}, func(txn storage.Transaction) error { - compiler, err := loadCompilerFromStore(ctx, m.Store, txn) + if err := storage.Txn(ctx, m.Store, storage.WriteParams, func(txn storage.Transaction) error { + + c, err := loadCompilerFromStore(ctx, m.Store, txn) if err != nil { return err } - m.setCompiler(compiler) - return nil - }) - if err != nil { + m.setCompiler(c) + + _, err = m.Store.Register(ctx, txn, storage.TriggerConfig{OnCommit: m.onCommit}) + return err + + }); err != nil { return err } @@ -295,12 +299,7 @@ func (m *Manager) Start(ctx context.Context) error { } } - config := storage.TriggerConfig{OnCommit: m.onCommit} - - return storage.Txn(ctx, m.Store, storage.WriteParams, func(txn storage.Transaction) error { - _, err := m.Store.Register(ctx, txn, config) - return err - }) + return nil } // Stop stops the manager, stopping all the plugins registered with it @@ -402,6 +401,7 @@ func (m *Manager) copyPluginStatus() map[string]*Status { } func (m *Manager) onCommit(ctx context.Context, txn storage.Transaction, event storage.TriggerEvent) { + if event.PolicyChanged() { var compiler *ast.Compiler diff --git a/runtime/runtime.go b/runtime/runtime.go index e9d93ca9d9..513d962209 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -191,6 +191,8 @@ func NewRuntime(ctx context.Context, params Params) (*Runtime, error) { return nil, errors.Wrap(err, "load error") } + // TOOD(tsandall): All of this storage setup could be done by the plugin manager. + // This would avoid the need to parse and recompile modules provided on startup. store := inmem.New() txn, err := store.NewTransaction(ctx, storage.WriteParams)