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


Python TaskSet.apply方法代码示例

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


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

示例1: test_named_taskset

# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply [as 别名]
 def test_named_taskset(self):
     prefix = 'test_named_taskset-'
     ts = TaskSet([return_True_task.subtask([1])])
     res = ts.apply(taskset_id=prefix + uuid())
     self.assertTrue(res.taskset_id.startswith(prefix))
开发者ID:Crowdbooster,项目名称:celery,代码行数:7,代码来源:test_tasks.py

示例2: run

# 需要导入模块: from celery.task import TaskSet [as 别名]
# 或者: from celery.task.TaskSet import apply [as 别名]
    def run(self, image_pk, destination_image_format, image_filepath, **kwargs):
        logger = self.get_logger(**kwargs)
        task_id = kwargs.get("task_id", "")
        logger.info("Starting request %s. image_pk: %s, destination_image_format: %s, image_filepath: %s" %
                (task_id,
                 image_pk,
                 destination_image_format,
                 image_filepath))
        try:
            # -----------------------------------------------------------------
            #   Resize the image into large, medium, and small images.
            # -----------------------------------------------------------------
            logger.info("Starting resize tasks...")
            resize_tasks = TaskSet(tasks=[
                ResizeImageTask.subtask((image_filepath, destination_image_format, Image.image_xlarge_dimensions)),
                ResizeImageTask.subtask((image_filepath, destination_image_format, Image.image_large_dimensions)),
                ResizeImageTask.subtask((image_filepath, destination_image_format, Image.image_medium_dimensions)),
                ResizeImageTask.subtask((image_filepath, destination_image_format, Image.image_small_dimensions)),
            ])
            resize_tasks_results = resize_tasks.apply()
            if not resize_tasks_results.successful():
                logger.error("Error during resize tasks, bail out.")
                for result in resize_tasks_results:
                    if result.exception:
                        raise result.exception
            resize_tasks_results = [unicode(result) for result in resize_tasks_results]
            logger.info("Resize tasks done:\n%s." % (pprint.pformat(resize_tasks_results), ))
            # -----------------------------------------------------------------

            # -----------------------------------------------------------------
            #   Save each of the resized images to S3.
            # -----------------------------------------------------------------
            logger.info("Starting save tasks...")
            save_tasks = TaskSet(tasks=[
                SaveImageDataTask.subtask((resize_tasks_results[0], image_pk, "image_xlarge")),
                SaveImageDataTask.subtask((resize_tasks_results[1], image_pk, "image_large")),
                SaveImageDataTask.subtask((resize_tasks_results[2], image_pk, "image_medium")),
                SaveImageDataTask.subtask((resize_tasks_results[3], image_pk, "image_small")),
            ])
            save_tasks_results = save_tasks.apply()
            if not save_tasks_results.successful():
                logger.error("Error during save tasks, bail out.")
                for result in save_tasks_results:
                    if result.exception:
                        raise result.exception
            #save_tasks_results = [result.get() for result in save_tasks_results]
            logger.info("Save tasks done\n%s" % (pprint.pformat(save_tasks_results), ))
            # -----------------------------------------------------------------

            # -----------------------------------------------------------------
            #   Mark the Image object as being uploaded.
            # -----------------------------------------------------------------
            image = Image.objects.get(pk=image_pk)
            image.is_uploaded = True
            image.save()

            # Clean up the original temporary file and the other three new
            # temporary files created for the resized images.
            for filepath in resize_tasks_results + [image_filepath]:
                logger.info("Deleting file %s" % filepath)
                os.remove(filepath)
            # -----------------------------------------------------------------
        except Exception, exc:
            logger.exception("HandleImageUploadTask_%s: unhandled exception." % (task_id, ))
            self.retry(exc=exc,
                       args=(image_pk, destination_image_format, image_filepath),
                       kwargs=kwargs)
开发者ID:asimihsan,项目名称:djangokata,代码行数:69,代码来源:tasks.py


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