...
 
Commits (2)
......@@ -5,6 +5,7 @@ import config.env
from django.core.validators import ValidationError
from django.http import JsonResponse
from django.shortcuts import redirect
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View
from main.helpers import upload_data, get_base_url, lookup_job_file, get_request_user
......@@ -21,29 +22,21 @@ def get_link(jobid, dir, filename, request):
return '/'.join((get_base_url(request), "datastore", str(jobid), filename))
def job_response(job, request):
status = {0: 'new',
1: 'waiting',
2: 'running',
3: 'done',
4: 'archived',
5: 'deleted',
6: 'aborting'}
job_dir = job.data_dir
files = {f: get_link(job.id, job_dir, f, request) for f in os.listdir(job_dir)
if lookup_job_file(job.id, f)}
return {str(job.id): {'status': status[job.state],
'files': files
}
}
class APIJobView(JobAuthMixin, View):
def get(self, request, pk):
try:
job = Job.objects.get(id=pk)
return JsonResponse(job_response(job, request))
files = {}
for f in os.listdir(job.data_dir):
if lookup_job_file(job.id, f):
files[f] = get_link(job.id, job.data_dir, f, request)
response = {
job.id: files,
"status": job.get_state_display().lower(),
}
return JsonResponse(response)
except Job.DoesNotExist as e:
log.error("Job not found %s", str(e))
return JsonResponse({'error': 'Job not found'}, status=404)
......@@ -90,7 +83,14 @@ def jobs(request):
job.state = Job.WAITING
job.save()
return JsonResponse(job_response(job, request))
no_domain_url = reverse('api:job', kwargs={'pk':job.id})
response = {
"avg_time": 0, # legacy, not relevant anymore
"id" : job.id,
"url" : get_base_url(request)+no_domain_url,
}
return JsonResponse(response)
class APIDownloadView(JobAuthMixin, View):
......