Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospace-file-catalog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VOSpace INAF
vospace-file-catalog
Commits
cbd13339
Commit
cbd13339
authored
3 years ago
by
Sonia Zorba
Browse files
Options
Downloads
Patches
Plain Diff
Improved job phase triggers
parent
e2f766db
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
03-other-functions.sql
+22
-6
22 additions, 6 deletions
03-other-functions.sql
with
22 additions
and
6 deletions
03-other-functions.sql
+
22
−
6
View file @
cbd13339
...
@@ -73,25 +73,41 @@ $func$ LANGUAGE sql;
...
@@ -73,25 +73,41 @@ $func$ LANGUAGE sql;
-- Trigger function that automatically updates start time and end time of jobs at phase update.
-- Trigger function that automatically updates start time and end time of jobs at phase update.
-- This could be performed by business logic of each application that handles jobs but relying directly on the database ensures a better uniformity.
-- This could be performed by business logic of each application that handles jobs but relying directly on the database ensures a better uniformity.
CREATE
OR
REPLACE
FUNCTION
job_phase_inserted
()
RETURNS
TRIGGER
AS
$
func
$
BEGIN
IF
new
.
phase
=
'EXECUTING'
THEN
new
.
start_time
:
=
NOW
();
ELSIF
new
.
phase
=
'COMPLETED'
OR
new
.
phase
=
'ERROR'
THEN
new
.
start_time
:
=
NOW
();
new
.
end_time
:
=
NOW
();
END
IF
;
RETURN
new
;
END
;
$
func
$
LANGUAGE
plpgsql
;
CREATE
OR
REPLACE
FUNCTION
job_phase_updated
()
RETURNS
TRIGGER
CREATE
OR
REPLACE
FUNCTION
job_phase_updated
()
RETURNS
TRIGGER
AS
AS
$
func
$
$
func
$
BEGIN
BEGIN
IF
new
.
phase
!=
old
.
phase
THEN
IF
new
.
phase
=
'EXECUTING'
THEN
IF
new
.
phase
=
'EXECUTING'
THEN
new
.
start_time
:
=
NOW
();
new
.
start_time
:
=
NOW
();
ELSIF
new
.
phase
=
'COMPLETED'
OR
new
.
phase
=
'ERROR'
OR
new
.
phase
=
'ABORTED'
THEN
ELSIF
new
.
phase
=
'COMPLETED'
OR
new
.
phase
=
'ERROR'
OR
new
.
phase
=
'ABORTED'
THEN
new
.
end_time
:
=
NOW
();
new
.
end_time
:
=
NOW
();
END
IF
;
END
IF
;
END
IF
;
RETURN
new
;
RETURN
new
;
END
;
END
;
$
func
$
LANGUAGE
plpgsql
;
$
func
$
LANGUAGE
plpgsql
;
CREATE
TRIGGER
job_update
BEFORE
UPDATE
OF
phase
ON
job
FOR
EACH
ROW
EXECUTE
PROCEDURE
job_phase_updated
();
CREATE
TRIGGER
job_insert
CREATE
TRIGGER
job_insert
BEFORE
INSERT
ON
job
BEFORE
INSERT
ON
job
FOR
EACH
ROW
FOR
EACH
ROW
EXECUTE
PROCEDURE
job_phase_inserted
();
CREATE
TRIGGER
job_update
BEFORE
UPDATE
OF
phase
ON
job
FOR
EACH
ROW
EXECUTE
PROCEDURE
job_phase_updated
();
EXECUTE
PROCEDURE
job_phase_updated
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment