better logging
This commit is contained in:
parent
bc0fa52461
commit
697a6ade5e
|
@ -4,6 +4,7 @@ import datetime
|
|||
import json
|
||||
import urllib2
|
||||
import base64
|
||||
import logging
|
||||
|
||||
from DateTime.DateTime import DateTime
|
||||
|
||||
|
@ -19,6 +20,8 @@ from themis.datatypes.address import Address
|
|||
|
||||
from utils import UtilityView
|
||||
|
||||
log = logging.getLogger('Plone')
|
||||
|
||||
class SyncFromThemis(UtilityView):
|
||||
src_url = 'http://localhost:8081/themis'
|
||||
|
||||
|
@ -40,12 +43,16 @@ class SyncFromThemis(UtilityView):
|
|||
|
||||
timestamp = self.request.form.get('timestamp')
|
||||
objects = self.request.form.get('objects', '').split(',')
|
||||
log.info('sync: start [%r] [%r]' % (timestamp, objects))
|
||||
for object in ('deputies', 'ministries', 'commissions', 'documents',
|
||||
'blocked_documents'):
|
||||
if not 'all' in objects:
|
||||
if not object in objects:
|
||||
continue
|
||||
getattr(self, 'sync_'+object)(timestamp)
|
||||
t0 = time.time()
|
||||
result = getattr(self, 'sync_'+object)(timestamp)
|
||||
duration = time.time() - t0
|
||||
log.info('sync: %-14s: %6s [%s]' % (object, result, format_duration(duration)))
|
||||
|
||||
return 'OK'
|
||||
|
||||
|
@ -152,7 +159,7 @@ class SyncFromThemis(UtilityView):
|
|||
try:
|
||||
obj = getattr(self.deputies_folder, author.split(':', 1)[1])
|
||||
except AttributeError:
|
||||
print 'failed to get author', author
|
||||
log.warn('failed to get author %r' % author)
|
||||
return None
|
||||
obj_intid = self.intids.getId(obj)
|
||||
return obj_intid
|
||||
|
@ -161,12 +168,12 @@ class SyncFromThemis(UtilityView):
|
|||
qs = ''
|
||||
if timestamp:
|
||||
qs = '?timestamp=%s' % timestamp
|
||||
print 'loading documents list from', self.src_url
|
||||
log.info('loading documents list from %s' % self.src_url)
|
||||
documents = json.load(self.urlopen('%s/@@listDocuments%s' % (self.src_url, qs)))
|
||||
print 'done'
|
||||
log.info('loading documents list from %s -> DONE' % self.src_url)
|
||||
|
||||
for count, document_url in enumerate(documents):
|
||||
print 'loading', document_url
|
||||
log.info('loading %s' % document_url)
|
||||
data = json.load(self.urlopen('%s/json' % document_url))
|
||||
|
||||
new_id = data.get('id')
|
||||
|
@ -353,18 +360,19 @@ class SyncFromThemis(UtilityView):
|
|||
if count % 100 == 0:
|
||||
transaction.commit()
|
||||
|
||||
print 'documents done'
|
||||
log.info('documents done')
|
||||
return count
|
||||
|
||||
def sync_blocked_documents(self, timestamp=None):
|
||||
qs = ''
|
||||
if timestamp:
|
||||
qs = '?timestamp=%s' % timestamp
|
||||
print 'loading blocked documents list from', self.src_url
|
||||
log.info('loading blocked documents list from %s' % self.src_url)
|
||||
documents = json.load(self.urlopen('%s/@@listBlockedDocuments%s' % (self.src_url, qs)))
|
||||
print 'done'
|
||||
log.info('loading blocked documents list from %s -> DONE' % self.src_url)
|
||||
|
||||
for count, document_url in enumerate(documents):
|
||||
print 'loading', document_url
|
||||
log.info('loading %s' % document_url)
|
||||
data = json.load(self.urlopen('%s/json' % document_url))
|
||||
|
||||
new_id = data.get('id')
|
||||
|
@ -385,4 +393,4 @@ class SyncFromThemis(UtilityView):
|
|||
if count % 100 == 0:
|
||||
transaction.commit()
|
||||
|
||||
print 'blocked documents done'
|
||||
log.info('blocked documents done')
|
||||
|
|
Reference in New Issue