Ejemplo n.º 1
0
    def startremoteimport(self, request):
        '''Download a channel's database from the main curation server, and then
        download its content.

        '''
        TASKTYPE = "remoteimport"

        if "channel_id" not in request.data:
            raise serializers.ValidationError(
                "The 'channel_id' field is required.")

        channel_id = request.data['channel_id']

        # ensure the requested channel_id can be found on the central server, otherwise error
        status = requests.head(
            get_content_database_file_url(channel_id)).status_code
        if status == 404:
            raise Http404(
                _("The requested channel does not exist on the content server."
                  ))

        task_id = async (_networkimport,
                         channel_id,
                         group=TASKTYPE,
                         progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id),
                                 task_type=TASKTYPE,
                                 task_id=task_id)

        return Response(resp)
Ejemplo n.º 2
0
def fetch(task_id):
    """
    Returns the processed task
    :param task_id: the task name or uuid
    :type task_id: str or uuid
    :return: the full task object
    :rtype: Task
    """
    return Task.get_task(task_id)
Ejemplo n.º 3
0
    def cleartask(self, request):
        '''
        Clears a task with its task id given in the task_id parameter.
        '''

        if 'task_id' not in request.data:
            raise serializers.ValidationError("The 'task_id' field is required.")

        task_id = request.data['task_id']

        # Attempt to kill running task.
        Task.get_task(task_id).kill_running_task()

        # we need to decrypt tasks first in the ORM queue to get their real task_id. Hence why this python-side task_id retrieval and deletion.
        [taskitem.delete() for taskitem in OrmQ.objects.all() if taskitem.task()["id"] == task_id]

        Task.objects.filter(pk=task_id).delete()

        return Response({})
Ejemplo n.º 4
0
    def cleartask(self, request):
        '''
        Clears a task with its task id given in the task_id parameter.
        '''

        if 'task_id' not in request.data:
            raise serializers.ValidationError(
                "The 'task_id' field is required.")

        task_id = request.data['task_id']

        # Attempt to kill running task.
        Task.get_task(task_id).kill_running_task()

        # we need to decrypt tasks first in the ORM queue to get their real task_id. Hence why this python-side task_id retrieval and deletion.
        [
            taskitem.delete() for taskitem in OrmQ.objects.all()
            if taskitem.task()["id"] == task_id
        ]

        Task.objects.filter(pk=task_id).delete()

        return Response({})
Ejemplo n.º 5
0
    def startremoteimport(self, request):
        '''Download a channel's database from the main curation server, and then
        download its content.

        '''
        TASKTYPE = "remoteimport"

        if "channel_id" not in request.data:
            raise serializers.ValidationError("The 'channel_id' field is required.")

        task_id = async(_networkimport, request.data['channel_id'], group=TASKTYPE, progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id), task_type=TASKTYPE, task_id=task_id)

        return Response(resp)
Ejemplo n.º 6
0
    def startlocalexport(self, request):
        '''
        Export a channel to a local drive, and copy content to the drive.

        '''
        TASKTYPE = "localexport"

        if "drive_id" not in request.data:
            raise serializers.ValidationError("The 'drive_id' field is required.")

        task_id = async(_localexport, request.data['drive_id'], group=TASKTYPE, progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id), task_type=TASKTYPE, task_id=task_id)

        return Response(resp)
Ejemplo n.º 7
0
    def startlocalimport(self, request):
        '''
        Import a channel from a local drive, and copy content to the local machine.

        '''
        # Importing django/running setup because Windows...
        TASKTYPE = "localimport"

        if "drive_id" not in request.data:
            raise serializers.ValidationError("The 'drive_id' field is required.")

        task_id = make_async_call(_localimport, request.data['drive_id'], group=TASKTYPE, progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id), task_type=TASKTYPE, task_id=task_id)

        return Response(resp)
Ejemplo n.º 8
0
def fetch(task_id, wait=0, cached=Conf.CACHED):
    """
    Return the processed task.

    :param task_id: the task name or uuid
    :type task_id: str or uuid
    :param wait: the number of milliseconds to wait for a result
    :type wait: int
    :param bool cached: run this against the cache backend
    :return: the full task object
    :rtype: Task
    """
    if cached:
        return fetch_cached(task_id, wait)
    start = time()
    while True:
        t = Task.get_task(task_id)
        if t:
            return t
        if (time() - start) * 1000 >= wait >= 0:
            break
        sleep(0.01)
Ejemplo n.º 9
0
    def startlocalexport(self, request):
        '''
        Export a channel to a local drive, and copy content to the drive.

        '''
        TASKTYPE = "localexport"

        if "drive_id" not in request.data:
            raise serializers.ValidationError(
                "The 'drive_id' field is required.")

        task_id = async (_localexport,
                         request.data['drive_id'],
                         group=TASKTYPE,
                         progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id),
                                 task_type=TASKTYPE,
                                 task_id=task_id)

        return Response(resp)
