mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 02:17:37 -02:30
Merge pull request #85 from matburt/fact_scans_and_caching
Fact scans and caching
This commit is contained in:
@@ -87,7 +87,7 @@ class CallbackReceiver(object):
|
||||
queue_worker[2] = w
|
||||
if workers_changed:
|
||||
signal.signal(signal.SIGINT, shutdown_handler([p[2] for p in worker_queues] + [main_process]))
|
||||
signal.signal(signal.SIGTERM, shutdown_handler([p[2] for p in worker_queues] + [main_process]))
|
||||
signal.signal(signal.SIGTERM, shutdown_handler([p[2] for p in worker_queues] + [main_process]))
|
||||
if not main_process.is_alive():
|
||||
sys.exit(1)
|
||||
time.sleep(0.1)
|
||||
@@ -239,7 +239,7 @@ class Command(NoArgsCommand):
|
||||
Save Job Callback receiver (see awx.plugins.callbacks.job_event_callback)
|
||||
Runs as a management command and receives job save events. It then hands
|
||||
them off to worker processors (see Worker) which writes them to the database
|
||||
'''
|
||||
'''
|
||||
help = 'Launch the job callback receiver'
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
|
||||
55
awx/main/management/commands/run_fact_cache_receiver.py
Normal file
55
awx/main/management/commands/run_fact_cache_receiver.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved
|
||||
|
||||
import logging
|
||||
|
||||
from django.core.management.base import NoArgsCommand
|
||||
|
||||
from awx.main.models import * # noqa
|
||||
from awx.main.socket import Socket
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver')
|
||||
|
||||
class FactCacheReceiver(object):
|
||||
|
||||
def __init__(self):
|
||||
self.client = MongoClient('localhost', 27017)
|
||||
|
||||
def process_fact_message(self, message):
|
||||
host = message['host']
|
||||
facts = message['facts']
|
||||
date_key = message['date_key']
|
||||
host_db = self.client.host_facts
|
||||
host_collection = host_db[host]
|
||||
facts.update(dict(tower_host=host, datetime=date_key))
|
||||
rec = host_collection.find({"datetime": date_key})
|
||||
if rec.count():
|
||||
this_fact = rec.next()
|
||||
this_fact.update(facts)
|
||||
host_collection.save(this_fact)
|
||||
else:
|
||||
host_collection.insert(facts)
|
||||
|
||||
def run_receiver(self):
|
||||
with Socket('fact_cache', 'r') as facts:
|
||||
for message in facts.listen():
|
||||
print("Message received: " + str(message))
|
||||
if 'host' not in message or 'facts' not in message or 'date_key' not in message:
|
||||
continue
|
||||
self.process_fact_message(message)
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
'''
|
||||
blah blah
|
||||
'''
|
||||
help = 'Launch the Fact Cache Receiver'
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
fcr = FactCacheReceiver()
|
||||
try:
|
||||
fcr.run_receiver()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user