当前位置: 首页>>代码示例>>Python>>正文


Python celery.task方法代码示例

本文整理汇总了Python中celery.task方法的典型用法代码示例。如果您正苦于以下问题:Python celery.task方法的具体用法?Python celery.task怎么用?Python celery.task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在celery的用法示例。


在下文中一共展示了celery.task方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _send_update

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def _send_update(task_id, status, secret, virtual_host='/', extra=None):
    """
    Sends a status update about the running task.

    id: The task ID.
    status: The new status for the task. One of 'running', 'finished' or 'failed'.
    """
    task_args = {'status': status}
    if extra:
        task_args['extra'] = extra
    logger.info("Updating task=%s status to %s", task_id, status)
    with app.connection() as new_connection:
        # We need to send on the main virtual host, not whatever host we're currently
        # connected to.
        new_connection.virtual_host = virtual_host
        app.send_task(
            'apps.web.tasks.update_submission',
            args=(task_id, task_args, secret),
            connection=new_connection,
            queue="submission-updates",
        ) 
开发者ID:yuantailing,项目名称:ctw-baseline,代码行数:23,代码来源:worker.py

示例2: update

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def update(self):
        self.sqli_obj.scan_status = json.loads(get('{}/scan/{}/status'.format(self.api_url, self.task_id)).text)[
            'status']
        try:
            self.sqli_obj.scan_log = json.loads(get('{}/scan/{}/log'.format(self.api_url, self.task_id)).text)['log'][
                -1]
            self.sqli_obj.scan_data = json.loads(get('{}/scan/{}/data'.format(self.api_url, self.task_id)).text)['data']
        except:
            pass
        if self.sqli_obj.scan_status != 'terminated':
            self.update.apply_async((self,), countdown=60)
        else:
            get('{}/task/{}/delete'.format(self.api_url, self.task_id))
            self.sqli_obj.vulnerable = bool(self.sqli_obj.scan_data)
            if self.sqli_obj.vulnerable:
                send_mail('发现注入',
                          "Url:\t{}\n注入点:\t{}".format(self.sqli_obj.target_url,
                                                      self.sqli_obj.scan_data[0]['value'][0]['parameter']),
                          self.mail_from,
                          self.mail_to, fail_silently=False)
        self.sqli_obj.save() 
开发者ID:0xbug,项目名称:SQLiScanner,代码行数:23,代码来源:tasks.py

示例3: upload_zip

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def upload_zip(self, index, *args, **kwargs):
    """
    Celery task which unzips files in a .zip archive and ignores folder
    structure, taking each file to the top level of the output folder.
    """
    self.index = index
    self.index.status = "STARTED"
    self.index.save()
    if not os.path.exists(self.index.data_folder):
        os.mkdir(self.index.data_folder)
    with zipfile.ZipFile(self.index.uploaded_data.name) as archive:
        for x in archive.namelist():
            filename = os.path.basename(x).decode("utf-8")
            if not filename:
                continue
            source = archive.open(x)
            target = open(os.path.join(self.index.data_folder, filename), "wb")
            with source, target:
                shutil.copyfileobj(source, target)
    return "success" 
开发者ID:nasa-jpl-memex,项目名称:memex-explorer,代码行数:22,代码来源:file_tasks.py

示例4: cache_lock

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def cache_lock(lock_id, oid):
    # source: https://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html
    # we use the database cache backend here, this is not as good as using memcached,
    # but should be good enough for the use case
    timeout_at = monotonic() + LOCK_EXPIRE - 3
    # cache.add fails if the key already exists
    status = caches['locks'].add(lock_id, oid, LOCK_EXPIRE)
    try:
        yield status
    finally:
        if monotonic() < timeout_at and status:
            # don't release the lock if we exceeded the timeout
            # to lessen the chance of releasing an expired lock
            # owned by someone else
            # also don't release the lock if we didn't acquire it
            caches['locks'].delete(lock_id) 
开发者ID:helfertool,项目名称:helfertool,代码行数:18,代码来源:tasks.py

示例5: odt_template

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def odt_template(fn, ctx, page_size="A4"):
    inp = zipfile.ZipFile(fn, "r" )
    outs = StringIO.StringIO()
    output = zipfile.ZipFile(outs, "a" )
    for zi in inp.filelist:
            out = inp.read(zi.filename)
            if zi.filename == 'content.xml': # waut for the only interesting file
                    # un-escape the quotes (in filters etc.)
                    t = Template(out.replace( '&quot;', '"' ))
                    out = t.render(ctx).encode('utf8')
            if page_size=="US" and zi.filename == 'styles.xml' :
                    t = Template(out.replace( 'style:page-layout-properties fo:page-width="297mm" fo:page-height="210.01mm"', 'style:page-layout-properties fo:page-width="279.4mm" fo:page-height="215.9mm"' ))
                    out = t.render(ctx).encode('utf8')
            output.writestr(zi.filename, out)
    output.close()
    content=outs.getvalue()
    return content

#from celery.task.control import inspect
#i = inspect()
#i.scheduled()
#i.active() 
开发者ID:norn,项目名称:bctip,代码行数:24,代码来源:tasks.py

示例6: start

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def start(self):
        self.task_id = json.loads(get('{}/task/new'.format(self.api_url)).text)['taskid']
        self.sqli_obj.task_id = self.task_id
        logging.info(json.dumps(self.scan_options))
        res = json.loads(post('{}/option/{}/set'.format(self.api_url, self.task_id), data=json.dumps(self.scan_options),
                              headers=self.headers).text)
        if res['success']:
            post('{}/scan/{}/start'.format(self.api_url, self.task_id), data=self.target_url,
                 headers=self.headers)
            self.update.apply_async((self,), countdown=10)
        else:
            self.delete.delay(self) 
