Skip to content

Commit 7d5f620

Browse files
committed
workshop: add column "jobs.time_modified"
1 parent e29067e commit 7d5f620

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cm4all-workshop (7.3) unstable; urgency=low
22

33
* workshop: add plan option "notify_progress"
4+
* workshop: add column "jobs.time_modified"
45

56
--
67

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ The `jobs` table
528528
* ``description``: Human readable description. Not used by
529529
Workshop.
530530
* ``time_created``: The time stamp when this job was created.
531+
* ``time_modified``: The time stamp when this job was most recently
532+
modified (e.g. progress update, completion).
531533
* ``scheduled_time``: The time when the job will be executed.
532534
The database server's clock is the authoritative reference.
533535
* ``enabled``: If :samp:`FALSE`, this job will not be scheduled

sql/jobs.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ CREATE TABLE jobs (
2828

2929
-- the time this job was created
3030
time_created timestamp NOT NULL DEFAULT now(),
31+
-- the time this record was last modified
32+
time_modified timestamp NOT NULL DEFAULT now(),
3133
-- the job will not be executed before this time
3234
scheduled_time timestamp NULL,
3335
-- is this job enabled?

src/Migrate.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ MigrateWorkshopDatabase(Pg::Connection &c, const char *schema)
5050

5151
/* since Workshop 7.1 */
5252
c.Execute("ALTER TABLE jobs ADD COLUMN IF NOT EXISTS stdin bytea NULL");
53+
54+
// since Workshop 7.3
55+
c.Execute("ALTER TABLE jobs ADD COLUMN IF NOT EXISTS time_modified timestamp NOT NULL DEFAULT now()");
5356
}
5457

5558
static void

src/workshop/PGQueue.cxx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pg_init(Pg::Connection &db, const char *schema)
2424
? "stdin"sv
2525
: "NULL"sv;
2626

27+
const std::string_view set_time_modified = Pg::ColumnExists(db, schema, "jobs", "time_modified")
28+
? ", time_modified=now()"sv
29+
: ""sv;
30+
2731
/* ignore jobs which are scheduled deep into the future; some
2832
Workshop clients (such as URO) do this, and it slows down
2933
the PostgreSQL query */
@@ -59,25 +63,28 @@ LIMIT 1 OFFSET $3
5963
)SQL",
6064
3);
6165

62-
db.Prepare("claim_job", R"SQL(
66+
db.Prepare("claim_job", fmt::format(R"SQL(
6367
UPDATE jobs
6468
SET node_name=$1, node_timeout=now()+$3::INTERVAL, time_started=now()
69+
{}
6570
WHERE id=$2 AND node_name IS NULL AND enabled
66-
)SQL",
71+
)SQL", set_time_modified).c_str(),
6772
3);
6873

69-
db.Prepare("set_job_progress", R"SQL(
74+
db.Prepare("set_job_progress", fmt::format(R"SQL(
7075
UPDATE jobs
7176
SET progress=$2, node_timeout=now()+$3::INTERVAL
77+
{}
7278
WHERE id=$1
73-
)SQL",
79+
)SQL", set_time_modified).c_str(),
7480
3);
7581

76-
db.Prepare("set_job_done", R"SQL(
82+
db.Prepare("set_job_done", fmt::format(R"SQL(
7783
UPDATE jobs
7884
SET time_done=now(), progress=100, exit_status=$2, log=$3
85+
{}
7986
WHERE id=$1
80-
)SQL",
87+
)SQL", set_time_modified).c_str(),
8188
3);
8289

8390
db.Prepare("add_cpu_usage", R"SQL(
@@ -87,20 +94,22 @@ WHERE id=$1
8794
)SQL",
8895
2);
8996

90-
db.Prepare("release_jobs", R"SQL(
97+
db.Prepare("release_jobs", fmt::format(R"SQL(
9198
UPDATE jobs
9299
SET node_name=NULL, node_timeout=NULL, progress=0
100+
{}
93101
WHERE node_name=$1 AND time_done IS NULL AND exit_status IS NULL
94-
)SQL",
102+
)SQL", set_time_modified).c_str(),
95103
1);
96104

97-
db.Prepare("expire_jobs", R"SQL(
105+
db.Prepare("expire_jobs", fmt::format(R"SQL(
98106
UPDATE jobs
99107
SET node_name=NULL, node_timeout=NULL, progress=0
108+
{}
100109
WHERE time_done IS NULL AND exit_status IS NULL AND
101110
node_name IS NOT NULL AND node_name <> $1 AND
102111
node_timeout IS NOT NULL AND now() > node_timeout
103-
)SQL",
112+
)SQL", set_time_modified).c_str(),
104113
1);
105114

106115
db.Prepare("set_env", R"SQL(
@@ -110,22 +119,24 @@ WHERE id=$1
110119
)SQL",
111120
3);
112121

113-
db.Prepare("rollback_job", R"SQL(
122+
db.Prepare("rollback_job", fmt::format(R"SQL(
114123
UPDATE jobs
115124
SET node_name=NULL, node_timeout=NULL, progress=0
125+
{}
116126
WHERE id=$1 AND node_name IS NOT NULL
117127
AND time_done IS NULL
118-
)SQL",
128+
)SQL", set_time_modified).c_str(),
119129
1);
120130

121-
db.Prepare("again_job", R"SQL(
131+
db.Prepare("again_job", fmt::format(R"SQL(
122132
UPDATE jobs
123133
SET node_name=NULL, node_timeout=NULL, progress=0
124134
, log=$3
125135
, scheduled_time=NOW() + $2 * '1 second'::interval
136+
{}
126137
WHERE id=$1 AND node_name IS NOT NULL
127138
AND time_done IS NULL
128-
)SQL",
139+
)SQL", set_time_modified).c_str(),
129140
3);
130141

131142
db.Prepare("reap_finished_jobs", R"SQL(

0 commit comments

Comments
 (0)