aboutsummaryrefslogtreecommitdiff
path: root/captain/api.f90
diff options
context:
space:
mode:
Diffstat (limited to 'captain/api.f90')
-rw-r--r--captain/api.f9087
1 files changed, 54 insertions, 33 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index 8b6890d..9e92185 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -6,6 +6,34 @@ implicit none
contains
+ subroutine handle_task_request(req)
+ use server_response
+ use captain_db
+ implicit none
+
+ class(request)::req
+ character(8)::job_text, task_text
+ integer::job_i, task_i, ierr
+
+ call req%path_component(5, job_text)
+ read(job_text, *, iostat=ierr) job_i
+
+ if(ierr == 0) then
+ call req%path_component(7, task_text)
+ read(task_text, *, iostat=ierr) task_i
+ if(ierr == 0) then
+ if(req%query_string == "starting" .or. req%query_string == "inprogress") then
+ call update_task_status(job_i, task_i, JOB_STATUS_WORKING)
+ else if(req%query_string == "complete") then
+ call update_task_status(job_i, task_i, JOB_STATUS_SUCCESS)
+ else if(req%query_string == "failed") then
+ call update_task_status(job_i, task_i, JOB_STATUS_FAILURE)
+ end if
+ end if
+ end if
+
+ end subroutine handle_task_request
+
function api_request_gemini(req) result(resp)
use server_response
use captain_db
@@ -15,9 +43,9 @@ contains
type(request), intent(in)::req
type(response)::resp
- character(8)::job_text, task_text
+ character(8)::job_text
character(PLAYER_NAME_LENGTH)::player
- integer::job_i, task_i, player_i, instruction_i, ierr
+ integer::job_i, player_i, instruction_i, ierr
! Complete - "/api/player/{name}/job/{jobid}/complete"
! Failed - "/api/player/{name}/job/{jobid}/failed"
@@ -35,17 +63,7 @@ contains
end if
if(ierr == 0 .and. trim(req%component(6)) == "task") then
- call req%path_component(7, task_text)
- read(task_text, *, iostat=ierr) task_i
- if(ierr == 0) then
- if(req%query_string == "starting" .or. req%query_string == "inprogress") then
- call update_task_status(job_i, task_i, JOB_STATUS_WORKING)
- else if(req%query_string == "complete") then
- call update_task_status(job_i, task_i, JOB_STATUS_SUCCESS)
- else if(req%query_string == "failed") then
- call update_task_status(job_i, task_i, JOB_STATUS_FAILURE)
- end if
- end if
+ call handle_task_request(req)
end if
resp%code = GEMINI_CODE_SUCCESS
@@ -75,12 +93,15 @@ contains
function api_request_titan(req) result(resp)
use server_response
+ use special_filenames
implicit none
type(titan_request), intent(in)::req
type(response)::resp
character(len=:), pointer::fullpath
+ character(12)::job_text, task_text
+ integer::job_id, task_num, ierr
fullpath => null()
@@ -89,12 +110,31 @@ contains
trim(req%component(4)) == "job" .and. &
trim(req%component(6)) == "task") then
- fullpath =>
+ call req%path_component(5, job_text)
+ read(job_text, *, iostat=ierr) job_id
+ if(ierr /= 0) then
+ resp%code = GEMINI_CODE_PERMFAIL
+ return
+ end if
+
+ call req%path_component(5, task_text)
+ read(task_text, *, iostat=ierr) task_num
+ if(ierr /= 0) then
+ resp%code = GEMINI_CODE_PERMFAIL
+ return
+ end if
+
+ call handle_task_request(req)
+
+ fullpath => get_task_result_static_filename(job_id, task_num)
end if
if(associated(fullpath)) then
+ ! Write the file
+ call req%write_to(fullpath)
+
resp%code = GEMINI_CODE_SUCCESS
call resp%set_body_contents(RESPONSE_JSON_OKAY)
resp%body_mimetype = "application/json"
@@ -105,25 +145,6 @@ contains
end if
-
-
end function api_request_titan
- function api_request(req) result(resp)
- use server_response
- implicit none
-
- type(request)::req
- type(titan_request)::titan_req
- type(response)::resp
-
- if(req%protocol == "gemini") then
- resp = api_request_gemini(req)
- else if(req%protocol == "titan") then
- call titan_req%init_from_request(req)
- resp = api_request_titan(titan_req)
- end if
-
- end function api_request
-
end module api_handling \ No newline at end of file