mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 08:48:46 -03:30
Handle unifying the datetime value as a key that we can update on the
tower side
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import NoArgsCommand
|
||||||
from django.utils.timezone import now
|
|
||||||
|
|
||||||
from awx.main.models import * # noqa
|
from awx.main.models import * # noqa
|
||||||
from awx.main.socket import Socket
|
from awx.main.socket import Socket
|
||||||
@@ -21,16 +20,23 @@ class FactCacheReceiver(object):
|
|||||||
def process_fact_message(self, message):
|
def process_fact_message(self, message):
|
||||||
host = message['host']
|
host = message['host']
|
||||||
facts = message['facts']
|
facts = message['facts']
|
||||||
|
date_key = message['date_key']
|
||||||
host_db = self.client.host_facts
|
host_db = self.client.host_facts
|
||||||
host_collection = host_db[host]
|
host_collection = host_db[host]
|
||||||
facts.update(dict(tower_host=host, datetime=now()))
|
facts.update(dict(tower_host=host, datetime=date_key))
|
||||||
host_collection.insert(facts)
|
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):
|
def run_receiver(self):
|
||||||
with Socket('fact_cache', 'r') as facts:
|
with Socket('fact_cache', 'r') as facts:
|
||||||
for message in facts.listen():
|
for message in facts.listen():
|
||||||
print("Message received: " + str(message))
|
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
|
continue
|
||||||
self.process_fact_message(message)
|
self.process_fact_message(message)
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.cache.base import BaseCacheModule
|
from ansible.cache.base import BaseCacheModule
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ class CacheModule(BaseCacheModule):
|
|||||||
|
|
||||||
# This is the local tower zmq connection
|
# This is the local tower zmq connection
|
||||||
self._tower_connection = C.CACHE_PLUGIN_CONNECTION
|
self._tower_connection = C.CACHE_PLUGIN_CONNECTION
|
||||||
|
self.date_key = datetime.datetime.utcnow()
|
||||||
try:
|
try:
|
||||||
self.context = zmq.Context()
|
self.context = zmq.Context()
|
||||||
self.socket = self.context.socket(zmq.REQ)
|
self.socket = self.context.socket(zmq.REQ)
|
||||||
@@ -57,7 +59,7 @@ class CacheModule(BaseCacheModule):
|
|||||||
return {} # Temporary until we have some tower retrieval endpoints
|
return {} # Temporary until we have some tower retrieval endpoints
|
||||||
|
|
||||||
def set(self, key, value):
|
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()
|
self.socket.recv()
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user