aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--captain/api.f9022
-rw-r--r--captain/db.f9021
-rw-r--r--captain/external.f908
-rw-r--r--captain/special.f9018
4 files changed, 51 insertions, 18 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index 003a601..19c4cea 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -35,17 +35,17 @@ contains
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
-
+ job_i = req%path_component_int(5)
if(ierr == 0) then
- call req%path_component(7, task_text)
- read(task_text, *, iostat=ierr) task_i
+
+ task_i = req%path_component_int(7)
if(ierr == 0) then
- if(req%query_string == "starting" .or. req%query_string == "inprogress") then
+ if(req%query_string == "starting") then
+ call insert_task(job_i, task_i)
+ call update_job_status(job_i, JOB_STATUS_WORKING)
+ else if(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
@@ -68,9 +68,8 @@ contains
type(request), intent(in)::req
type(response)::resp
- character(8)::job_text
character(PLAYER_NAME_LENGTH)::player, instruction
- integer::job_i, player_i, instruction_i, ierr
+ integer::job_i, player_i, ierr
character(len=:), pointer::checkin_work_json
@@ -78,10 +77,9 @@ contains
! 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
- call req%path_component(5, job_text)
- read(job_text, *, iostat=ierr) job_i
+ job_i = req%path_component_int(5)
- if(ierr == 0 .and. .not. is_final_job_status(job_i)) then
+ if(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
diff --git a/captain/db.f90 b/captain/db.f90
index 7937383..7bc501d 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -608,13 +608,32 @@ contains
end subroutine update_job_time
+ subroutine insert_task(job_id, task_id)
+ implicit none
+
+ integer, intent(in)::job_id, task_id
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "INSERT INTO tasks(job, task, status) VALUES(?,?,?") == SQLITE_OK) then
+ if(stmt%bind_int(1, job_id) == SQLITE_OK .and. &
+ stmt%bind_int(2, task_id) == SQLITE_OK .and. &
+ stmt%bind_int(3, JOB_STATUS_WORKING) == SQLITE_OK) then
+ call stmt%step_now()
+ end if
+ end if
+ call stmt%finalize()
+
+ call update_job_time(job_id)
+
+ end subroutine insert_task
+
subroutine update_task_status(job_id, task_id, status)
implicit none
integer, intent(in)::job_id, task_id, status
type(sqlite3_stmt)::stmt
- if(stmt%prepare(db, "UPDATE jobs SET status=? WHERE job=? AND task=?") == SQLITE_OK) then
+ if(stmt%prepare(db, "UPDATE tasks SET status=? WHERE job=? AND task=?") == SQLITE_OK) then
if(stmt%bind_int(1, status) == SQLITE_OK .and. &
stmt%bind_int(2, job_id) == SQLITE_OK .and. &
stmt%bind_int(3, task_id) == SQLITE_OK) then
diff --git a/captain/external.f90 b/captain/external.f90
index d9e2a7e..2ddd7f4 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -162,6 +162,7 @@ contains
function generate_one_job_gemini(req) result(res)
use captain_db
use server_response
+ use special_filenames, only: get_task_result_static_filename
implicit none
type(request), intent(in)::req
@@ -176,6 +177,7 @@ contains
type(task), dimension(:), pointer::tasks
character(32)::task_text, job_text
+ character(len=:), pointer::task_results_filename
res => null()
@@ -201,9 +203,11 @@ contains
if(associated(tasks)) then
do i = 1, size(tasks)
status = get_status_utf8(tasks(i)%status)
- write(task_text, '(I8)') tasks(i)%number
+ task_results_filename => get_task_result_static_filename(one_job%id, i, no_path=.true.)
- res = trim(res)//nl//"=> /results/"//trim(job_text)//"-"//trim(adjustl(task_text))//".txt "// &
+ write(task_text, '(I8)') i
+
+ res = trim(res)//nl//"=> /results/"//task_results_filename//" "// &
trim(status)//"Task "//trim(adjustl(task_text))
end do
diff --git a/captain/special.f90 b/captain/special.f90
index 26f31e3..f1c5e94 100644
--- a/captain/special.f90
+++ b/captain/special.f90
@@ -50,11 +50,14 @@ contains
end function get_instructions_static_filename
- function get_task_result_static_filename(job_id, task_num) result(res)
+ function get_task_result_static_filename(job_id, task_num, no_path) result(res)
use config
implicit none
integer, intent(in)::job_id, task_num
+
+ logical, intent(in), optional::no_path
+
character(len=:), pointer::res
character(64)::filename
@@ -63,8 +66,17 @@ contains
write(job_text, '(I8)') job_id
write(task_text, '(I8)') task_num
filename = "results-job"//trim(adjustl(job_text))//"-task"//trim(adjustl(task_text))//".txt"
-
- res => get_special_full_filename("results", filename)
+
+ if(present(no_path)) then
+ if(no_path) then
+ allocate(character(len=len_trim(filename)) :: res)
+ res = filename
+ else
+ res => get_special_full_filename("results", filename)
+ end if
+ else
+ res => get_special_full_filename("results", filename)
+ end if
end function get_task_result_static_filename