Scott Baker | 2290b05 | 2014-05-08 10:28:22 -0700 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import base64 |
| 4 | import traceback |
| 5 | from django.db.models import F, Q |
Scott Baker | 76a840e | 2015-02-11 21:38:09 -0800 | [diff] [blame] | 6 | from xos.config import Config |
Scott Baker | 2290b05 | 2014-05-08 10:28:22 -0700 | [diff] [blame] | 7 | from observer.syncstep import SyncStep |
| 8 | from core.models import Service |
| 9 | from requestrouter.models import RequestRouterService |
| 10 | from util.logger import Logger, logging |
| 11 | |
| 12 | parentdir = os.path.join(os.path.dirname(__file__),"..") |
| 13 | sys.path.insert(0,parentdir) |
| 14 | |
| 15 | from rrlib import RequestRouterLibrary |
| 16 | |
| 17 | logger = Logger(level=logging.INFO) |
| 18 | |
| 19 | class SyncRequestRouterService(SyncStep, RequestRouterLibrary): |
| 20 | provides=[RequestRouterService] |
| 21 | requested_interval=0 |
| 22 | |
| 23 | def __init__(self, **args): |
| 24 | SyncStep.__init__(self, **args) |
| 25 | RequestRouterLibrary.__init__(self) |
| 26 | |
| 27 | def fetch_pending(self): |
| 28 | try: |
| 29 | ret = RequestRouterService.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) |
| 30 | return ret |
| 31 | except Exception, e: |
| 32 | traceback.print_exc() |
| 33 | return None |
| 34 | |
| 35 | def sync_record(self, rr_service): |
| 36 | try: |
| 37 | print "syncing service!" |
| 38 | logger.info("sync'ing rr_service %s" % str(rr_service)) |
| 39 | self.gen_slice_file(rr_service) |
| 40 | rr_service.save() |
| 41 | return True |
| 42 | except Exception, e: |
| 43 | traceback.print_exc() |
| 44 | return False |
| 45 | |
| 46 | |