Commit ad0012ec authored by Alex Dadgar's avatar Alex Dadgar Committed by Michael Schurter
Browse files

Remove SetState from interface

parent 39939a1b
Branches unavailable
No related merge requests found
Showing with 4 additions and 6 deletions
+4 -6
......@@ -30,15 +30,14 @@ func (*artifactHook) Name() string {
}
func (h *artifactHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartRequest, resp *interfaces.TaskPrestartResponse) error {
h.eventEmitter.SetState(structs.TaskStatePending, structs.NewTaskEvent(structs.TaskDownloadingArtifacts))
h.eventEmitter.EmitEvent(structs.NewTaskEvent(structs.TaskDownloadingArtifacts))
for _, artifact := range req.Task.Artifacts {
//XXX add ctx to GetArtifact to allow cancelling long downloads
if err := getter.GetArtifact(req.TaskEnv, artifact, req.TaskDir); err != nil {
wrapped := fmt.Errorf("failed to download artifact %q: %v", artifact.GetterSource, err)
h.logger.Debug(wrapped.Error())
h.eventEmitter.SetState(structs.TaskStatePending,
structs.NewTaskEvent(structs.TaskArtifactDownloadFailed).SetDownloadError(wrapped))
h.eventEmitter.EmitEvent(structs.NewTaskEvent(structs.TaskArtifactDownloadFailed).SetDownloadError(wrapped))
return wrapped
}
}
......
......@@ -3,6 +3,5 @@ package interfaces
import "github.com/hashicorp/nomad/nomad/structs"
type EventEmitter interface {
SetState(state string, event *structs.TaskEvent)
EmitEvent(event *structs.TaskEvent)
}
......@@ -35,7 +35,7 @@ func (h *taskDirHook) Prestart(ctx context.Context, req *interfaces.TaskPrestart
}
// Emit the event that we are going to be building the task directory
h.runner.SetState("", structs.NewTaskEvent(structs.TaskSetup).SetMessage(structs.TaskBuildingTaskDir))
h.runner.EmitEvent(structs.NewTaskEvent(structs.TaskSetup).SetMessage(structs.TaskBuildingTaskDir))
// Build the task directory structure
fsi := h.runner.driver.FSIsolation()
......
......@@ -507,7 +507,7 @@ func (tr *TaskRunner) SetState(state string, event *structs.TaskEvent) {
taskState := tr.state
//XXX REMOVE ME AFTER TESTING
if state != "" {
if state == "" {
panic("SetState must not be called with an empty state")
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment