Skip to content

Commit

Permalink
fix: restart watcher on end
Browse files Browse the repository at this point in the history
  • Loading branch information
Sceat committed Apr 6, 2024
1 parent 60bd04f commit 3c1e829
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ const respond_with_endpoints = async () => {
await zmq_reply.send(ips)
}

await new Watch(kc).watch(
'/api/v1/pods',
{
labelSelector: `app=${LABEL}`,
timeoutSeconds: 0,
},
(type, { status: { podIP } }) => {
if (!podIP) return
log.info({ type, ip: podIP }, 'sending update')
zmq_publisher.send([type, podIP]).catch(error => log.error(error))
},
error => {
console.error('Watcher stopped with error:', error)
}
)
async function start_watcher() {
log.info('Starting watcher..')

return new Watch(kc).watch(
'/api/v1/pods',
{
labelSelector: `app=${LABEL}`,
timeoutSeconds: 0,
},
(type, { status: { podIP } }) => {
if (!podIP) return
log.info({ type, ip: podIP }, 'sending update')
zmq_publisher.send([type, podIP]).catch(error => log.error(error))
},
error => {
log.error(error, 'Watcher stopped with error:')
start_watcher()
}
)
}

await start_watcher()

while (await zmq_reply.receive()) await respond_with_endpoints()

0 comments on commit 3c1e829

Please sign in to comment.