aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
Diffstat (limited to 'captain')
-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
6 files changed, 82 insertions, 8 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