aboutsummaryrefslogtreecommitdiff
path: root/captain/api.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-04-02 13:08:37 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-04-02 13:08:37 -0400
commitb27bd7cfa58eb82fc2a6c76aaa848e07a6fa7c24 (patch)
treef611937418d1ea5416431715ab1f6a44d42d1905 /captain/api.f90
parentda47fdfddc46e35a939b7771eda21debec50c094 (diff)
downloadlevitating-b27bd7cfa58eb82fc2a6c76aaa848e07a6fa7c24.tar.gz
levitating-b27bd7cfa58eb82fc2a6c76aaa848e07a6fa7c24.zip
API calls to the gemini interface should work. API calls to the titan interface need implementation.
Diffstat (limited to 'captain/api.f90')
-rw-r--r--captain/api.f9056
1 files changed, 52 insertions, 4 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index 025251d..48cae8a 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -1,27 +1,75 @@
module api_handling
implicit none
+ character(*), parameter::RESPONSE_JSON_OKAY = '{"status": "okay"}'
+ character(*), parameter::RESPONSE_JSON_IDLE = '{"status": "idle"}'
+
contains
function api_request_gemini(req) result(resp)
use server_response
+ use captain_db
+ use special_filenames
implicit none
type(request), intent(in)::req
type(response)::resp
- integer::i
+ character(8)::job_text, task_text
+ character(PLAYER_NAME_LENGTH)::player
+ integer::job_i, task_i, player_i, instruction_i, ierr
! Complete - "/api/player/{name}/job/{jobid}/complete"
! Failed - "/api/player/{name}/job/{jobid}/failed"
! Task - "/api/player/{name}/job/{jobid}/task/{task num}"
if(trim(req%component(2)) == "player" .and. trim(req%component(4)) == "job") then
- if(trim(req%component(6)) == "complete") then
-
+ call req%path_component(5, job_text)
+ read(job_text, *, iostat=ierr) job_i
+
+ if(ierr == 0 .and. .not. is_final_job_status(job_i)) then
+ if(trim(req%component(6)) == "complete") then
+ call update_job_status(job_i, JOB_STATUS_SUCCESS)
+ else if(trim(req%component(6)) == "failure") then
+ call update_job_status(job_i, JOB_STATUS_FAILURE)
+ end if
+ 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
+ end if
+
+ resp%code = GEMINI_CODE_SUCCESS
+ call resp%set_body_contents(RESPONSE_JSON_OKAY)
+
+ ! Checkin - /api/player/{name}/checkin.json
+ else if(trim(req%component(2)) == "player" .and. trim(req%component(4)) == "checkin.json") then
+ ! Check for pending jobs
+ call req%path_component(3, player)
+ player_i = get_player_id(player)
+
+ job_i = get_pending_job_for_player(player_i)
+ if(job_i < 0) then
+ resp%code = GEMINI_CODE_SUCCESS
+ call resp%set_body_contents(RESPONSE_JSON_IDLE)
+ else
+ resp%code = GEMINI_CODE_SUCCESS
+ instruction_i = get_job_instruction(job_i)
+ resp%body_filename => get_instructions_static_filename(instruction_i)
+ resp%temporary_file = .false.
+ resp%body_mimetype = "application/json"
end if
end if
-
end function api_request_gemini
function api_request_titan(req) result(resp)