aboutsummaryrefslogtreecommitdiff
path: root/captain/api.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-04-07 14:21:35 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-04-07 14:21:35 -0400
commitc493170e73506e974a0644452fc5a334c08171bc (patch)
tree7cfbbde04f5e3263092118dbabf843fbe68d93ad /captain/api.f90
parent1de4bd52574599452f9e92c8e36381a4797563fb (diff)
downloadlevitating-c493170e73506e974a0644452fc5a334c08171bc.tar.gz
levitating-c493170e73506e974a0644452fc5a334c08171bc.zip
Fixed many issues related to reporting status. Initial debugging of titan upload handling.
Diffstat (limited to 'captain/api.f90')
-rw-r--r--captain/api.f9045
1 files changed, 27 insertions, 18 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index 4594ba9..003a601 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -1,10 +1,11 @@
module api_handling
+use iso_c_binding
implicit none
character(*), parameter::RESPONSE_JSON_OKAY = '{"status": "okay"}'
character(*), parameter::RESPONSE_JSON_IDLE = '{"status": "idle"}'
character(*), parameter::RESPONSE_JSON_WORK_AVAILABLE = &
- '{"status": "pending", "job": {job_number}, "instruction": "{instruction_name}"}'
+ '{"status": "pending",'//c_new_line//' "job": {job_number},'//c_new_line//' "instruction": "{instruction_name}"}'
contains
@@ -46,6 +47,7 @@ contains
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)
+ call update_job_status(job_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
@@ -60,6 +62,7 @@ contains
use server_response
use captain_db
use special_filenames
+ use logging
implicit none
type(request), intent(in)::req
@@ -92,7 +95,7 @@ contains
resp%code = GEMINI_CODE_SUCCESS
call resp%set_body_contents(RESPONSE_JSON_OKAY)
- resp%body_mimetype = "application/json"
+ resp%body_mimetype = "text/plain"
! Checkin - /api/player/{name}/checkin.json
else if(trim(req%component(2)) == "player" .and. trim(req%component(4)) == "checkin.json") then
@@ -100,6 +103,10 @@ contains
call req%path_component(3, player)
player_i = get_player_id(player)
+ ! If we have a checkin, but the worker should have a job in progress, mark
+ ! the jobs as failed.
+ call mark_working_jobs_as_failed(player_i)
+
job_i = get_pending_job_for_player(player_i)
if(job_i < 0) then
resp%code = GEMINI_CODE_SUCCESS
@@ -108,7 +115,8 @@ contains
checkin_work_json => build_job_available_json(job_i)
if(associated(checkin_work_json)) then
resp%code = GEMINI_CODE_SUCCESS
- call resp%set_body_contents(checkin_work_json, "application/json")
+ call write_log("Sending: "//trim(checkin_work_json))
+ call resp%set_body_contents(trim(checkin_work_json), "text/gemini")
deallocate(checkin_work_json)
else
resp%code = GEMINI_CODE_PERMFAIL
@@ -123,7 +131,7 @@ contains
if(associated(resp%body_filename)) then
resp%temporary_file = .false.
resp%code = GEMINI_CODE_SUCCESS
- resp%body_mimetype = "application/json"
+ resp%body_mimetype = "text/plain"
else
resp%code = GEMINI_CODE_PERMFAIL
end if
@@ -135,6 +143,7 @@ contains
function api_request_titan(req) result(resp)
use server_response
use special_filenames
+ use logging
implicit none
type(titan_request), intent(in)::req
@@ -144,27 +153,25 @@ contains
character(12)::job_text, task_text
integer::job_id, task_num, ierr
+ character(64)::msg
+
fullpath => null()
+ call write_log("Titan request encountered")
+
! Task - "/api/player/{name}/job/{jobid}/task/{task num}"
if(trim(req%component(2)) == "player" .and. &
trim(req%component(4)) == "job" .and. &
trim(req%component(6)) == "task") then
- 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
+ job_id = req%path_component_int(5)
+
+ task_num = req%path_component_int(7)
+
+ write(job_text, '(I6)') job_id
+ write(task_text, '(I6)') task_num
+ call write_log("Handling a task update for job "//trim(job_text)//" task "//trim(task_text))
call handle_task_request(req)
fullpath => get_task_result_static_filename(job_id, task_num)
@@ -174,11 +181,13 @@ contains
if(associated(fullpath)) then
! Write the file
+ call write_log("Storing titan file to "//trim(fullpath))
+
call req%write_to(fullpath)
resp%code = GEMINI_CODE_SUCCESS
call resp%set_body_contents(RESPONSE_JSON_OKAY)
- resp%body_mimetype = "application/json"
+ resp%body_mimetype = "text/plain"
else