aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2022-06-27 16:52:40 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2022-06-27 16:57:17 -0400
commita9fc9ce2035e0db07baa6e732200265a90f66332 (patch)
treed31b4d46cb14608b3bdf1f2a65b7186841949d0c
parent1e7a526f569ebce3687c43a907b45fc2e44fab23 (diff)
downloadlevitating-a9fc9ce2035e0db07baa6e732200265a90f66332.tar.gz
levitating-a9fc9ce2035e0db07baa6e732200265a90f66332.zip
Added player report of task type, which the captain will show in the job summary.
-rw-r--r--captain/api.f9012
-rw-r--r--captain/db.f9047
-rw-r--r--captain/external.f906
-rw-r--r--captain/sql/create.sql2
-rw-r--r--captain/sqlite.f9012
-rw-r--r--captain/web.f9011
-rw-r--r--player/endpoints.f908
-rw-r--r--player/instructions.f904
8 files changed, 92 insertions, 10 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index f75a257..fa72b9d 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -59,7 +59,7 @@ contains
class(request)::req
integer::job_i, task_i
- character(len=:), pointer::status
+ character(len=:), pointer::status, task_type, attribute
status => req%q%get_value("status")
@@ -79,6 +79,13 @@ contains
else if(status == "failed") then
call update_task_status(job_i, task_i, JOB_STATUS_FAILURE)
end if
+
+ task_type => req%q%get_value("type")
+ if(associated(task_type)) then
+ call write_log("Task Type Is "//trim(task_type), LOG_DEBUG)
+ call update_task_type(job_i, task_i, task_type)
+ end if
+
end if
end subroutine handle_task_request
@@ -110,11 +117,10 @@ contains
job_i = req%path_component_int(5)
call write_log("Job "//trim(req%component(5))//" update arrived", LOG_INFO)
- write(player, *) job_i
-
if(.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
diff --git a/captain/db.f90 b/captain/db.f90
index 44bc473..90fb4e1 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -794,6 +794,53 @@ contains
end subroutine update_task_status
+ subroutine update_task_type(job_id, task_id, task_type)
+ implicit none
+
+ integer, intent(in)::job_id, task_id
+ character(len=*), intent(in)::task_type
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "UPDATE tasks SET type=? WHERE job=? AND task=?") == SQLITE_OK) then
+ if(stmt%bind_text(1, task_type) == SQLITE_OK .and. &
+ stmt%bind_int(2, job_id) == SQLITE_OK .and. &
+ stmt%bind_int(3, task_id) == SQLITE_OK) &
+ then
+ call stmt%step_now()
+ end if
+ end if
+ call stmt%finalize()
+
+ end subroutine update_task_type
+
+ function get_task_type(job_id, task_id, task_type) result(ret)
+ implicit none
+
+ integer, intent(in)::job_id, task_id
+ character(len=*), intent(out), optional::task_type
+ logical::ret
+ type(sqlite3_stmt)::stmt
+
+ ret = .false.
+
+ if(stmt%prepare(db, "SELECT type FROM tasks WHERE job=? AND task=?") == SQLITE_OK) then
+ if(stmt%bind_int(1, job_id) == SQLITE_OK .and. &
+ stmt%bind_int(2, task_id) == SQLITE_OK) &
+ then
+ if(stmt%step() == SQLITE_ROW) then
+ if(.not. stmt%column_is_null(0)) then
+ ret = .true.
+ if(present(task_type)) then
+ call stmt%column_text(0, task_type)
+ end if
+ end if
+ end if
+ end if
+ end if
+ call stmt%finalize()
+
+ end function get_task_type
+
function is_final_job_status(job_id)
implicit none
diff --git a/captain/external.f90 b/captain/external.f90
index 467f1ca..07f52cb 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -94,7 +94,7 @@ contains
character(1)::nl = new_line(' ')
type(task), dimension(:), pointer::tasks
- character(32)::task_text, job_text
+ character(32)::task_text, job_text, task_type
character(len=:), pointer::task_results_filename
character(len=:), pointer::player_link, instruction_link, result_link
@@ -142,6 +142,10 @@ contains
res = trim(res)//nl//result_link
deallocate(result_link)
+ if(get_task_type(job_id, i, task_type)) then
+ res = trim(res)//" ("//trim(task_type)//")"
+ end if
+
end do
deallocate(tasks)
else
diff --git a/captain/sql/create.sql b/captain/sql/create.sql
index 40cbc0c..323efd0 100644
--- a/captain/sql/create.sql
+++ b/captain/sql/create.sql
@@ -3,7 +3,7 @@ CREATE TABLE players(id INTEGER PRIMARY KEY, name TEXT NOT NULL, token TEXT NOT
CREATE TABLE jobs(id INTEGER PRIMARY KEY, player INTEGER, instruction INTEGER, status INTEGER, time TEXT DEFAULT NULL, FOREIGN KEY(player) REFERENCES players(id), FOREIGN KEY(instruction) REFERENCES instructions(id));
-CREATE TABLE tasks(job INTEGER, task INTEGER, status INTEGER, FOREIGN KEY(job) REFERENCES jobs(id));
+CREATE TABLE tasks(job INTEGER, task INTEGER, status INTEGER, type TEXT DEFAULT NULL, attribute TEXT DEFAULT NULL, FOREIGN KEY(job) REFERENCES jobs(id));
CREATE TABLE instructions(id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL);
diff --git a/captain/sqlite.f90 b/captain/sqlite.f90
index 6bad946..f9bc5b4 100644
--- a/captain/sqlite.f90
+++ b/captain/sqlite.f90
@@ -173,6 +173,7 @@ implicit none
procedure::column_text => stmt_column_text
procedure::column_type => stmt_column_type
procedure::column_text_length => stmt_column_text_length
+ procedure::column_is_null => stmt_column_is_null
end type
@@ -357,6 +358,17 @@ contains
end function stmt_column_type
+ function stmt_column_is_null(self, i)
+ implicit none
+
+ class(sqlite3_stmt), intent(inout)::self
+ integer, intent(in)::i
+ logical::stmt_column_is_null
+
+ stmt_column_is_null = (sqlite3_column_type(self%stmt, i) == SQLITE_NULL)
+
+ end function stmt_column_is_null
+
subroutine stmt_column_text(self, i, res)
implicit none
diff --git a/captain/web.f90 b/captain/web.f90
index 4242083..e7ade4f 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -745,7 +745,7 @@ contains
character(1)::nl = new_line(' ')
type(task), dimension(:), pointer::tasks
- character(32)::task_text, job_text
+ character(32)::task_text, job_text, task_type
character(len=:), pointer::task_results_filename, one_link, local_task_results_filename
character(len=:), pointer::player_link, instruction_link
@@ -796,13 +796,18 @@ contains
one_link => html_link("../results/"//task_results_filename, &
trim(status)//" - Task "//trim(adjustl(task_text)))
- res = trim(res)//nl//" <li>"//trim(one_link)//"</li>"
+ res = trim(res)//nl//" <li>"//trim(one_link)
deallocate(one_link)
else
res = trim(res)//nl//" <li>"// &
- trim(status)//" - Task "//trim(adjustl(task_text))//"</li>"
+ trim(status)//" - Task "//trim(adjustl(task_text))
end if
+ if(get_task_type(job_id, i, task_type)) then
+ res = trim(res)//" ("//trim(task_type)//")"
+ end if
+
+ res = trim(res)//"</li>"
deallocate(local_task_results_filename)
deallocate(task_results_filename)
end do
diff --git a/player/endpoints.f90 b/player/endpoints.f90
index 8708592..60e96af 100644
--- a/player/endpoints.f90
+++ b/player/endpoints.f90
@@ -91,7 +91,7 @@ contains
end subroutine get_check_in_url
- subroutine get_status_url(job, step, url, posting, status)
+ subroutine get_status_url(job, step, url, posting, status, task_type)
use config
use utilities, only: replace_field
implicit none
@@ -100,6 +100,7 @@ contains
integer, intent(in)::step
logical, intent(in), optional::posting
integer, intent(in), optional::status
+ character(len=*), intent(in), optional::task_type
character(*), intent(out)::url
character(32)::int_text
@@ -115,6 +116,11 @@ contains
if(present(status)) then
url = trim(url)//"?status="//trim(status_text(status))
+ if(present(task_type)) then
+ url = trim(url)//"&type="//trim(task_type)
+ end if
+ else if(present(task_type)) then
+ url = trim(url)//"?type="//trim(task_type)
end if
call append_query_token(url)
diff --git a/player/instructions.f90 b/player/instructions.f90
index 300fa2a..f9be1f9 100644
--- a/player/instructions.f90
+++ b/player/instructions.f90
@@ -405,6 +405,7 @@ contains
logical::res
character(len=:), pointer::captured_filename
character(len=1024)::url
+ character(len=40)::operation
task_count = get_task_count(j)
@@ -412,8 +413,9 @@ contains
! Remember to zero-index your json!
do i = 1, task_count
+ call get_task_operation(j, i, operation)
+ call get_status_url(job_id, i, url, status=STATUS_STARTING, task_type=operation)
- call get_status_url(job_id, i, url, status=STATUS_STARTING)
Print *, "Reporting: "//trim(url)
server_status = request_to_ignored(url)