Ejemplo n.º 10
0
def fetch(task_id, wait=0, cached=Conf.CACHED):
    """
    Return the processed task.

    :param task_id: the task name or uuid
    :type task_id: str or uuid
    :param wait: the number of milliseconds to wait for a result
    :type wait: int
    :param bool cached: run this against the cache backend
    :return: the full task object
    :rtype: Task
    """
    if cached:
        return fetch_cached(task_id, wait)
    start = time.time()
    while True:
        t = Task.get_task(task_id)
        if t:
            return t
        if (time.time() - start) * 1000 >= wait >= 0:
            break
        time.sleep(0.01)
Ejemplo n.º 11
0
    def startlocalimport(self, request):
        '''
        Import a channel from a local drive, and copy content to the local machine.

        '''
        # Importing django/running setup because Windows...
        TASKTYPE = "localimport"

        if "drive_id" not in request.data:
            raise serializers.ValidationError(
                "The 'drive_id' field is required.")

        task_id = make_async_call(_localimport,
                                  request.data['drive_id'],
                                  group=TASKTYPE,
                                  progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id),
                                 task_type=TASKTYPE,
                                 task_id=task_id)

        return Response(resp)
Ejemplo n.º 12
0
    def startremoteimport(self, request):
        '''Download a channel's database from the main curation server, and then
        download its content.

        '''
        TASKTYPE = "remoteimport"

        if "channel_id" not in request.data:
            raise serializers.ValidationError("The 'channel_id' field is required.")

        channel_id = request.data['channel_id']

        # ensure the requested channel_id can be found on the central server, otherwise error
        status = requests.head(get_content_database_file_url(channel_id)).status_code
        if status == 404:
            raise Http404(_("The requested channel does not exist on the content server."))

        task_id = async(_networkimport, channel_id, group=TASKTYPE, progress_updates=True)

        # attempt to get the created Task, otherwise return pending status
        resp = _task_to_response(Task.get_task(task_id), task_type=TASKTYPE, task_id=task_id)

        return Response(resp)
Ejemplo n.º 13
0
 def retrieve(self, request, pk=None):
     task = _task_to_response(Task.get_task(pk))
     return Response(task)
Ejemplo n.º 14
0
        # Import here to avoid circular imports.
        from django_q.tasks import async
        from django_q.models import Task
        data = json.loads(request.body.decode('utf-8'))

        if "id" not in data:
            raise serializers.ValidationError("The 'id' field is required.")

        channel_id = data['id']

        task_id = async(_importchannel, channel_id, group=TASKTYPE, progress_updates=True)

        # id status metadata

        # wait for the task instance to be saved first before continuing
        taskobj = Task.get_task(task_id)
        if taskobj:             # the task object has been saved!
            resp = _task_to_response(taskobj)
        else:                   # task object hasn't been saved yet, fake the response for now
            resp = {
                "type": TASKTYPE,
                "status": "PENDING",
                "percentage": 0,
                "metadata": {},
                "id": task_id,
            }

        return Response(resp)

    @list_route(methods=['post'])
    def startlocalimportchannel(self, request):
Ejemplo n.º 15
0
    def retrieve(self, request, pk=None):
        from django_q.models import Task

        task = _task_to_response(Task.get_task(pk))
        return Response(task)
Ejemplo n.º 16
0
    def retrieve(self, request, pk=None):
        from django_q.models import Task

        task = _task_to_response(Task.get_task(pk))
        return Response(task)
Ejemplo n.º 17
0
 def retrieve(self, request, pk=None):
     task = _task_to_response(Task.get_task(pk))
     return Response(task)
Ejemplo n.º 18
0
        # Import here to avoid circular imports.
        from django_q.tasks import async
        from django_q.models import Task
        data = json.loads(request.body.decode('utf-8'))

        if "id" not in data:
            raise serializers.ValidationError("The 'id' field is required.")

        channel_id = data['id']

        task_id = async(_importchannel, channel_id, group=TASKTYPE, progress_updates=True)

        # id status metadata

        # wait for the task instance to be saved first before continuing
        taskobj = Task.get_task(task_id)
        if taskobj:             # the task object has been saved!
            resp = _task_to_response(taskobj)
        else:                   # task object hasn't been saved yet, fake the response for now
            resp = {
                "type": TASKTYPE,
                "status": "PENDING",
                "percentage": 0,
                "metadata": {},
                "id": task_id,
            }

        return Response(resp)

    @list_route(methods=['post'])
    def startlocalimportchannel(self, request):