def handleReadTimed (proxy_id, datestring): """ Reads all metadata updated after timestamp and returns them in json format :param proxy_id: :param datestring: ISO8601 datestring :return: """ #TODO: handle validation and exceptions locker = proxy_lock.ProxyLocker (retries=3, wait=5) try: timestamp = validate_fields.extractTimestampFromISO8601(datestring) except: timestamp = None meta_dict = {} for meta_id in buildReadList(proxy_id, timestamp): meta_dict [meta_id] = locker.performLocked(assembleMetaJson, proxy_id, meta_id) if timestamp is not None: returnstamp = None else: returnstamp = time.strftime("%Y-%m-%dT%H:%M:%SZ",timestamp) template = TemplatesModels.model_response_read customfields = { "token" : proxy_id, "time" : returnstamp, "data": { "upserts" : meta_dict, "delete" : [] } } responsemsg = createMessageFromTemplate(template, **customfields) #NOTE that the read happens as a HTTPResponse, so we only return the json for Django to send back, rather than handling the HTTPConnection ourselves return json.dumps(responsemsg)
def handleReadFull (proxy_id): """ Reads everything in the specified proxy and returns it as a json message :param proxy_id: :return: """ #note: just a modified version of handleReadTimed #TODO: handle validation and exceptions locker = proxy_lock.ProxyLocker (retries=3, wait=5) meta_dict = {} for meta_id in buildReadList(proxy_id): #meta_dict [meta_id] = locker.performLocked(assembleMetaJson, proxy_id, meta_id) try: meta_dict[meta_id] = locker.performLocked(handleReadMeta, proxy_id, meta_id) except RuntimeProxyException as ex: print "Exception encountered: %s" % ex.message print "Read performed" template = TemplatesModels.model_response_read_full customfields = { "token" : proxy_id, "data": { "upserts" : meta_dict, "delete" : [] } } responsemsg = createMessageFromTemplate(template, **customfields) print "RESULT: %s features " % len(responsemsg) #NOTE that the read happens as a HTTPResponse, so we only return the json for Django to send back, rather than handling the HTTPConnection ourselves return json.dumps(responsemsg)