mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use context manager for request channel
This commit is contained in:
parent
be5ef66a3a
commit
6615b5a530
1 changed files with 10 additions and 13 deletions
|
@ -552,19 +552,16 @@ class AsyncPubChannel:
|
|||
"data": data,
|
||||
"tag": tag,
|
||||
}
|
||||
req_channel = AsyncReqChannel.factory(self.opts)
|
||||
try:
|
||||
yield req_channel.send(load, timeout=60)
|
||||
except salt.exceptions.SaltReqTimeoutError:
|
||||
log.info(
|
||||
"fire_master failed: master could not be contacted. Request timed"
|
||||
" out."
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
log.info("fire_master failed", exc_info=True)
|
||||
finally:
|
||||
# SyncWrapper will call either close() or destroy(), whichever is available
|
||||
req_channel.close()
|
||||
with AsyncReqChannel.factory(self.opts) as channel:
|
||||
try:
|
||||
yield channel.send(load, timeout=60)
|
||||
except salt.exceptions.SaltReqTimeoutError:
|
||||
log.info(
|
||||
"fire_master failed: master could not be contacted. Request timed"
|
||||
" out."
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
log.info("fire_master failed", exc_info=True)
|
||||
else:
|
||||
self._reconnected = True
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
|
|
Loading…
Add table
Reference in a new issue