# -*- coding: utf-8 -*-
# $Id: SpoolerQueue.py 1603 2011-10-10 12:33:02Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
#
import os
import sys
import pickle
class SpoolerQueue:
"""
A thread safe simple queue which stores queue items using pickle.
"""
"""
Sets the name of the file for saving the entries and initializes the
queue as a dictionary.
"""
# initialize the queue
# try to load a queue from file
"""
Reads the whole queue from a file.
"""
try:
#log.debug("loading queue from '%s'" % (self._filename,))
except Exception, e:
"""
Saves the whole queue to a file.
"""
try:
except Exception, e:
"""
Returns whether or not the queue is empty.
"""
"""
Returns the number of objects in the queue.
"""
"""
Adds a single instance of QueueItem to the queue.
@param: obj an object to enqueue
"""
"Illegal Argument, item must be an instance of class QueueItem"
#log.debug('adding new item to queue: %s' % id)
"Item '%s' already exists in queue" % (id,)
# store changes in file on disk
return id
"""
Returns the first item or the item for the given id and removes it
from the queue.
@return: a QueueItem
"""
try:
#log.debug('id: %s' % id)
if not id:
else:
#log.debug("pop item '%s'" % (id,))
# store changes in file on disk
return item
except KeyError, e :
return None
# -- some tests ---------------------------------------------------------------
#if __name__ == "__main__":
# """
# """
# from lib.data.BackendJob import BackendJob
#
# data = {}
# data['backend'] = "checker_val"
# data["submission"] = "student_val"
# data["model"] = "sample_val"
# data["comparator"] = "comp_val"
#
# data2 = {}
# data2['backend'] = "checker_val2"
# data2["submission"] = "student_val2"
# data2["model"] = "sample_val2"
# data2["comparator"] = "comp_val2"
#
# j = BackendJob(data)
# j2 = BackendJob(data2)
#
# q = SpoolerQueue(os.path.join(os.path.dirname(__file__),
# '..', '..', 'var', 'test.fs'))
#
# print q.getSize()
#
# q.enqueue(j)
# q.enqueue(j2)
#
# print q.getSize()