Skip to content

Commit

Permalink
Merge pull request #144 from mskcc/develop
Browse files Browse the repository at this point in the history
Version 1.7.0
  • Loading branch information
nikhil authored Feb 16, 2021
2 parents 0271f9b + a917013 commit fbff2fb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django==2.2.13
psycopg2==2.7.4
psycopg2==2.8.6
djangorestframework==3.9.4
markdown==3.1.1
django-filter==2.1.0
Expand All @@ -12,6 +12,6 @@ celery==4.4.7
cwltool==2.0.20200122124526
ruamel.yaml<=0.16.5
schema-salad==5.0.20200122085940
psycopg2-binary==2.8.4
psycopg2-binary==2.8.6
mock==4.0.2
dj-static==0.0.6
2 changes: 1 addition & 1 deletion ridgeback/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="1.5.0"
__version__="1.7.0"
11 changes: 11 additions & 0 deletions toil_orchestrator/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class Meta:
model = CommandLineToolJob
fields = '__all__'

class JobIdsSerializer(serializers.Serializer):
job_ids = serializers.ListField(
allow_empty=True,
child=serializers.UUIDField(required=True),
)


class JobSerializer(serializers.ModelSerializer):
status = serializers.SerializerMethodField()
Expand All @@ -105,6 +111,11 @@ class Meta:
message = MessageField(required=False)
commandlinetooljob_set = CommandLineToolJobSerializer(many=True, required=False)


class JobStatusSerializer(serializers.Serializer):
jobs = serializers.DictField()


class JobSubmitSerializer(JobSerializer):


Expand Down
10 changes: 7 additions & 3 deletions toil_orchestrator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_message(job_obj):
def set_message(job_obj, message_obj):
message_str = json.dumps(message_obj, sort_keys=True, indent=1, cls=DjangoJSONEncoder)
job_obj.message = message_str
job_obj.save()
job_obj.save(update_fields=['message'])


def update_message_by_key(job_obj, key, value):
Expand Down Expand Up @@ -98,8 +98,12 @@ def submit_jobs_to_lsf(self, job_id):
job.output_directory = job_output_dir
job.status = Status.PENDING
log_path = os.path.join(job_work_dir, 'lsf.log')
update_message_by_key(job,'log',log_path)
job.save()
update_message_by_key(job, 'log', log_path)
job.save(update_fields=['external_id',
'job_store_location',
'working_dir',
'output_directory',
'status'])


@shared_task(bind=True, max_retries=10, retry_jitter=True, retry_backoff=60)
Expand Down
25 changes: 23 additions & 2 deletions toil_orchestrator/views/job_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from toil_orchestrator.models import Job, Status
from toil_orchestrator.serializers import JobSerializer, JobSubmitSerializer, JobResumeSerializer
from toil_orchestrator.serializers import JobSerializer, JobSubmitSerializer, JobResumeSerializer, JobIdsSerializer, JobStatusSerializer
from toil_orchestrator.tasks import submit_jobs_to_lsf, abort_job
from rest_framework import mixins
from rest_framework import status
Expand Down Expand Up @@ -46,6 +46,27 @@ def resume(self, request, pk=None, *args, **kwargs):
except Job.DoesNotExist:
return Response("Could not find the indicated job to resume", status=status.HTTP_404_NOT_FOUND)

@swagger_auto_schema(request_body=JobIdsSerializer(), responses={status.HTTP_200_OK: JobStatusSerializer})
@action(detail=False, methods=['post'])
def statuses(self, request):
serializer = JobIdsSerializer(data=request.data)
if not serializer.is_valid():
return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)
job_ids = serializer.validated_data.get("job_ids")
job_status_data = {}
for single_job in self.queryset.filter(id__in=job_ids):
job_obj = JobSerializer(single_job)
job_data = job_obj.data
job_id = job_data["id"]
job_status_data[job_id] = job_data
resp_serializer = JobStatusSerializer(data={'jobs':job_status_data})
if resp_serializer.is_valid():
return Response(resp_serializer.data)
else:
return Response(resp_serializer.errors,
status=status.HTTP_500_INTERNAL_SERVER_ERROR)

@swagger_auto_schema(responses={status.HTTP_200_OK: JobSerializer})
@action(detail=True, methods=['get'])
def abort(self, request, pk=None, *args, **kwargs):
Expand All @@ -56,7 +77,7 @@ def abort(self, request, pk=None, *args, **kwargs):
abort_job.delay(str(pk))
return Response("Job aborted", status=status.HTTP_200_OK)

@swagger_auto_schema(request_body=JobSubmitSerializer, responses={201: JobSerializer})
@swagger_auto_schema(request_body=JobSubmitSerializer, responses={status.HTTP_201_CREATED: JobSerializer})
def create(self, request, *args, **kwargs):
return self.validate_and_save(request.data)

Expand Down

0 comments on commit fbff2fb

Please sign in to comment.