Skip to content

Commit

Permalink
[+] add timetable.execution_log.ignore_error column, closes #629 (#630
Browse files Browse the repository at this point in the history
)

* [+] add `timetable.execution_log.ignore_error` column, closes #629
  • Loading branch information
pashagolub authored Dec 22, 2023
1 parent ffb8705 commit 3cfc7d8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
7 changes: 4 additions & 3 deletions internal/pgengine/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ func (pge *PgEngine) IsAlive() bool {
// LogTaskExecution will log current chain element execution status including retcode
func (pge *PgEngine) LogTaskExecution(ctx context.Context, task *ChainTask, retCode int, output string) {
_, err := pge.ConfigDb.Exec(ctx, `INSERT INTO timetable.execution_log (
chain_id, task_id, command, kind, last_run, finished, returncode, pid, output, client_name, txid)
VALUES ($1, $2, $3, $4, clock_timestamp() - $5 :: interval, clock_timestamp(), $6, $7, NULLIF($8, ''), $9, $10)`,
chain_id, task_id, command, kind, last_run, finished, returncode, pid, output, client_name, txid, ignore_error)
VALUES ($1, $2, $3, $4, clock_timestamp() - $5 :: interval, clock_timestamp(), $6, $7, NULLIF($8, ''), $9, $10, $11)`,
task.ChainID, task.TaskID, task.Script, task.Kind,
fmt.Sprintf("%f seconds", float64(task.Duration)/1000000),
retCode, pge.Getsid(), strings.TrimSpace(output), pge.ClientName, task.Txid)
retCode, pge.Getsid(), strings.TrimSpace(output), pge.ClientName, task.Txid,
task.IgnoreError)
if err != nil {
pge.l.WithError(err).Error("Failed to log chain element execution status")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pgengine/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestLogChainElementExecution(t *testing.T) {
t.Run("Check LogChainElementExecution if sql fails", func(t *testing.T) {
mockPool.ExpectExec("INSERT INTO .*execution_log").WithArgs(
pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(),
pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg()).
pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg(), pgxmock.AnyArg()).
WillReturnError(errors.New("Failed to log chain element execution status"))
pge.LogTaskExecution(context.Background(), &pgengine.ChainTask{}, 0, "STATUS")
})
Expand Down
6 changes: 6 additions & 0 deletions internal/pgengine/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ var Migrations func() migrator.Option = func() migrator.Option {
return ExecuteMigrationScript(ctx, tx, "00575.sql")
},
},
&migrator.Migration{
Name: "00629 Add ignore_error column to timetable.execution_log",
Func: func(ctx context.Context, tx pgx.Tx) error {
return ExecuteMigrationScript(ctx, tx, "00629.sql")
},
},
// adding new migration here, update "timetable"."migration" in "sql/init.sql"
// and "dbapi" variable in main.go!

Expand Down
23 changes: 12 additions & 11 deletions internal/pgengine/sql/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,18 @@ COMMENT ON TABLE timetable.log IS
'Stores log entries of active sessions';

CREATE TABLE timetable.execution_log (
chain_id BIGINT,
task_id BIGINT,
txid BIGINT NOT NULL,
last_run TIMESTAMPTZ DEFAULT now(),
finished TIMESTAMPTZ,
pid BIGINT,
returncode INTEGER,
kind timetable.command_kind,
command TEXT,
output TEXT,
client_name TEXT NOT NULL
chain_id BIGINT,
task_id BIGINT,
txid BIGINT NOT NULL,
last_run TIMESTAMPTZ DEFAULT now(),
finished TIMESTAMPTZ,
pid BIGINT,
returncode INTEGER,
ignore_error BOOLEAN,
kind timetable.command_kind,
command TEXT,
output TEXT,
client_name TEXT NOT NULL
);

COMMENT ON TABLE timetable.execution_log IS
Expand Down
3 changes: 2 additions & 1 deletion internal/pgengine/sql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ VALUES
(9, '00534 Use cron_split_to_arrays() in cron domain check'),
(10, '00560 Alter txid column to bigint'),
(11, '00573 Add ability to start a chain with delay'),
(12, '00575 Add on_error handling');
(12, '00575 Add on_error handling'),
(13, '00629 Add ignore_error column to timetable.execution_log');
2 changes: 2 additions & 0 deletions internal/pgengine/sql/migrations/00629.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE timetable.execution_log
ADD COLUMN ignore_error BOOLEAN;
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
commit = "000000"
version = "master"
date = "unknown"
dbapi = "00573"
dbapi = "00629"
)

func printVersion() {
Expand Down

0 comments on commit 3cfc7d8

Please sign in to comment.