diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-08 09:31:55 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-08 09:31:55 -0400 |
commit | eaf8cf88305640cdaf274504c1cead5e88bf09d4 (patch) | |
tree | 6aa1814e7172f001c62ad2a15da86970b7e1860f | |
parent | 26eee62be8820373a61654c51c6f3622fe46d166 (diff) | |
download | levitating-eaf8cf88305640cdaf274504c1cead5e88bf09d4.tar.gz levitating-eaf8cf88305640cdaf274504c1cead5e88bf09d4.zip |
Fixed task handling inside the captain. Fixed static file delivery.
-rw-r--r-- | captain/api.f90 | 46 | ||||
-rw-r--r-- | captain/db.f90 | 13 | ||||
-rw-r--r-- | captain/external.f90 | 8 | ||||
-rw-r--r-- | captain/gemini.f90 | 1 | ||||
-rw-r--r-- | captain/response.f90 | 10 |
5 files changed, 44 insertions, 34 deletions
diff --git a/captain/api.f90 b/captain/api.f90 index 19c4cea..b330d30 100644 --- a/captain/api.f90 +++ b/captain/api.f90 @@ -32,27 +32,27 @@ contains subroutine handle_task_request(req) use server_response use captain_db + use logging implicit none class(request)::req - integer::job_i, task_i, ierr + integer::job_i, task_i - job_i = req%path_component_int(5) - if(ierr == 0) then - + if(associated(req%query_string)) then + job_i = req%path_component_int(5) task_i = req%path_component_int(7) - if(ierr == 0) 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 - 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 + call write_log("task update is "//trim(req%query_string)) + if(req%query_string == "starting") then + call write_log("Inserting task") + 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 + 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 @@ -69,7 +69,7 @@ contains type(response)::resp character(PLAYER_NAME_LENGTH)::player, instruction - integer::job_i, player_i, ierr + integer::job_i, player_i character(len=:), pointer::checkin_work_json @@ -78,8 +78,13 @@ contains ! Task - "/api/player/{name}/job/{jobid}/task/{task num}" if(trim(req%component(2)) == "player" .and. trim(req%component(4)) == "job") then job_i = req%path_component_int(5) + call write_log("Job "//trim(req%component(5))//" update arrived") + + write(player, *) job_i + call write_log("int is "//trim(player)) - if(is_final_job_status(job_i)) then + if(.not. is_final_job_status(job_i)) then + call write_log("Processing line") if(trim(req%component(6)) == "complete") then call update_job_status(job_i, JOB_STATUS_SUCCESS) else if(trim(req%component(6)) == "failure") then @@ -87,7 +92,8 @@ contains end if end if - if(ierr == 0 .and. trim(req%component(6)) == "task") then + if(trim(req%component(6)) == "task") then + call write_log("Task update encountered") call handle_task_request(req) end if @@ -149,7 +155,7 @@ contains character(len=:), pointer::fullpath character(12)::job_text, task_text - integer::job_id, task_num, ierr + integer::job_id, task_num character(64)::msg diff --git a/captain/db.f90 b/captain/db.f90 index 7bc501d..56e8a70 100644 --- a/captain/db.f90 +++ b/captain/db.f90 @@ -569,11 +569,16 @@ contains end function get_job_tasks subroutine update_job_status(job_id, status) + use logging implicit none integer, intent(in)::job_id, status type(sqlite3_stmt)::stmt - + character(128)::msg + + write(msg, *) "Update ", job_id, " to ", status + call write_log(trim(msg)) + if(stmt%prepare(db, "UPDATE jobs SET status=? WHERE id=?") == SQLITE_OK) then if(stmt%bind_int(1, status) == SQLITE_OK .and. stmt%bind_int(2, job_id) == SQLITE_OK) then call stmt%step_now() @@ -614,7 +619,7 @@ contains 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%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 @@ -647,15 +652,19 @@ contains end subroutine update_task_status function is_final_job_status(job_id) + use logging implicit none integer, intent(in)::job_id logical::is_final_job_status integer::i + character(128)::s i = get_job_status(job_id) is_final_job_status = (i == JOB_STATUS_SUCCESS .or. i == JOB_STATUS_FAILURE) + write(s, *) "Status for ", job_id, " is ", i, " or ", is_final_job_status + call write_log(trim(s)) end function is_final_job_status diff --git a/captain/external.f90 b/captain/external.f90 index 2ddd7f4..5cbee17 100644 --- a/captain/external.f90 +++ b/captain/external.f90 @@ -208,7 +208,7 @@ contains write(task_text, '(I8)') i res = trim(res)//nl//"=> /results/"//task_results_filename//" "// & - trim(status)//"Task "//trim(adjustl(task_text)) + trim(status)//" - Task "//trim(adjustl(task_text)) end do deallocate(tasks) @@ -644,7 +644,11 @@ contains logical::exists resp%temporary_file = .false. - resp%body_filename => get_special_full_filename(category, filename) + + call req%path_component(1, category) + call req%path_component(2, filename) + + resp%body_filename => get_special_full_filename(trim(category), trim(filename)) inquire(file=resp%body_filename, exist=exists) if(.not. exists) then diff --git a/captain/gemini.f90 b/captain/gemini.f90 index db0ac17..02b57c7 100644 --- a/captain/gemini.f90 +++ b/captain/gemini.f90 @@ -265,6 +265,7 @@ contains call req%path_component(1, first) if(trim(first) == 'api') then + call write_log("API call encountered") if(req%protocol == "gemini") then resp = api_request_gemini(req) call write_log("resp filename is: '"//trim(resp%body_filename)//"'") diff --git a/captain/response.f90 b/captain/response.f90 index 9cd2d9f..b980f8e 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -435,23 +435,13 @@ contains open(newunit=unum, file=filename, status="unknown", action="write", access="stream", form="formatted") bytes_to_go = self%size - call write_log("Writing!") do while(bytes_to_go > 0) bufread = ssl_read(self%ssl_connection, buf) bytes_to_go = bytes_to_go - bufread - - write(msg, *) "read: ", bufread - call write_log(trim(msg)) - - write(msg, *) "remaining: ", bytes_to_go - call write_log(trim(msg)) - - do i = 1, bufread write(unum, '(A1)', advance='no') buf(i) end do - end do close(unum) |