Exemplo n.º 1
0
 def update(target, k, value):
     # for dict obj and dict value, merge the two, else set key or attribute
     if isinstance(value, dict):
         set_default(target, k, {})
         dict_merge(get_k(target, k), value)
     else:
         set_k(target, k, value)
Exemplo n.º 2
0
def update_from_config(vars=globals(), config_file=OMEGA_CONFIG_FILE):
    """
    update omegaml.defaults from configuration file

    :param vars: the variables to update
    :param config_file: the path to config.yml or a file object
    :return:
    """
    # override from configuration file
    userconfig = markup(config_file, default={}, msg='could not read config file {}')
    if isinstance(userconfig, dict):
        for k in [k for k in vars.keys() if k.startswith('OMEGA')]:
            value = userconfig.get(k, None) or vars[k]
            if isinstance(vars[k], dict):
                dict_merge(vars[k], value)
            else:
                vars[k] = value
    return vars
Exemplo n.º 3
0
    def queues(self):
        """ list queues

        Returns:
            dict of workers => list of queues

        See Also:
            celery Inspect.active_queues()
        """
        local_q = {gethostname(): [{'name': 'local', 'is_local': True}]}
        celery_qs = self._inspect.active_queues() or {}
        return dict_merge(local_q, celery_qs)
Exemplo n.º 4
0
    def task(self, name, **kwargs):
        """
        retrieve the task function from the celery instance

        Args:
            name (str): a registered celery task as ``module.tasks.task_name``
            kwargs (dict): routing keywords to CeleryTask.apply_async

        Returns:
            CeleryTask
        """
        taskfn = self.celeryapp.tasks.get(name)
        assert taskfn is not None, "cannot find task {name} in Celery runtime".format(
            **locals())
        kwargs = dict_merge(self._common_kwargs, dict(routing=kwargs))
        task = CeleryTask(taskfn, kwargs)
        self._require_kwargs = dict(routing={}, task={})
        return task