Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Map/Parallel States checking container_runner#status! of finished states #296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/floe/container_runner/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def docker_event_status_to_event(status)

def inspect_container(container_id)
JSON.parse(docker!("inspect", container_id).output).first
rescue
nil
rescue AwesomeSpawn::CommandResultError => err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but it's weird to me that docker! method fails and we catch AwesomeSpawn::CommandResultError, as that requires the caller to know the implementation of the callee. Does it make more sense to have docker! do the rescue/catch and raise something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, it's all self contained in the same file, so probably not a big deal.

raise Floe::ExecutionError.new("Failed to get status for container #{container_id}: #{err}")
end

def delete_container(container_id)
Expand Down
2 changes: 2 additions & 0 deletions lib/floe/container_runner/kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def wait(timeout: nil, events: %i[create update delete])

def pod_info(pod_name)
kubeclient.get_pod(pod_name, namespace)
rescue Kubeclient::HttpError => err
raise Floe::ExecutionError.new("Failed to get status for pod #{namespace}/#{pod_name}: #{err}")
end

def pod_running?(context)
Expand Down
10 changes: 9 additions & 1 deletion lib/floe/workflow/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ def start(context)
mark_started(context)
end

def started?(context)
context.state_started?
end

def finish(context)
mark_finished(context)
end

def finished?(context)
context.state_finished?
end

def mark_started(context)
context.state["EnteredTime"] = Time.now.utc.iso8601

Expand Down Expand Up @@ -87,7 +95,7 @@ def mark_error(context, exception)
end

def ready?(context)
!context.state_started? || !running?(context)
!started?(context) || !running?(context)
end

def running?(context)
Expand Down
3 changes: 2 additions & 1 deletion lib/floe/workflow/states/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def finish(context)
end

def running?(context)
return true if waiting?(context)
return true if waiting?(context)
return false if finished?(context)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for this issue, I'd also like to make sure we don't check running? for a sub-workflow that we know to be finished but this is also good insurance at the Task level.


runner.status!(context.state["RunnerContext"])
runner.running?(context.state["RunnerContext"])
Expand Down
2 changes: 1 addition & 1 deletion spec/container_runner/kubernetes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@

it "raises an exception when getting pod info fails" do
allow(kubeclient).to receive(:get_pod).and_raise(Kubeclient::ResourceNotFoundError.new(404, "Resource Not Found", {}))
expect { subject.status!(runner_context) }.to raise_error(Kubeclient::ResourceNotFoundError, /Resource Not Found/)
expect { subject.status!(runner_context) }.to raise_error(Floe::ExecutionError, /Failed to get status for pod/)
end
end

Expand Down