def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-H', '--host', default=os.environ.get('RQ_REDIS_HOST', 'localhost'), help="Redis host") parser.add_argument('-p', '--port', default=int(os.environ.get('RQ_REDIS_PORT', 6379)), type=int, help="Redis port number") parser.add_argument('-d', '--db', default=int(os.environ.get('RQ_REDIS_DB', 0)), type=int, help="Redis database") parser.add_argument('-P', '--password', default=os.environ.get('RQ_REDIS_PASSWORD'), help="Redis password") parser.add_argument('--url', '-u', default=os.environ.get('RQ_REDIS_URL') , help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument('-i', '--interval', default=60, type=int , help="How often the scheduler checks for new jobs to add to the \ queue (in seconds).") parser.add_argument('--path', default='.', help='Specify the import path.') parser.add_argument('--pid', help='A filename to use for the PID file.', metavar='FILE') args = parser.parse_args() if args.path: sys.path = args.path.split(':') + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, 'w') as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) else: connection = Redis(args.host, args.port, args.db, args.password) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run()
def main(): parser = argparse.ArgumentParser(description="Runs RQ scheduler") parser.add_argument("-H", "--host", default="localhost", help="Redis host") parser.add_argument("-p", "--port", default=6379, type=int, help="Redis port number") parser.add_argument("-d", "--db", default=0, type=int, help="Redis database") parser.add_argument("-P", "--password", default=None, help="Redis password") args = parser.parse_args() connection = Redis(args.host, args.port, args.db, args.password) scheduler = Scheduler(connection=connection) scheduler.run()
def main(): parser = argparse.ArgumentParser(description="Runs RQ scheduler") parser.add_argument( "-b", "--burst", action="store_true", default=False, help="Run in burst mode (quit after all work is done)" ) parser.add_argument("-H", "--host", default=os.environ.get("RQ_REDIS_HOST", "localhost"), help="Redis host") parser.add_argument( "-p", "--port", default=int(os.environ.get("RQ_REDIS_PORT", 6379)), type=int, help="Redis port number" ) parser.add_argument("-d", "--db", default=int(os.environ.get("RQ_REDIS_DB", 0)), type=int, help="Redis database") parser.add_argument("-P", "--password", default=os.environ.get("RQ_REDIS_PASSWORD"), help="Redis password") parser.add_argument("--verbose", "-v", action="store_true", default=False, help="Show more output") parser.add_argument( "--url", "-u", default=os.environ.get("RQ_REDIS_URL"), help="URL describing Redis connection details. \ Overrides other connection arguments if supplied.", ) parser.add_argument( "-i", "--interval", default=60.0, type=float, help="How often the scheduler checks for new jobs to add to the \ queue (in seconds, can be floating-point for more precision).", ) parser.add_argument("--path", default=".", help="Specify the import path.") parser.add_argument("--pid", help="A filename to use for the PID file.", metavar="FILE") args = parser.parse_args() if args.path: sys.path = args.path.split(":") + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, "w") as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) else: connection = Redis(args.host, args.port, args.db, args.password) if args.verbose: level = "DEBUG" else: level = "INFO" setup_loghandlers(level) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run(burst=args.burst)
def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-H', '--host', default='localhost', help="Redis host") parser.add_argument('-p', '--port', default=6379, type=int, help="Redis port number") parser.add_argument('-d', '--db', default=0, type=int, help="Redis database") parser.add_argument('-P', '--password', default=None, help="Redis password") parser.add_argument('-i', '--interval', default=60, type=int , help="How often the scheduler checks for new jobs to add to the \ queue (in seconds).") args = parser.parse_args() connection = Redis(args.host, args.port, args.db, args.password) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run()
def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-b', '--burst', action='store_true', default=False, help='Run in burst mode (quit after all work is done)') parser.add_argument('-H', '--host', default=os.environ.get('RQ_REDIS_HOST', 'localhost'), help="Redis host") parser.add_argument('-p', '--port', default=int(os.environ.get('RQ_REDIS_PORT', 6379)), type=int, help="Redis port number") parser.add_argument('-d', '--db', default=int(os.environ.get('RQ_REDIS_DB', 0)), type=int, help="Redis database") parser.add_argument('-P', '--password', default=os.environ.get('RQ_REDIS_PASSWORD'), help="Redis password") parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output') parser.add_argument('--quiet', action='store_true', default=False, help='Show less output') parser.add_argument('--url', '-u', default=os.environ.get('RQ_REDIS_URL') , help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument('-i', '--interval', default=60.0, type=float , help="How often the scheduler checks for new jobs to add to the \ queue (in seconds, can be floating-point for more precision).") parser.add_argument('--path', default='.', help='Specify the import path.') parser.add_argument('--pid', help='A filename to use for the PID file.', metavar='FILE') parser.add_argument('-j', '--job-class', help='Custom RQ Job class') parser.add_argument('-q', '--queue-class', help='Custom RQ Queue class') args = parser.parse_args() if args.path: sys.path = args.path.split(':') + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, 'w') as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) else: connection = Redis(args.host, args.port, args.db, args.password) if args.verbose: level = 'DEBUG' elif args.quiet: level = 'WARNING' else: level = 'INFO' setup_loghandlers(level) scheduler = Scheduler(connection=connection, interval=args.interval, job_class=args.job_class, queue_class=args.queue_class) scheduler.run(burst=args.burst)
class Scheduler(object): JN = 1 def __init__(self): from rq_scheduler.scheduler import Scheduler self.scheduler = Scheduler(connection=redis, interval=60) def check_jobs(self): now = datetime.utcnow() self.my_jobs = self.scheduler.get_jobs(with_times=True) ## check correct n of jobs if len(self.my_jobs) < self.JN: return False ## check expired jobs for j, t in self.my_jobs: if t <= now: return False return True def delete_jobs(self): for el in self.my_jobs: self.scheduler.cancel(el[0]) self.my_jobs = [] def create_jobs(self): # version and docs grab date = datetime.utcnow() + timedelta(seconds=15) job = self.scheduler.schedule( scheduled_time=date, func=update_base, interval=3600, repeat=None ) self.my_jobs.append((job.id, date)) # extensions grab date = datetime.utcnow() + timedelta(seconds=45) job = self.scheduler.schedule( scheduled_time=date, func=update_extensions, interval=7200, repeat=None ) self.my_jobs.append((job.id, date)) def run(self): self.check_jobs() self.delete_jobs() self.create_jobs() self.scheduler.run()
def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-H', '--host', default='localhost', help="Redis host") parser.add_argument('-p', '--port', default=6379, type=int, help="Redis port number") parser.add_argument('-d', '--db', default=0, type=int, help="Redis database") parser.add_argument('-P', '--password', default=None, help="Redis password") parser.add_argument('--url', '-u', default=None , help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument('-i', '--interval', default=60, type=int , help="How often the scheduler checks for new jobs to add to the \ queue (in seconds).") parser.add_argument('--path', default='.', help='Specify the import path.') args = parser.parse_args() if args.path: sys.path = args.path.split(':') + sys.path if args.url is not None: connection = Redis.from_url(args.url) else: connection = Redis(args.host, args.port, args.db, args.password) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run()
def run_scheduler(): """Initializes a rq scheduler.""" conn = Redis( host=app.config['RQ_DEFAULT_HOST'], port=app.config['RQ_DEFAULT_PORT'], db=0, password=app.config['RQ_DEFAULT_PASSWORD'] ) setup_loghandlers('INFO') scheduler = Scheduler(connection=conn, interval=60.0) for _ in xrange(10): try: scheduler.run() except ValueError as exc: if exc.message == 'There\'s already an active RQ scheduler': scheduler.log.info( 'An RQ scheduler instance is already running. Retrying in ' '%d seconds.', 10, ) time.sleep(10) else: raise exc
def main(): scheduler = Scheduler(connection=scheduler_conn, interval=10) scheduler.run()
def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-H', '--host', default=os.environ.get('RQ_REDIS_HOST', 'localhost'), help="Redis host") parser.add_argument('-p', '--port', default=int(os.environ.get('RQ_REDIS_PORT', 6379)), type=int, help="Redis port number") parser.add_argument('-d', '--db', default=int(os.environ.get('RQ_REDIS_DB', 0)), type=int, help="Redis database") parser.add_argument('-P', '--password', default=os.environ.get('RQ_REDIS_PASSWORD'), help="Redis password") parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output') parser.add_argument('--url', '-u', default=os.environ.get('RQ_REDIS_URL'), help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument( '-i', '--interval', default=60.0, type=float, help="How often the scheduler checks for new jobs to add to the \ queue (in seconds, can be floating-point for more precision).") parser.add_argument('--path', default='.', help='Specify the import path.') parser.add_argument('--pid', help='A filename to use for the PID file.', metavar='FILE') args = parser.parse_args() if args.path: sys.path = args.path.split(':') + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, 'w') as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) elif os.getenv('REDISTOGO_URL'): redis_url = os.getenv('REDISTOGO_URL') if not redis_url: raise RuntimeError('Set up Redis To Go first.') urlparse.uses_netloc.append('redis') url = urlparse.urlparse(redis_url) connection = Redis(host=url.hostname, port=url.port, db=0, password=url.password) elif args.host is not None: connection = Redis(args.host, args.port, args.db, args.password) else: connection = Redis() if args.verbose: level = 'DEBUG' else: level = 'INFO' setup_loghandlers(level) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run()
def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-b', '--burst', action='store_true', default=False, help='Run in burst mode (quit after all work is done)') parser.add_argument('-H', '--host', default=os.environ.get('RQ_REDIS_HOST', 'localhost'), help="Redis host") parser.add_argument('-p', '--port', default=int(os.environ.get('RQ_REDIS_PORT', 6379)), type=int, help="Redis port number") parser.add_argument('-d', '--db', default=int(os.environ.get('RQ_REDIS_DB', 0)), type=int, help="Redis database") parser.add_argument('-P', '--password', default=os.environ.get('RQ_REDIS_PASSWORD'), help="Redis password") parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output') parser.add_argument('--quiet', '-q', action='store_true', default=False, help='Show less output') parser.add_argument('--url', '-u', default=os.environ.get('RQ_REDIS_URL'), help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument( '-i', '--interval', default=60.0, type=float, help="How often the scheduler checks for new jobs to add to the \ queue (in seconds, can be floating-point for more precision).") parser.add_argument('--path', default='.', help='Specify the import path.') parser.add_argument('--pid', help='A filename to use for the PID file.', metavar='FILE') parser.add_argument('-j', '--job-class', help='Custom RQ Job class') parser.add_argument('-q', '--queue-class', help='Custom RQ Queue class') args = parser.parse_args() if args.path: sys.path = args.path.split(':') + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, 'w') as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) else: connection = Redis(args.host, args.port, args.db, args.password) if args.verbose: level = 'DEBUG' elif args.quiet: level = 'WARNING' else: level = 'INFO' setup_loghandlers(level) scheduler = Scheduler(connection=connection, interval=args.interval, job_class=args.job_class, queue_class=args.queue_class) scheduler.run(burst=args.burst)
def main(): # set up minimal argparser to get -c option parser = argparse.ArgumentParser( add_help=False # help will be picked up later when we redfine parser ) parser.add_argument('-c', "--config", help='Use an rq config file') args, remaining_argv = parser.parse_known_args() # config, pass 1: read environment vars config = { KEY_HOST : os.environ.get('RQ_REDIS_HOST', 'localhost'), KEY_PORT : int(os.environ.get('RQ_REDIS_PORT', 6379)), KEY_DB : int(os.environ.get('RQ_REDIS_DB', 0)), KEY_PASSWORD : os.environ.get('RQ_REDIS_PASSWORD'), KEY_URL : os.environ.get('RQ_REDIS_URL') } # config, pass 2: read config file if args.config: # bit of a hack, this, but does allow helpers.read_config_file to work... sys.path.insert( 0, os.path.dirname(os.path.realpath(args.config)) ) rq_config = helpers.read_config_file( args.config ) # map rq settings to our own config dict config[KEY_URL] = rq_config.get("REDIS_URL", config[KEY_URL]) config[KEY_HOST] = rq_config.get("REDIS_HOST", config[KEY_HOST]) config[KEY_PORT] = rq_config.get("REDIS_PORT", config[KEY_PORT]) config[KEY_DB] = rq_config.get("REDIS_DB", config[KEY_DB]) config[KEY_PASSWORD] = rq_config.get("REDIS_PASSWORD",config[KEY_PASSWORD]) # config, pass 3: read commandline args. overwrites any other config. parser = argparse.ArgumentParser( parents=[parser] # inherit from existing parser ) parser.add_argument('-H', '--host', default=config[KEY_HOST], help="Redis host") parser.add_argument('-p', '--port', default=config[KEY_PORT], type=int, help="Redis port number") parser.add_argument('-d', '--db', default=config[KEY_DB], type=int, help="Redis database") parser.add_argument('-P', '--password', default=config[KEY_PASSWORD], help="Redis password") parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output') parser.add_argument('--url', '-u', default=config[KEY_URL] , help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument('-i', '--interval', default=60.0, type=float , help="How often the scheduler checks for new jobs to add to the \ queue (in seconds, can be floating-point for more precision).") parser.add_argument('--path', default='.', help='Specify the import path.') parser.add_argument('--pid', help='A filename to use for the PID file.', metavar='FILE') args = parser.parse_args( remaining_argv ) if args.path: sys.path = args.path.split(':') + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, 'w') as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) else: connection = Redis(args.host, args.port, args.db, args.password) if args.verbose: level = 'DEBUG' else: level = 'INFO' setup_loghandlers(level) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run()
def main(): conn = redis.from_url(os.getenv('REDISCLOUD_URL', 'redis://localhost:6379')) scheduler = Scheduler(connection=conn, interval=30) scheduler.run()
import logging import os import redis from rq.utils import ColorizingStreamHandler from rq_scheduler.scheduler import Scheduler as RQScheduler redis_url = os.getenv('REDISTO_URL', 'redis://localhost:6379') conn = redis.from_url(redis_url) def setup_loghandlers(level='INFO'): logger = logging.getLogger('scheduler') if not logger.handlers: logger.setLevel(level) formatter = logging.Formatter(fmt='%(asctime)s %(message)s', datefmt='%H:%M:%S') handler = ColorizingStreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) setup_loghandlers() logger = logging.getLogger('scheduler') if __name__ == '__main__': scheduler = RQScheduler(connection=conn) logger.info('Starting scheduler') scheduler.run()
def scheduler(): """Run rq-scheduler""" redis_client = get_rq_redis_client() scheduler = Scheduler(connection=redis_client) schedule(scheduler, redis_client, config) scheduler.run()
def main(): parser = argparse.ArgumentParser(description='Runs RQ scheduler') parser.add_argument('-H', '--host', default=os.environ.get('RQ_REDIS_HOST', 'localhost'), help="Redis host") parser.add_argument('-p', '--port', default=int(os.environ.get('RQ_REDIS_PORT', 6379)), type=int, help="Redis port number") parser.add_argument('-d', '--db', default=int(os.environ.get('RQ_REDIS_DB', 0)), type=int, help="Redis database") parser.add_argument('-P', '--password', default=os.environ.get('RQ_REDIS_PASSWORD'), help="Redis password") parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output') parser.add_argument('--url', '-u', default=os.environ.get('RQ_REDIS_URL'), help='URL describing Redis connection details. \ Overrides other connection arguments if supplied.') parser.add_argument('-i', '--interval', default=60.0, type=float, help="How often the scheduler checks for new jobs to add to the \ queue (in seconds, can be floating-point for more precision).") parser.add_argument('--path', default='.', help='Specify the import path.') parser.add_argument('--pid', help='A filename to use for the PID file.', metavar='FILE') args = parser.parse_args() if args.path: sys.path = args.path.split(':') + sys.path if args.pid: pid = str(os.getpid()) filename = args.pid with open(filename, 'w') as f: f.write(pid) if args.url is not None: connection = Redis.from_url(args.url) elif os.getenv('REDISTOGO_URL'): redis_url = os.getenv('REDISTOGO_URL') if not redis_url: raise RuntimeError('Set up Redis To Go first.') urlparse.uses_netloc.append('redis') url = urlparse.urlparse(redis_url) connection = Redis(host=url.hostname, port=url.port, db=0, password=url.password) elif args.host is not None: connection = Redis(args.host, args.port, args.db, args.password) else: connection = Redis() if args.verbose: level = 'DEBUG' else: level = 'INFO' setup_loghandlers(level) scheduler = Scheduler(connection=connection, interval=args.interval) scheduler.run()