开发者ID:0xbug,项目名称:SQLiScanner,代码行数:14,代码来源:tasks.py

示例7: delete

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def delete(self):
        get('{}/task/{}/delete'.format(self.api_url, self.task_id))
        self.sqli_obj.delete() 
开发者ID:0xbug,项目名称:SQLiScanner,代码行数:5,代码来源:tasks.py

示例8: on_success

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def on_success(self, *args, **kwargs):
        """
        If the upload task succeeded, change index status to UPLOAD SUCCESS.

        If we are in deployment mode, create the corresponding index after the task
        has succeeded.
        """
        self.index.status = "UPLOAD SUCCESS"
        self.index.num_files = len(os.listdir(self.index.get_dumped_data_path()))
        self.index.save()
        create_index.delay(self.index) 
开发者ID:nasa-jpl-memex,项目名称:memex-explorer,代码行数:13,代码来源:file_tasks.py

示例9: deploy_rules

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def deploy_rules(probe_name):
    job = Job.create_job('deploy_rules', probe_name)
    probe = Probe.get_by_name(probe_name)
    if probe is None:
        job.update_job("Error - probe is None - param id not set : " + str(probe_name), 'Error')
        return {"message": "Error - probe is None - param id not set : " + str(probe_name)}
    if probe.subtype:
        my_class = getattr(importlib.import_module(probe.type.lower() + ".models"), probe.subtype)
    else:
        my_class = getattr(importlib.import_module(probe.type.lower() + ".models"), probe.type)
    probe = my_class.get_by_name(probe_name)
    try:
        response_deploy_rules = probe.deploy_rules()
        response_reload = probe.reload()
        if response_deploy_rules['status'] and response_reload['status']:
            job.update_job('Deployed rules successfully', 'Completed')
        elif not response_deploy_rules['status']:
            if 'errors' in response_deploy_rules:
                job.update_job('Error during the rules deployed',
                               'Error: ' + str(probe_name) + " - " +
                               repr_instance.repr(response_deploy_rules['errors']))
                logger.error("task - deploy_rules : " + str(probe_name) + " - " + str(response_deploy_rules['errors']))
                return {"message": "Error for probe " + str(probe.name) + " to deploy rules",
                        "exception": str(response_deploy_rules['errors'])}
            else:
                job.update_job('Error during the rules deployed', 'Error: ' + str(probe_name))
                logger.error("task - deploy_rules : " + str(probe_name))
                return {"message": "Error for probe " + str(probe.name) + " to deploy rules", "exception": " "}
        elif not response_reload['status']:
            job.update_job('Error during the rules deployed',
                           'Error: ' + str(probe_name) + repr_instance.repr(response_reload['errors']))
            logger.error("task - deploy_rules : " + str(probe_name) + " - " + str(response_reload['errors']))
            return {"message": "Error for probe " + str(probe.name) + " to deploy rules",
                    "exception": str(response_reload['errors'])}
    except Exception as e:
        logger.exception('Error during the rules deployed')
        job.update_job(repr_instance.repr(e), 'Error')
        send_notification("Probe " + str(probe.name), str(e))
        return {"message": "Error for probe " + str(probe.name) + " to deploy rules", "exception": str(e)}
    return {"message": "Probe " + probe.name + ' deployed rules successfully'} 
开发者ID:treussart,项目名称:ProbeManager,代码行数:42,代码来源:tasks.py

示例10: reload_probe

# 需要导入模块: import celery [as 别名]
# 或者: from celery import task [as 别名]
def reload_probe(probe_name):
    job = Job.create_job('reload_probe', probe_name)
    probe = Probe.get_by_name(probe_name)
    if probe is None:
        job.update_job("Error - probe is None - param id not set : " + str(probe_name), 'Error')
        return {"message": "Error - probe is None - param id not set : " + str(probe_name)}
    if probe.subtype:
        my_class = getattr(importlib.import_module(probe.type.lower() + ".models"), probe.subtype)
    else:
        my_class = getattr(importlib.import_module(probe.type.lower() + ".models"), probe.type)
    probe = my_class.get_by_name(probe_name)
    if probe.scheduled_rules_deployment_enabled:
        try:
            response = probe.reload()
            if response['status']:
                job.update_job("task - reload_probe : " + str(probe_name), 'Completed')
                logger.info("task - reload_probe : " + str(probe_name))
                return {"message": "Probe " + str(probe.name) + " reloaded successfully"}
            else:
                job.update_job(repr_instance.repr(response['errors']), 'Error')
                return {"message": "Error for probe " + str(probe.name) + " to reload",
                        "exception": str(response['errors'])}
        except Exception as e:
            logger.exception("Error for probe to reload")
            job.update_job(repr_instance.repr(e), 'Error')
            send_notification("Probe " + str(probe.name), str(e))
            return {"message": "Error for probe " + str(probe.name) + " to reload", "exception": str(e)}
    else:
        job.update_job("Not enabled to reload", 'Error')
        send_notification("Probe " + str(probe.name), "Not enabled to reload")
        return {"message": probe.name + " not enabled to reload"} 
开发者ID:treussart,项目名称:ProbeManager,代码行数:33,代码来源:tasks.py


注:本文中的celery.task方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。