From 6a40940ad6c6facea6c8e9d0dc1896885168c442 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 2 May 2025 10:17:13 +0300 Subject: split housekeeping jobs to separate scheduled tasks on longer cooldown intervals, add table to record task execution timestamps, bump schema --- sql/pgsql/migrations/150.sql | 5 +++++ sql/pgsql/schema.sql | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 sql/pgsql/migrations/150.sql (limited to 'sql/pgsql') diff --git a/sql/pgsql/migrations/150.sql b/sql/pgsql/migrations/150.sql new file mode 100644 index 000000000..55d9609e9 --- /dev/null +++ b/sql/pgsql/migrations/150.sql @@ -0,0 +1,5 @@ +create table ttrss_scheduled_tasks( + id serial not null primary key, + task_name varchar(250) unique not null, + last_rc integer not null, + last_run timestamp not null default NOW()); diff --git a/sql/pgsql/schema.sql b/sql/pgsql/schema.sql index acfa619c9..3ff9a6674 100644 --- a/sql/pgsql/schema.sql +++ b/sql/pgsql/schema.sql @@ -1,3 +1,4 @@ +drop table if exists ttrss_scheduled_tasks; drop table if exists ttrss_error_log; drop table if exists ttrss_plugin_storage; drop table if exists ttrss_linked_feeds; @@ -394,4 +395,10 @@ create table ttrss_error_log( context text not null, created_at timestamp not null); +create table ttrss_scheduled_tasks( + id serial not null primary key, + task_name varchar(250) unique not null, + last_rc integer not null, + last_run timestamp not null default NOW()); + commit; -- cgit v1.2.3-54-g00ecf From a268f52de695fffb29769960332bfb34fe3ac7b5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 2 May 2025 10:23:30 +0300 Subject: record task duration in seconds --- classes/PluginHost.php | 6 +++++- sql/pgsql/migrations/150.sql | 1 + sql/pgsql/schema.sql | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'sql/pgsql') diff --git a/classes/PluginHost.php b/classes/PluginHost.php index 484364f26..e417fde1f 100644 --- a/classes/PluginHost.php +++ b/classes/PluginHost.php @@ -968,12 +968,15 @@ class PluginHost { if ($task['cron']->isDue($last_run)) { Debug::log("Task $task_name is due, executing..."); + $task_started = time(); $rc = (int) $task['callback'](); + $task_duration = time() - $task_started; - Debug::log("Task $task_name has finished with RC=$rc, recording timestamp..."); + Debug::log("Task $task_name has finished in $task_duration seconds with RC=$rc, recording timestamp..."); if ($task_record) { $task_record->last_run = time(); + $task_record->last_duration = $task_duration; $task_record->last_rc = $rc; $task_record->save(); @@ -982,6 +985,7 @@ class PluginHost { $task_record->set([ 'task_name' => $task_name, + 'last_duration' => $task_duration, 'last_rc' => $rc, 'last_run' => Db::NOW(), ]); diff --git a/sql/pgsql/migrations/150.sql b/sql/pgsql/migrations/150.sql index 55d9609e9..c0aae3bdf 100644 --- a/sql/pgsql/migrations/150.sql +++ b/sql/pgsql/migrations/150.sql @@ -1,5 +1,6 @@ create table ttrss_scheduled_tasks( id serial not null primary key, task_name varchar(250) unique not null, + last_duration integer not null, last_rc integer not null, last_run timestamp not null default NOW()); diff --git a/sql/pgsql/schema.sql b/sql/pgsql/schema.sql index 3ff9a6674..7e995f915 100644 --- a/sql/pgsql/schema.sql +++ b/sql/pgsql/schema.sql @@ -398,6 +398,7 @@ create table ttrss_error_log( create table ttrss_scheduled_tasks( id serial not null primary key, task_name varchar(250) unique not null, + last_duration integer not null, last_rc integer not null, last_run timestamp not null default NOW()); -- cgit v1.2.3-54-g00ecf From 5256edd484d6d3efdd870fd04d09c289e2d23c61 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 2 May 2025 21:51:07 +0300 Subject: schema - spaces to tabs --- sql/pgsql/migrations/150.sql | 10 +++++----- sql/pgsql/schema.sql | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'sql/pgsql') diff --git a/sql/pgsql/migrations/150.sql b/sql/pgsql/migrations/150.sql index c0aae3bdf..19f3aaa3a 100644 --- a/sql/pgsql/migrations/150.sql +++ b/sql/pgsql/migrations/150.sql @@ -1,6 +1,6 @@ create table ttrss_scheduled_tasks( - id serial not null primary key, - task_name varchar(250) unique not null, - last_duration integer not null, - last_rc integer not null, - last_run timestamp not null default NOW()); + id serial not null primary key, + task_name varchar(250) unique not null, + last_duration integer not null, + last_rc integer not null, + last_run timestamp not null default NOW()); diff --git a/sql/pgsql/schema.sql b/sql/pgsql/schema.sql index 7e995f915..3145629fc 100644 --- a/sql/pgsql/schema.sql +++ b/sql/pgsql/schema.sql @@ -397,9 +397,9 @@ create table ttrss_error_log( create table ttrss_scheduled_tasks( id serial not null primary key, - task_name varchar(250) unique not null, - last_duration integer not null, - last_rc integer not null, - last_run timestamp not null default NOW()); + task_name varchar(250) unique not null, + last_duration integer not null, + last_rc integer not null, + last_run timestamp not null default NOW()); commit; -- cgit v1.2.3-54-g00ecf