-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split apart task hydration+execution from watcher/config package with…
… a simple channel resolves #27
- Loading branch information
1 parent
b61ceac
commit b3657a1
Showing
6 changed files
with
95 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package executor | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
|
||
"github.com/picostack/pico/service/secret" | ||
"github.com/picostack/pico/service/task" | ||
) | ||
|
||
var _ Executor = &CommandExecutor{} | ||
|
||
// CommandExecutor handles command invocation targets | ||
type CommandExecutor struct { | ||
secrets secret.Store | ||
} | ||
|
||
// NewCommandExecutor creates a new CommandExecutor | ||
func NewCommandExecutor(secrets secret.Store) CommandExecutor { | ||
return CommandExecutor{ | ||
secrets: secrets, | ||
} | ||
} | ||
|
||
// Subscribe implements executor.Executor | ||
func (e *CommandExecutor) Subscribe(bus chan task.ExecutionTask) error { | ||
for t := range bus { | ||
if err := e.execute(t.Target, t.Path, t.Shutdown); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (e *CommandExecutor) execute( | ||
target task.Target, | ||
path string, | ||
shutdown bool, | ||
) (err error) { | ||
env, err := e.secrets.GetSecretsForTarget(target.Name) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get secrets for target") | ||
} | ||
|
||
zap.L().Debug("executing with secrets", | ||
zap.String("target", target.Name), | ||
zap.Strings("cmd", target.Up), | ||
zap.String("url", target.RepoURL), | ||
zap.String("dir", path), | ||
zap.Int("secrets", len(env))) | ||
|
||
return target.Execute(path, env, shutdown) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package executor | ||
|
||
import "github.com/picostack/pico/service/task" | ||
|
||
// Executor describes a type that can handle events and react to them. An | ||
// executor is also responsible for hydrating a target with secrets. | ||
type Executor interface { | ||
Subscribe(chan task.ExecutionTask) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters