mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 02:47:35 -02:30
Merge pull request #2695 from ryanpetrello/celerywatcher-iso8601
some celery-watcher tweaks
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -33,19 +34,25 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
INTERVAL = 60
|
INTERVAL = 60
|
||||||
|
|
||||||
|
def _log(self, msg):
|
||||||
|
sys.stderr.write(datetime.datetime.utcnow().isoformat())
|
||||||
|
sys.stderr.write(' ')
|
||||||
|
sys.stderr.write(msg)
|
||||||
|
sys.stderr.write('\n')
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
app = Celery('awx')
|
app = Celery('awx')
|
||||||
app.config_from_object('django.conf:settings')
|
app.config_from_object('django.conf:settings')
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
pongs = app.control.ping(['celery@{}'.format(settings.CLUSTER_HOST_ID)])
|
pongs = app.control.ping(['celery@{}'.format(settings.CLUSTER_HOST_ID)], timeout=30)
|
||||||
except Exception:
|
except Exception:
|
||||||
pongs = []
|
pongs = []
|
||||||
if not pongs:
|
if not pongs:
|
||||||
sys.stderr.write('celery is not responsive to ping over local AMQP\n')
|
self._log('celery is not responsive to ping over local AMQP')
|
||||||
pid = self.getpid()
|
pid = self.getpid()
|
||||||
if pid:
|
if pid:
|
||||||
sys.stderr.write('sending SIGHUP to {}\n'.format(pid))
|
self._log('sending SIGHUP to {}'.format(pid))
|
||||||
os.kill(pid, signal.SIGHUP)
|
os.kill(pid, signal.SIGHUP)
|
||||||
time.sleep(self.INTERVAL)
|
time.sleep(self.INTERVAL)
|
||||||
|
|
||||||
@@ -56,4 +63,4 @@ class Command(BaseCommand):
|
|||||||
try:
|
try:
|
||||||
return int(subprocess.check_output(cmd, shell=True))
|
return int(subprocess.check_output(cmd, shell=True))
|
||||||
except Exception:
|
except Exception:
|
||||||
sys.stderr.write('could not detect celery pid\n')
|
self._log('could not detect celery pid')
|
||||||
|
|||||||
Reference in New Issue
Block a user