mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Handle unifying the datetime value as a key that we can update on the
tower side
This commit is contained in:
parent
fd1668dfd8
commit
70f2e5ea1d
@ -4,7 +4,6 @@
|
||||
import logging
|
||||
|
||||
from django.core.management.base import NoArgsCommand
|
||||
from django.utils.timezone import now
|
||||
|
||||
from awx.main.models import * # noqa
|
||||
from awx.main.socket import Socket
|
||||
@ -21,16 +20,23 @@ class FactCacheReceiver(object):
|
||||
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=now()))
|
||||
host_collection.insert(facts)
|
||||
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:
|
||||
if 'host' not in message or 'facts' not in message or 'date_key' not in message:
|
||||
continue
|
||||
self.process_fact_message(message)
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import sys
|
||||
import datetime
|
||||
from ansible import constants as C
|
||||
from ansible.cache.base import BaseCacheModule
|
||||
|
||||
@ -45,6 +46,7 @@ class CacheModule(BaseCacheModule):
|
||||
|
||||
# This is the local tower zmq connection
|
||||
self._tower_connection = C.CACHE_PLUGIN_CONNECTION
|
||||
self.date_key = datetime.datetime.utcnow()
|
||||
try:
|
||||
self.context = zmq.Context()
|
||||
self.socket = self.context.socket(zmq.REQ)
|
||||
@ -57,7 +59,7 @@ class CacheModule(BaseCacheModule):
|
||||
return {} # Temporary until we have some tower retrieval endpoints
|
||||
|
||||
def set(self, key, value):
|
||||
self.socket.send_json(dict(host=key, facts=value))
|
||||
self.socket.send_json(dict(host=key, facts=value, date_key=self.date_key))
|
||||
self.socket.recv()
|
||||
|
||||
def keys(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user