コード例 #1
0
    def process_images(self, linked_task=None):
        """
        Starts the Celery task to import this RawImageUploadSession.

        Parameters
        ----------
        linked_task
            A celery task that will be executed on success of the build_images
            task, with 1 keyword argument: upload_session_pk=self.pk
        """

        # Local import to avoid circular dependency
        from grandchallenge.cases.tasks import build_images

        RawImageUploadSession.objects.filter(pk=self.pk).update(
            status=RawImageUploadSession.REQUEUED)

        kwargs = {"upload_session_pk": self.pk}
        workflow = build_images.signature(kwargs=kwargs)

        if linked_task is not None:
            linked_task.kwargs.update(kwargs)
            workflow |= linked_task

        on_commit(workflow.apply_async)
コード例 #2
0
def run_algorithm_job_for_inputs(*, job_pk, upload_pks):
    start_jobs = execute_algorithm_job_for_inputs.signature(
        kwargs={"job_pk": job_pk}, immutable=True)
    if upload_pks:
        image_tasks = group(
            # Chords and iterator groups are broken in Celery, send a list
            # instead, see https://github.com/celery/celery/issues/7285
            [
                chain(
                    build_images.signature(
                        kwargs={"upload_session_pk": upload_pk},
                        immutable=True),
                    add_images_to_component_interface_value.signature(
                        kwargs={
                            "component_interface_value_pk": civ_pk,
                            "upload_session_pk": upload_pk,
                        },
                        immutable=True,
                    ),
                ) for civ_pk, upload_pk in upload_pks.items()
            ])
        start_jobs = chord(image_tasks, start_jobs).on_error(
            on_job_creation_error.s(job_pk=job_pk))

    on_commit(start_jobs.apply_async)
コード例 #3
0
def run_algorithm_job_for_inputs(*, job_pk, upload_pks):
    start_jobs = execute_algorithm_job_for_inputs.signature(
        kwargs={"job_pk": job_pk}, immutable=True)
    if upload_pks:
        image_tasks = group(
            chain(
                build_images.signature(kwargs={"upload_session_pk": upload_pk},
                                       immutable=True),
                add_images_to_component_interface_value.signature(
                    kwargs={
                        "component_interface_value_pk": civ_pk,
                        "upload_session_pk": upload_pk,
                    },
                    immutable=True,
                ),
            ) for civ_pk, upload_pk in upload_pks.items())
        start_jobs = chord(image_tasks, start_jobs).on_error(
            group(on_job_creation_error.s(job_pk=job_pk)))

    on_commit(start_jobs.apply_async)
コード例 #4
0
def start_archive_item_update_tasks(
    archive_item_pk, civ_pks_to_add, civ_pks_to_remove, upload_pks
):
    tasks = update_archive_item_values.signature(
        kwargs={
            "archive_item_pk": archive_item_pk,
            "civ_pks_to_add": civ_pks_to_add,
            "civ_pks_to_remove": civ_pks_to_remove,
        },
        immutable=True,
    )

    if len(upload_pks) > 0:
        image_tasks = group(
            # Chords and iterator groups are broken in Celery, send a list
            # instead, see https://github.com/celery/celery/issues/7285
            [
                chain(
                    build_images.signature(
                        kwargs={"upload_session_pk": upload_pk}
                    ),
                    add_images_to_component_interface_value.signature(
                        kwargs={
                            "component_interface_value_pk": civ_pk,
                            "upload_session_pk": upload_pk,
                        },
                        immutable=True,
                    ),
                )
                for civ_pk, upload_pk in upload_pks.items()
            ]
        )
        tasks = group(image_tasks, tasks)

    with transaction.atomic():
        on_commit(tasks.apply_async)
コード例 #5
0
    def form_valid(self, form):  # noqa: C901
        def create_upload(image_files):
            upload_session = RawImageUploadSession.objects.create(
                creator=self.request.user)
            upload_session.user_uploads.set(image_files)
            return upload_session.pk

        upload_pks = {}
        civ_pks_to_remove = set()
        civ_pks_to_add = set()

        for slug, value in form.cleaned_data.items():
            if value is None:
                continue

            ci = ComponentInterface.objects.get(slug=slug)
            civ = self.archive_item.values.filter(interface=ci).first()

            if civ:
                if civ.value == value:
                    continue
                civ_pks_to_remove.add(civ.pk)

            if ci.kind in InterfaceKind.interface_type_image():
                if value:
                    civ = ComponentInterfaceValue.objects.create(interface=ci)
                    civ_pks_to_add.add(civ.pk)
                    upload_pks[civ.pk] = create_upload(value)
            elif ci.kind in InterfaceKind.interface_type_file():
                civ = ComponentInterfaceValue.objects.create(interface=ci)
                value.copy_object(to_field=civ.file)
                civ.full_clean()
                civ.save()
                value.delete()
                civ_pks_to_add.add(civ.pk)
            else:
                civ = ci.create_instance(value=value)
                civ_pks_to_add.add(civ.pk)

        tasks = update_archive_item_values.signature(
            kwargs={
                "archive_item_pk": self.archive_item.pk,
                "civ_pks_to_add": list(civ_pks_to_add),
                "civ_pks_to_remove": list(civ_pks_to_remove),
            },
            immutable=True,
        )

        if len(upload_pks) > 0:
            image_tasks = group(
                chain(
                    build_images.signature(
                        kwargs={"upload_session_pk": upload_pk}),
                    add_images_to_component_interface_value.signature(
                        kwargs={
                            "component_interface_value_pk": civ_pk,
                            "upload_session_pk": upload_pk,
                        },
                        immutable=True,
                    ),
                ) for civ_pk, upload_pk in upload_pks.items())
            tasks = chord(image_tasks, tasks)

        on_commit(tasks.apply_async)

        return HttpResponseRedirect(
            reverse(
                "archives:items-list",
                kwargs={"slug": self.kwargs["slug"]},
            ))