def main():
	setup = settings.beanstalkd

	try:
		c = Connection(*setup['connection'])
		c.watchMany(setup['tubes']['watch'])
		c.ignoreMany(setup['tubes']['ignore'])
		logger.info("Watching tubes {}".format(c.watching()))
		logger.info("Ignoring tubes {}".format(setup['tubes']['ignore']))
	except ConnectionRefusedError as e:
		logger.error(e)
		send_alert(e)
		sys.exit(1)
	except SocketError as e:
		logger.error(e)
		send_alert(e)
		sys.exit(1)

	b = Backup()

	while True:

		if c.isBroken():
			try:
				c.reconnect()
				c.watchMany(setup['tubes']['watch'])
				c.ignoreMany(setup['tubes']['ignore'])
			except ConnectionRefusedError as e:
				logger.error(e)
				send_alert(e)
				sys.exit(3)
			except SocketError as e:
				logger.error(e)
				send_alert(e)
				sys.exit(4)

		job = c.reserve(setup['timeout'])

		if job:
			archiverJob = json.loads(job.body, cls=JobDecoder)
			if b.run(archiverJob):
				logger.info("Success backuping file {} from {}".format(archiverJob.filename, archiverJob.host))
				job.delete()
			else:
				logger.info("Error while backuping file {} from {}".format(archiverJob.filename, archiverJob.host))
				job.release()

		sleep(setup['timeout'])
Пример #2
0
try:
    c = Connection(*setup['connection'])
    c.watchMany(setup['tubes']['watch'])
    c.ignoreMany(setup['tubes']['ignore'])
    print("Watching tubes {}".format(c.watching()))
    print("Ignoring tubes {}".format(setup['tubes']['ignore']))
except ConnectionRefusedError as e:
    print(e)
    send_alert(e)
    sys.exit(1)
except SocketError as e:
    print(e)
    send_alert(e)
    sys.exit(1)

b = Backup()

while True:

    if c.isBroken():
        try:
            c.reconnect()
            c.watchMany(setup['tubes']['watch'])
            c.ignoreMany(setup['tubes']['ignore'])
        except ConnectionRefusedError as e:
            print(e)
            send_alert(e)
            sys.exit(3)
        except SocketError as e:
            print(e)
            send_alert(e)