Skip to content

Commit

Permalink
Merge pull request #2061 from greenbone/add-processing-task-status
Browse files Browse the repository at this point in the history
Add: New "Processing" task and report status
  • Loading branch information
timopollmeier authored Aug 17, 2023
2 parents 5b5cdd1 + d8b09d8 commit 1bd6a88
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,7 @@ run_status_name (task_status_t status)
return "Stop Requested";

case TASK_STATUS_STOPPED: return "Stopped";
case TASK_STATUS_PROCESSING: return "Processing";
default: return "Interrupted";
}
}
Expand Down Expand Up @@ -1683,6 +1684,7 @@ run_status_name_internal (task_status_t status)
return "Stop Waiting";

case TASK_STATUS_STOPPED: return "Stopped";
case TASK_STATUS_PROCESSING: return "Processing";
default: return "Interrupted";
}
}
Expand Down Expand Up @@ -2869,6 +2871,9 @@ fork_osp_scan_handler (task_t task, target_t target, int from,
g_free (report_id);
if (rc == 0)
{
set_task_run_status (task, TASK_STATUS_PROCESSING);
set_report_scan_run_status (global_current_report,
TASK_STATUS_PROCESSING);
hosts_set_identifiers (global_current_report);
hosts_set_max_severity (global_current_report, NULL, NULL);
hosts_set_details (global_current_report);
Expand Down Expand Up @@ -3895,6 +3900,7 @@ move_task (const char *task_id, const char *slave_id)
case TASK_STATUS_DELETE_WAITING:
case TASK_STATUS_DELETE_ULTIMATE_WAITING:
case TASK_STATUS_REQUESTED:
case TASK_STATUS_PROCESSING:
// Task cannot be stopped now
return 5;
break;
Expand Down
3 changes: 2 additions & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ typedef enum
/* 15 was removed (TASK_STATUS_STOP_REQUESTED_GIVEUP). */
TASK_STATUS_DELETE_WAITING = 16,
TASK_STATUS_DELETE_ULTIMATE_WAITING = 17,
TASK_STATUS_QUEUED = 18
TASK_STATUS_QUEUED = 18,
TASK_STATUS_PROCESSING = 19,
} task_status_t;

/**
Expand Down
10 changes: 7 additions & 3 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ manage_create_sql_functions ()
" WHEN (SELECT scan_run_status FROM reports"
" WHERE reports.id = $1)"
" IN (SELECT unnest (ARRAY [%i, %i, %i, %i, %i,"
" %i, %i, %i]))"
" %i, %i, %i, %i]))"
" THEN true"
" ELSE false"
" END;"
Expand All @@ -988,7 +988,8 @@ manage_create_sql_functions ()
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOPPED,
TASK_STATUS_INTERRUPTED,
TASK_STATUS_QUEUED);
TASK_STATUS_QUEUED,
TASK_STATUS_PROCESSING);

sql ("CREATE OR REPLACE FUNCTION report_progress (integer)"
" RETURNS integer AS $$"
Expand Down Expand Up @@ -1391,6 +1392,8 @@ manage_create_sql_functions ()
" THEN 'Stopped'"
" WHEN $1 = %i"
" THEN 'Queued'"
" WHEN $1 = %i"
" THEN 'Processing'"
" ELSE 'Interrupted'"
" END;"
"$$ LANGUAGE SQL"
Expand All @@ -1406,7 +1409,8 @@ manage_create_sql_functions ()
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOP_WAITING,
TASK_STATUS_STOPPED,
TASK_STATUS_QUEUED);
TASK_STATUS_QUEUED,
TASK_STATUS_PROCESSING);

if (sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables"
" WHERE table_catalog = '%s'"
Expand Down
19 changes: 14 additions & 5 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2584,7 +2584,8 @@ keyword_applies_to_column (keyword_t *keyword, const char* column)
&& (strstr ("Queued", keyword->string) == NULL)
&& (strstr ("Stop Requested", keyword->string) == NULL)
&& (strstr ("Stopped", keyword->string) == NULL)
&& (strstr ("Interrupted", keyword->string) == NULL))
&& (strstr ("Interrupted", keyword->string) == NULL)
&& (strstr ("Processing", keyword->string) == NULL))
return 0;
return 1;
}
Expand Down Expand Up @@ -15420,7 +15421,8 @@ task_in_use (task_t task)
|| status == TASK_STATUS_RUNNING
|| status == TASK_STATUS_QUEUED
|| status == TASK_STATUS_STOP_REQUESTED
|| status == TASK_STATUS_STOP_WAITING;
|| status == TASK_STATUS_STOP_WAITING
|| status == TASK_STATUS_PROCESSING;
}

/**
Expand Down Expand Up @@ -16530,6 +16532,7 @@ stop_active_tasks ()
case TASK_STATUS_QUEUED:
case TASK_STATUS_STOP_REQUESTED:
case TASK_STATUS_STOP_WAITING:
case TASK_STATUS_PROCESSING:
{
task_t index = get_iterator_resource (&tasks);
/* Set the current user, for event checks. */
Expand Down Expand Up @@ -16562,6 +16565,7 @@ stop_active_tasks ()
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u;",
TASK_STATUS_INTERRUPTED,
TASK_STATUS_DELETE_REQUESTED,
Expand All @@ -16572,7 +16576,8 @@ stop_active_tasks ()
TASK_STATUS_RUNNING,
TASK_STATUS_QUEUED,
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOP_WAITING);
TASK_STATUS_STOP_WAITING,
TASK_STATUS_PROCESSING);
}

/**
Expand Down Expand Up @@ -18157,7 +18162,8 @@ task_iterator_current_report (iterator_t *iterator)
|| run_status == TASK_STATUS_DELETE_ULTIMATE_REQUESTED
|| run_status == TASK_STATUS_STOP_REQUESTED
|| run_status == TASK_STATUS_STOPPED
|| run_status == TASK_STATUS_INTERRUPTED)
|| run_status == TASK_STATUS_INTERRUPTED
|| run_status == TASK_STATUS_PROCESSING)
{
return (unsigned int) sql_int ("SELECT max(id) FROM reports"
" WHERE task = %llu"
Expand All @@ -18168,6 +18174,7 @@ task_iterator_current_report (iterator_t *iterator)
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u);",
task,
TASK_STATUS_REQUESTED,
Expand All @@ -18177,7 +18184,8 @@ task_iterator_current_report (iterator_t *iterator)
TASK_STATUS_DELETE_ULTIMATE_REQUESTED,
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOPPED,
TASK_STATUS_INTERRUPTED);
TASK_STATUS_INTERRUPTED,
TASK_STATUS_PROCESSING);
}
return (report_t) 0;
}
Expand Down Expand Up @@ -52325,6 +52333,7 @@ delete_user (const char *user_id_arg, const char *name_arg, int ultimate,
case TASK_STATUS_QUEUED:
case TASK_STATUS_STOP_REQUESTED:
case TASK_STATUS_STOP_WAITING:
case TASK_STATUS_PROCESSING:
{
cleanup_iterator (&tasks);
free (current_credentials.uuid);
Expand Down
2 changes: 1 addition & 1 deletion src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<name>task_status</name>
<summary>A task run status</summary>
<pattern>
xsd:token { pattern = "Delete Requested|Done|New|Requested|Running|Stop Requested|Stopped|Interrupted" }
xsd:token { pattern = "Delete Requested|Done|New|Processing|Requested|Running|Stop Requested|Stopped|Interrupted" }
</pattern>
</type>
<type>
Expand Down

0 comments on commit 1bd6a88

Please sign in to comment.