Пример #1
0
	def finalize (self, _commit) :
		_outcome_1 = self.operation.finalize (_commit)
		_outcome_2 = self.queue.finalize ()
		_outcome_3 = self.session.finalize (_commit)
		_outcome = outcomes.succeed_if_all (_outcome_1, _outcome_2, _outcome_3)
		if _outcome.succeeded :
			_outcome = self.succeeded (None)
		else :
			_outcome = self.failed ('failed while closing resources', errno.EIO)
		del self.session
		del self.queue
		del self.operation
		return _outcome
Пример #2
0
 def finalize(self):
     _outcome = None
     if _outcome is None:
         if not self.initialized:
             _outcome = outcomes.fail("queue not initialized")
     if _outcome is None:
         if len(self.operations) > 0:
             _outcome = outcomes.fail("queue has pending operations")
     if _outcome is None:
         try:
             self.queue.close()
             _outcome_1 = outcomes.succeed()
         except:
             _outcome_1 = outcomes.fail_with_traceback("queue failed to close BDB queue database")
         try:
             self.data.close()
             _outcome_2 = outcomes.succeed()
         except:
             _outcome_2 = outcomes.fail_with_traceback("queue failed to close BDB data database")
         try:
             self.recycle.close()
             _outcome_3 = outcomes.succeed()
         except:
             _outcome_3 = outcomes.fail_with_traceback("queue failed to close BDB data database")
         if self.session is not None:
             self.session.queues.remove(self)
         else:
             self.store.queues.remove(self)
         del self.store
         del self.session
         del self.name
         self.initialized = None
         del self.transaction
         del self.queue
         del self.data
         del self.recycle
         del self.operations
         _outcome = outcomes.succeed_if_all(_outcome_1, _outcome_2, _outcome_3)
     return _outcome
Пример #3
0
def enqueue (_arguments) :
	_outcome = None
	if _outcome is None :
		if len (_arguments) == 3 :
			_environment_path = _arguments[0]
			_queue_name = _arguments[1]
			_data_path = _arguments[2]
		else :
			_outcome = outcomes.fail ('enqueue invalid arguments')
	_stream = None
	_data = None
	if _outcome is None :
		try :
			_stream = file (_data_path, 'rb')
			_data = _stream.read (-1)
			_stream.close ()
		except :
			_outcome = outcomes.fail_with_traceback ('failed while opening or reading input file')
			if _stream is not None :
				try :
					_stream.close ()
				except :
					pass
	_store = None
	if _outcome is None :
		_store = store.Store (_environment_path)
		_outcome = _store.initialize ()
		if _outcome.succeeded :
			_outcome = None
	_session = None
	if _outcome is None :
		_outcome = _store.session ()
		if _outcome.succeeded :
			_session = _outcome.session
			_outcome = None
	_queue = None
	if _outcome is None :
		_outcome = _session.queue (_queue_name)
		if _outcome.succeeded :
			_queue = _outcome.queue
			_outcome = None
	_operation = None
	if _outcome is None :
		_outcome = _queue.enqueue ()
		if _outcome.succeeded :
			_operation = _outcome.operation
			_outcome = None
	if _outcome is None :
		_outcome = _operation.update (_data)
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = _operation.finalize (True)
		_operation = None
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = _queue.finalize ()
		_queue = None
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = _session.finalize (True)
		_session = None
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = outcomes.succeed ()
	_outcome_0 = _outcome
	if _operation is not None :
		_outcome_1 = _operation.finalize (False)
		_operation = None
	else :
		_outcome_1 = None
	if _queue is not None :
		_outcome_2 = _queue.finalize ()
		_queue = None
	else :
		_outcome_2 = None
	if _session is not None :
		_outcome_3 = _session.finalize (False)
		_session = None
	else :
		_outcome_3 = None
	if _store is not None :
		_outcome_4 = _store.finalize ()
		_store = None
	else :
		_outcome_4 = None
	_outcome = outcomes.succeed_if_all (_outcome_0, _outcome_1, _outcome_2, _outcome_3, _outcome_4)
	return _outcome
Пример #4
0
def dequeue (_arguments) :
	_outcome = None
	if _outcome is None :
		if len (_arguments) == 3 :
			_environment_path = _arguments[0]
			_queue_name = _arguments[1]
			_data_path = _arguments[2]
		else :
			_outcome = outcomes.fail ('dequeue invalid arguments')
	_store = None
	if _outcome is None :
		_store = store.Store (_environment_path)
		_outcome = _store.initialize ()
		if _outcome.succeeded :
			_outcome = None
	_session = None
	if _outcome is None :
		_outcome = _store.session ()
		if _outcome.succeeded :
			_session = _outcome.session
			_outcome = None
	_queue = None
	if _outcome is None :
		_outcome = _session.queue (_queue_name)
		if _outcome.succeeded :
			_queue = _outcome.queue
			_outcome = None
	_operation = None
	if _outcome is None :
		_outcome = _queue.dequeue ()
		if _outcome.succeeded :
			_operation = _outcome.operation
			_outcome = None
	_data = None
	if _outcome is None :
		_outcome = _operation.poll ()
		if _outcome.succeeded :
			if _outcome.prepared :
				_outcome = None
			else :
				_outcome = outcomes.fail ('dequeue unavailable data')
	if _outcome is None :
		_outcome = _operation.select ()
		if _outcome.succeeded :
			_data = _outcome.data
			_outcome = None
	_stream = None
	if _outcome is None :
		try :
			_stream = file (_data_path, 'wb')
			_stream.write (_data)
			_stream.close ()
		except :
			_outcome = outcomes.fail_with_traceback ('failed while opening or writing output file')
			if _stream is not None :
				try :
					_stream.close ()
				except :
					pass
	if _outcome is None :
		_outcome = _operation.finalize (True)
		_operation = None
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = _queue.finalize ()
		_queue = None
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = _session.finalize (True)
		_session = None
		if _outcome.succeeded :
			_outcome = None
	if _outcome is None :
		_outcome = outcomes.succeed ()
	_outcome_0 = _outcome
	if _operation is not None :
		_outcome_1 = _operation.finalize (False)
		_operation = None
	else :
		_outcome_1 = None
	if _queue is not None :
		_outcome_2 = _queue.finalize ()
		_queue = None
	else :
		_outcome_2 = None
	if _session is not None :
		_outcome_3 = _session.finalize (False)
		_session = None
	else :
		_outcome_3 = None
	if _store is not None :
		_outcome_4 = _store.finalize ()
		_store = None
	else :
		_outcome_4 = None
	_outcome = outcomes.succeed_if_all (_outcome_0, _outcome_1, _outcome_2, _outcome_3, _outcome_4)
	return _outcome