コード例 #1
0
 def get_model(cls):
     """
     Compute and save the model based on the model_uri attribute, and return
     it.
     """
     if not cls.model:
         cls.model = import_class(cls.model_uri)
     return cls.model
コード例 #2
0
 def get_from_ident(self, ident):
     """
     Take a string as returned by get_ident and return a job,
     based on the class representation and the job's pk from the ident
     """
     model_repr, job_pk = ident.split(':', 1)
     klass = import_class(model_repr)
     return klass.get(job_pk)
コード例 #3
0
ファイル: models.py プロジェクト: limpyd/redis-limpyd-jobs
 def get_from_ident(self, ident):
     """
     Take a string as returned by get_ident and return a job,
     based on the class representation and the job's pk from the ident
     """
     model_repr, job_pk = ident.split(':', 1)
     klass = import_class(model_repr)
     return klass.get(job_pk)
コード例 #4
0
ファイル: workers.py プロジェクト: limpyd/redis-limpyd-jobs
 def do_import(self, name, default):
     """
     Import the given option (use default values if not defined on command line)
     """
     try:
         option = getattr(self.options, name)
         if option:
             klass = import_class(option)
         else:
             klass = default
         setattr(self.options, name, klass)
     except Exception as e:
         self.parser.error('Unable to import "%s": %s' % (name, e))
コード例 #5
0
ファイル: workers.py プロジェクト: limpyd/redis-limpyd-jobs
 def do_import(self, name, default):
     """
     Import the given option (use default values if not defined on command line)
     """
     try:
         option = getattr(self.options, name)
         if option:
             klass = import_class(option)
         else:
             klass = default
         setattr(self.options, name, klass)
     except Exception as e:
         self.parser.error('Unable to import "%s": %s' % (name, e))
コード例 #6
0
ファイル: worker.py プロジェクト: limpyd/redis-limpyd-jobs
def main():
    # first options needed for this script itself (the rest will be ignored for now)
    option_list = (
        make_option(
            '--pythonpath',
            action='append',
            help=
            'A directory to add to the Python path, e.g. --pythonpath=/my/module'
        ),
        make_option(
            '--worker-config',
            dest='worker_config',
            help=
            'The worker config class to use, e.g. --worker-config=my.module.MyWorkerConfig, '
            'default to limpyd_jobs.workers.WorkerConfig'))

    # create a light option parser that ignore everything but basic options
    # defined above
    parser = LaxOptionParser(usage="%prog [options]", option_list=option_list)
    options, args = parser.parse_args(sys.argv[:])

    # if we have some pythonpaths, add them
    if options.pythonpath:
        sys.path[0:0] = parser.parse_python_paths(sys.argv[:])

    try:
        # still load the defaut config, needed to parse the worker_config option
        from limpyd_jobs.workers import WorkerConfig

        # by default use the default worker config
        worker_config_class = WorkerConfig

        # and try to load the one passed as argument if any
        if options.worker_config:
            from limpyd_jobs.utils import import_class
            worker_config_class = import_class(options.worker_config)

        # finally instantiate and run the worker
        worker_config = worker_config_class()
        worker_config.execute()
    except ImportError as e:
        parser.print_lax_help()
        parser.lax_error('No WorkerConfig found. You need to use --pythonpath '
                         'and/or --worker-config: %s' % str(e))
コード例 #7
0
ファイル: worker.py プロジェクト: limpyd/redis-limpyd-jobs
def main():
    # first options needed for this script itself (the rest will be ignored for now)
    option_list = (
        make_option('--pythonpath', action='append',
            help='A directory to add to the Python path, e.g. --pythonpath=/my/module'),
        make_option('--worker-config', dest='worker_config',
            help='The worker config class to use, e.g. --worker-config=my.module.MyWorkerConfig, '
                  'default to limpyd_jobs.workers.WorkerConfig')
    )

    # create a light option parser that ignore everything but basic options
    # defined above
    parser = LaxOptionParser(usage="%prog [options]", option_list=option_list)
    options, args = parser.parse_args(sys.argv[:])

    # if we have some pythonpaths, add them
    if options.pythonpath:
        sys.path[0:0] = parser.parse_python_paths(sys.argv[:])

    try:
        # still load the defaut config, needed to parse the worker_config option
        from limpyd_jobs.workers import WorkerConfig

        # by default use the default worker config
        worker_config_class = WorkerConfig

        # and try to load the one passed as argument if any
        if options.worker_config:
            from limpyd_jobs.utils import import_class
            worker_config_class = import_class(options.worker_config)

        # finally instantiate and run the worker
        worker_config = worker_config_class()
        worker_config.execute()
    except ImportError as e:
        parser.print_lax_help()
        parser.lax_error('No WorkerConfig found. You need to use --pythonpath '
                         'and/or --worker-config: %s' % str(e))