30 lines
641 B
Go
30 lines
641 B
Go
|
package sdk
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"golang.org/x/exp/slog"
|
||
|
)
|
||
|
|
||
|
func NewExecutor(repoRoot, outDir, binDir string) Executor {
|
||
|
return Executor{
|
||
|
logger: slog.New(NewWASIHandler()),
|
||
|
repoRoot: repoRoot,
|
||
|
outDir: outDir,
|
||
|
binDir: binDir,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
type Executor struct {
|
||
|
logger *slog.Logger
|
||
|
repoRoot string
|
||
|
outDir string
|
||
|
binDir string
|
||
|
}
|
||
|
|
||
|
func (e Executor) Run(ctx context.Context, modName string, m Module) {
|
||
|
execCtx := newWasiExecutionContext(ctx, e.logger, modName, m, e.repoRoot, e.binDir, e.outDir)
|
||
|
if err := m.Execute(execCtx); err != nil {
|
||
|
e.logger.Error("Failed to execute module", slog.String("err", err.Error()))
|
||
|
}
|
||
|
}
|