blob: 546b45d648afb23f6cc04e807bc3297e2dec71ba [file] [log] [blame]
Scott Baker2290b052014-05-08 10:28:22 -07001import os
2import sys
3import base64
4import traceback
5from django.db.models import F, Q
6from planetstack.config import Config
7from observer.syncstep import SyncStep
8from core.models import Service
9from requestrouter.models import RequestRouterService
10from util.logger import Logger, logging
11
12parentdir = os.path.join(os.path.dirname(__file__),"..")
13sys.path.insert(0,parentdir)
14
15from rrlib import RequestRouterLibrary
16
17logger = Logger(level=logging.INFO)
18
19class 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