本文整理汇总了Python中datastore.DataStore.updateRecordAsInProcess方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.updateRecordAsInProcess方法的具体用法?Python DataStore.updateRecordAsInProcess怎么用?Python DataStore.updateRecordAsInProcess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastore.DataStore
的用法示例。
在下文中一共展示了DataStore.updateRecordAsInProcess方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyzeBWFFile
# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import updateRecordAsInProcess [as 别名]
def analyzeBWFFile(dbPath, identifier = 1):
logging = DefaultLogger()
loopcount = 0
datastore = DataStore(dbPath)
try:
while True:
sleep(60+random.randint(1,10))
if loopcount % 20 == 0:
logging.debug('bwf analyzer loop {} is active...'.format(identifier))
loopcount += 1
if not os.path.exists(dbPath):
logging.debug('Acquire File: can not find database at path')
return
record = None
#if daisy is not up then just wait until it is
if isDaisyUp() == False:
logging.debug('Daisy does not appear to be up')
continue
#get a lock on the file
lock = lockWithFile()
try:
lock.acquire(timeout=-1)
if lock.i_am_locking():
record = datastore.oneRecordReadyForProcessing()
if record != None:
logging.debug('process {} is acquiring the lock'.format(identifier))
datastore.updateRecordAsInProcess(record.id)
lock.release()
except Exception as e:
pass
if record == None:
continue
filePath = record.fileName
#lets check that is has a genuine Daisy Number
if getDaisyNumber(os.path.basename(filePath)) == None:
errorBox = configurationOptions().defaultPathStructure()['errorBox']
errorBox = os.path.expanduser(errorBox)
sendProcessFailureMessage({'subject':'BWF Error: file added that has no DANumber', 'message':'A file, %s, was deposited that does not have a Daisy Number' % (os.path.basename(filePath))})
#move to errorBox
try:
print "Moving file %s into %s" % (filePath, errorBox)
newPath = pathAfterSafelyMovingFileToDestinationFolder(filePath, errorBox)
except Exception as e:
logging.debug('Analyze File: Error moving file')
info = '''This should not happen as pathAfterSafelyMovingFileToDestinationFolder should create a unique name that avoids any collisions, otherwise the file has been moved'''
logging.debug(info)
info = 'There was a problem moving the file into into the errorBox for: ' + os.path.basename(filePath)
info = info + '\n' + 'This will require manual intervention as the occurrence is unique.'
sendProcessFailureMessage({'subject':'BWF Error', 'message':info})
logging.debug(info)
datastore.updateRecordAsNotHavingADaisyNumber(record.id)
continue
#lets look up metadata before we even proceed, if can't get the metadata we don't want to analyze files
dataTuple = retrieveDataForDANumber(os.path.basename(filePath), identifier)
logging.debug('Data for {} Before: {}'.format(os.path.basename(filePath), dataTuple))
if dataTuple == None:
#ok, lets send an email that will be sent at a maximum of 1 per 4 hours
result = "Process Error: Daisy Information not Available:" + e.message
sendPeriodicFailureMessage(result)
logging.debug('A Periodic Failure Message attempt was made.')
continue
result = None
resultObject = None
vendor = dataTuple[0]
comments = dataTuple[1]
status = dataTuple[2]
#once we have the metadata, lets examine the file
try:
logging.debug('Will examine %s in loop %s' % (filePath, str(identifier)))
resultObject = multiChannelBWFFileAnalysis(filePath)
result = json.dumps(resultObject)
if resultObject == None:
logging.debug('The analysis of the file %s is "None". This should not occur.' % (filePath))
raise Exception('The analysis of the file %s is "None". This should not occur.' % (filePath))
except Exception as e:
logging.debug('An exception occurred with %s in identifier %s.' % (filePath, str(identifier)))
#mark as error
datastore.updateRecordWithAnalysisError(record.id)
errorBox = configurationOptions().defaultPathStructure()['errorBox']
errorBox = os.path.expanduser(errorBox)
#send email
#.........这里部分代码省略.........