Beispiel #1
0
	def __init__(self, host, port, db, notification_name, process_name):
		self.host = host
		self.port = port
		self.db = db
		self.notification_name = notification_name
		self.process_name = process_name
		self.pid = os.getpid()
		self.last_id = None
		self.last_version = None
		self.dump_last_id = None
		self.dump_last_version = None
		self.writerlock = Lock()
		self.cblock = Lock()
		dir = '/var/lib/pacifica/metanotification/poke'
		try_mkdir(dir)
		self.socketreader = socketreader.SocketReader("%s/%s_%s" %(dir, notification_name, process_name), self._poked)
		self.statefile = "%s/%s_%s.json" %(dir, self.notification_name, self.process_name)
		while True:
			try:
				self.last_tag_init()
				if self.last_version == None:
					self.last_version = notification_version_get(host, port, db, notification_name)
				self.collection_name = collection_name_get(None, notification_name, self.last_version)
				if self.last_id == None:
					self.last_id = 1 #Initied always to one.
				print "Last ID: %s" %(self.last_id)
				break
			except pymongo.errors.AutoReconnect, e:
				print "Mongo disconnect. %s. Trying again in 10 seconds..." %(e)
				time.sleep(10)
Beispiel #2
0
	def last_tag_init(self):
		dir = '/var/lib/pacifica/metanotification/last'
		try_mkdir(dir)
		self.statefile = "%s/%s_%s.json" %(dir, self.notification_name, self.process_name)
		try:
			file = open(self.statefile, 'r')
			j = json.load(file)
			self.last_id = j['last_id']
			self.last_version = j['last_version']
			file.close()
		except IOError, e:
			if e.errno != errno.ENOENT:
				raise
Beispiel #3
0
	if parser.values.channel == "":
		sys.stderr.write("You must specify a channel with -c\n")
		sys.exit(-1)
	config = getconfig_notification(parser.values.channel)
	if parser.values.host == "":
		try:
			parser.values.host = config.notification.hostname
		except Exception, e:
			raise e
			sys.stderr.write("You must specify a MongoDB host with -n\n")
			sys.exit(-1)
	if parser.values.port == -1:
		parser.values.port = config.notification.port
	if parser.values.socket == "":
		parser.values.socket = writer_socket_get(parser.values.channel)
		try_mkdir(os.path.dirname(parser.values.socket))

def main():
	parser = OptionParser()
        add_usage(parser)
        add_options(parser)
        parser.parse_args()
        check_options(parser)
	try:
    		os.mkfifo(parser.values.socket)
	except OSError, e:
		if e.errno != errno.EEXIST:
			raise
	socket = os.open(parser.values.socket, os.O_RDONLY | os.O_NONBLOCK)
	socket_write = os.open(parser.values.socket, os.O_WRONLY | os.O_NONBLOCK)
	fl = fcntl.fcntl(socket, fcntl.F_GETFL)
    if parser.values.channel == "":
        sys.stderr.write("You must specify a channel with -c\n")
        sys.exit(-1)
    config = getconfig_notification(parser.values.channel)
    if parser.values.host == "":
        try:
            parser.values.host = config.notification.hostname
        except Exception, e:
            raise e
            sys.stderr.write("You must specify a MongoDB host with -n\n")
            sys.exit(-1)
    if parser.values.port == -1:
        parser.values.port = config.notification.port
    if parser.values.socket == "":
        parser.values.socket = writer_socket_get(parser.values.channel)
        try_mkdir(os.path.dirname(parser.values.socket))


def main():
    parser = OptionParser()
    add_usage(parser)
    add_options(parser)
    parser.parse_args()
    check_options(parser)
    try:
        os.mkfifo(parser.values.socket)
    except OSError, e:
        if e.errno != errno.EEXIST:
            raise
    socket = os.open(parser.values.socket, os.O_RDONLY | os.O_NONBLOCK)
    socket_write = os.open(parser.values.socket, os.O_WRONLY | os.O_NONBLOCK)