Skip to content

Commit

Permalink
yield task in async helper
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Jul 14, 2021
1 parent 5cf8639 commit 0b53d64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/kubetruth/etl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def with_polling(interval, &block)
def async(*args, **kwargs)
Async(*args, **kwargs) do |task|
begin
yield
yield task
rescue => e
logger.log_exception(e, "Failure in async task: #{task.annotation}")
task.stop
Expand Down
9 changes: 8 additions & 1 deletion spec/kubetruth/etl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,17 @@ class ForceExit < Exception; end
describe "verify async behavior" do

it "logs exceptions" do
etl.async(annotation: "badtask") do
task = etl.async(annotation: "badtask") do
raise "task fail"
end
expect(Logging.contents).to match(/ERROR ETL \[exception=RuntimeError \] Failure in async task: badtask/)
expect(task.status).to eq(:stopped)
end

it "yields task" do
etl.async(annotation: "mytask") do |task|
expect(task.annotation).to eq("mytask")
end
end

end
Expand Down

0 comments on commit 0b53d64

Please sign in to comment.