Skip to content

Commit

Permalink
Reboot dead workers
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 12, 2019
1 parent 58f4988 commit 9799774
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/workers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ function withworker!(f, pool::WorkerPool)

if isempty(pool.available)
worker = Worker(pool.spec)

# When the `worker` exits with an error, try rebooting it.
let poolref = WeakRef(pool),
process = worker.process
@async begin # this should go into a "nursery"
wait(process)
process.exitcode == 0 && return
local pool = poolref.value
pool === nothing && return
acquiring(pool.semaphore) do
# TODO: don't do this if `length(available) > limit`.
@info "Rebooting a dead worker..."
push!(pool.available, Worker(pool.spec))
end
end
end
else
worker = pop!(pool.available)
end
Expand Down

0 comments on commit 9799774

Please sign in to comment.