aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-04-05 16:30:15 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-04-05 16:30:15 -0400
commitaef2c3629718705975a181a345d3908776b14af5 (patch)
treee17ce550c12f1bd173a3e5a39f6388ca300e6651 /captain
parent15837a5fd46a1c9051d54138ba3ade26c74091f1 (diff)
downloadlevitating-aef2c3629718705975a181a345d3908776b14af5.tar.gz
levitating-aef2c3629718705975a181a345d3908776b14af5.zip
Fixed checkin json to return a name of instructions needed and a job id
Diffstat (limited to 'captain')
-rw-r--r--captain/api.f9049
1 files changed, 45 insertions, 4 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index 9e92185..4594ba9 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -3,9 +3,31 @@ 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}"}'
contains
+ function build_job_available_json(job_id) result(json_text)
+ use captain_db
+ use utilities, only: replace_field
+ implicit none
+
+ integer, intent(in)::job_id
+ character(len=:), pointer::json_text
+ integer::instruction_id
+ character(PLAYER_NAME_LENGTH)::instruction_name
+
+ instruction_id = get_job_instruction(job_id)
+ call get_instruction_name(instruction_id, instruction_name)
+
+ allocate(character(len=(len(RESPONSE_JSON_WORK_AVAILABLE)+len_trim(instruction_name)+32)) :: json_text)
+ json_text = RESPONSE_JSON_WORK_AVAILABLE
+ call replace_field(json_text, "job_number", job_id)
+ call replace_field(json_text, "instruction_name", instruction_name)
+
+ end function build_job_available_json
+
subroutine handle_task_request(req)
use server_response
use captain_db
@@ -44,8 +66,10 @@ contains
type(response)::resp
character(8)::job_text
- character(PLAYER_NAME_LENGTH)::player
+ character(PLAYER_NAME_LENGTH)::player, instruction
integer::job_i, player_i, instruction_i, ierr
+
+ character(len=:), pointer::checkin_work_json
! Complete - "/api/player/{name}/job/{jobid}/complete"
! Failed - "/api/player/{name}/job/{jobid}/failed"
@@ -81,12 +105,29 @@ contains
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)
+ 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")
+ deallocate(checkin_work_json)
+ else
+ resp%code = GEMINI_CODE_PERMFAIL
+ end if
+ end if
+
+ ! Instruction - /api/instructions/{name}
+ else if(trim(req%component(2)) == "instruction") then
+
+ call req%path_component(3, instruction)
+ resp%body_filename => get_special_full_filename("instructions", trim(instruction)//".json")
+ if(associated(resp%body_filename)) then
resp%temporary_file = .false.
+ resp%code = GEMINI_CODE_SUCCESS
resp%body_mimetype = "application/json"
+ else
+ resp%code = GEMINI_CODE_PERMFAIL
end if
+
end if
end function api_request_gemini