예제 #1
0
파일: schedule.py 프로젝트: ESA-MInv/minv
    def handle_authorized(self, *args, **options):
        task = options["task"]
        if task not in ("harvest", "export", "backup"):
            raise CommandError("Invalid task name '%s'" % task)

        mode = options.pop("mode")

        # get the duration when the task shall be scheduled
        if options.get("now"):
            interval = timedelta(0.0)
        elif options.get("in"):
            interval = parse_duration(options["in"])
        else:
            # get the harvesting interval from collection configuration
            interval = None

        if task == "harvest":
            items = self.handle_harvest(mode, interval, *args, **options)
        elif task == "export":
            items = self.handle_export(mode, interval, *args, **options)
        else:
            raise CommandError("Unknown task '%s'." % task)

        # inform the daemon
        try:
            if items:
                schedule_many(items)
            else:
                send_reload_schedule()
        except Exception as exc:
            if options.get("traceback"):
                raise
            raise CommandError(
                "Failed to send 'reload' message to daemon. Error was '%s'" %
                exc)
예제 #2
0
def harvest_view(request, mission, file_type):
    """ Django view function to inspect ongoing harvests and trigger new ones.
    """
    collection = models.Collection.objects.get(mission=mission,
                                               file_type=file_type)

    urls = request.GET.getlist("url")
    if urls:
        items = []
        for url in urls:
            items.append(("harvest", now(), {
                "mission": mission,
                "file_type": file_type,
                "url": url,
                "reschedule": False
            }))

        try:
            schedule_many(items)
        except:
            messages.error(
                request, "Failed to harvest URL%s %s for collection %s. "
                "Is the harvesting daemon running?" %
                ("s" if len(urls) > 1 else "", ", ".join(urls), collection))
        else:
            messages.info(
                request, "Harvesting URL%s %s for collection %s" %
                ("s" if len(urls) > 1 else "", ", ".join(urls), collection))
    else:
        messages.warning(request,
                         "Please select at least one harvesting location.")

    return redirect("inventory:collection:detail",
                    mission=mission,
                    file_type=file_type)
예제 #3
0
파일: views.py 프로젝트: ESA-MInv/minv
def harvest_view(request, mission, file_type):
    """ Django view function to inspect ongoing harvests and trigger new ones.
    """
    collection = models.Collection.objects.get(
        mission=mission, file_type=file_type
    )

    urls = request.GET.getlist("url")
    if urls:
        items = []
        for url in urls:
            items.append(("harvest", now(), {
                "mission": mission,
                "file_type": file_type,
                "url": url,
                "reschedule": False
            }))

        try:
            schedule_many(items)
        except:
            messages.error(request,
                "Failed to harvest URL%s %s for collection %s. "
                "Is the harvesting daemon running?" % (
                    "s" if len(urls) > 1 else "", ", ".join(urls), collection
                )
            )
        else:
            messages.info(request, "Harvesting URL%s %s for collection %s" % (
                "s" if len(urls) > 1 else "", ", ".join(urls), collection
            ))
    else:
        messages.warning(
            request, "Please select at least one harvesting location."
        )

    return redirect("inventory:collection:detail",
        mission=mission, file_type=file_type
    )
예제 #4
0
파일: schedule.py 프로젝트: ESA-MInv/minv
    def handle_authorized(self, *args, **options):
        task = options["task"]
        if task not in ("harvest", "export", "backup"):
            raise CommandError("Invalid task name '%s'" % task)

        mode = options.pop("mode")

        # get the duration when the task shall be scheduled
        if options.get("now"):
            interval = timedelta(0.0)
        elif options.get("in"):
            interval = parse_duration(options["in"])
        else:
            # get the harvesting interval from collection configuration
            interval = None

        if task == "harvest":
            items = self.handle_harvest(mode, interval, *args, **options)
        elif task == "export":
            items = self.handle_export(mode, interval, *args, **options)
        else:
            raise CommandError("Unknown task '%s'." % task)

        # inform the daemon
        try:
            if items:
                schedule_many(items)
            else:
                send_reload_schedule()
        except Exception as exc:
            if options.get("traceback"):
                raise
            raise CommandError(
                "Failed to send 'reload' message to daemon. Error was '%s'"
                % exc
            )