Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCMOD-8730: Support expiry policies #235

Open
wants to merge 197 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
acd1eab
Add expirationDate column on Job table
xbreizh Mar 8, 2021
d79a4b2
fix id name
xbreizh Mar 8, 2021
a86f374
change expirationDate to expirationdays
xbreizh Mar 8, 2021
e2cc2f4
Update contract
xbreizh Mar 9, 2021
c03cf8c
Add expirationPolicy object
xbreizh Mar 9, 2021
f32efb2
Update model
xbreizh Mar 9, 2021
475d70b
Update contract
xbreizh Mar 9, 2021
2c0872e
Remove db changes
xbreizh Mar 9, 2021
2cd8000
Reset files
xbreizh Mar 9, 2021
3dd83cd
Add expiryTime
xbreizh Mar 10, 2021
3ba822a
readd extra space
xbreizh Mar 10, 2021
581d23d
Pass expiryTime as date
xbreizh Mar 10, 2021
b357306
Add ExpirationPolicy to job and newJob + test
xbreizh Mar 10, 2021
85770b8
Update contract
xbreizh Mar 11, 2021
761c513
Downstream update
xbreizh Mar 11, 2021
2c728d2
Correct db column type
xbreizh Mar 12, 2021
3f06bdb
Add expiration_policy table
xbreizh Mar 12, 2021
a7c4b53
Update contract
xbreizh Mar 12, 2021
e48fc85
Update related objects
xbreizh Mar 12, 2021
1c3d77c
workaround test (temp)
xbreizh Mar 12, 2021
72ae034
Merge branch 'develop' into SCMOD-8730
xbreizh Mar 12, 2021
5967a6e
Review adjustments
xbreizh Mar 12, 2021
de265ae
Append new status
xbreizh Mar 15, 2021
481096a
Simplify job_status enum update
xbreizh Mar 15, 2021
c4ae1d8
Simplify expiryTime object
xbreizh Mar 15, 2021
d12c1a8
Rename Expiry back to ExpirationPolicy
xbreizh Mar 15, 2021
9037c25
Add upsertJobPolicy
xbreizh Mar 15, 2021
aad2b51
Update policy table
xbreizh Mar 15, 2021
a15f541
Simplified OperationEnum
xbreizh Mar 16, 2021
7375a49
Add policies build / validation
xbreizh Mar 17, 2021
835cf58
Review corrections
xbreizh Mar 17, 2021
6c42c67
Fixed policy typo
xbreizh Mar 18, 2021
e854d99
Change hashmap for map
xbreizh Mar 18, 2021
88ad854
Reduce cognotive complexity + javadoc
xbreizh Mar 18, 2021
9739795
Reduce cognitive complexity + javadoc
xbreizh Mar 18, 2021
c519823
Merge remote-tracking branch 'origin/SCMOD-8730' into SCMOD-8730
xbreizh Mar 18, 2021
0ffa5ff
Update expiration_policy table structure
xbreizh Mar 18, 2021
6adea26
implement upsert_job_policy.sql
xbreizh Mar 18, 2021
c302dcb
Simplified defineDefaultPolicy
xbreizh Mar 18, 2021
9002c19
Capitalizing
xbreizh Mar 18, 2021
f0d599b
Renamed job_expiration_policy table
xbreizh Mar 18, 2021
fba00e6
Implement sql scripts
xbreizh Mar 18, 2021
73992a3
Merge branch 'develop' into SCMOD-8730
xbreizh Mar 18, 2021
881a2ae
Update create_policy name
xbreizh Mar 19, 2021
db44cd7
Change map for ExpirationPolicy
xbreizh Mar 19, 2021
b6c9fed
Fixed typo
xbreizh Mar 19, 2021
3ae745a
Fixed ExpirationPolicy db string
xbreizh Mar 19, 2021
20a2a06
Adapted Expiration Policy to match db requirements
xbreizh Mar 22, 2021
85d074c
Implemented persistence
xbreizh Mar 22, 2021
b4de723
Restore PolicyBuilder
xbreizh Mar 23, 2021
34f1d24
Fixing tests
xbreizh Mar 23, 2021
f70af36
Add debug log
xbreizh Mar 23, 2021
8f5c830
Fixed internal_upsert_job_policy.sql
xbreizh Mar 23, 2021
31f03f8
fixed policyBuilder
xbreizh Mar 23, 2021
c21043c
converted duration unity
xbreizh Mar 23, 2021
d5e291e
Fixed log
xbreizh Mar 23, 2021
95e3d86
Fixed job with dependency
xbreizh Mar 23, 2021
2d131df
Refactored expiration_policy
xbreizh Mar 24, 2021
681c537
Update create_job functions
xbreizh Mar 24, 2021
fbeab05
Add copyright on upsertJobPolicy
xbreizh Mar 24, 2021
a24be4b
Remove duplication
xbreizh Mar 24, 2021
988a696
Add getJobPolicy
xbreizh Mar 24, 2021
8704872
Retrieve expiration policy on getJob
xbreizh Mar 24, 2021
f3b7371
Reordered the policies
xbreizh Mar 24, 2021
cef0bcb
Restored missing date validation
xbreizh Mar 24, 2021
611f00f
Remodel getJob()
xbreizh Mar 24, 2021
0b75aae
fixed getJobs()
xbreizh Mar 24, 2021
bddb94d
Return original expiration date value
xbreizh Mar 25, 2021
57e70bf
Merge branch 'develop' into SCMOD-8730
xbreizh Mar 26, 2021
736b92c
Merge remote-tracking branch 'origin/develop' into SCMOD-8730
xbreizh Mar 26, 2021
c0ceb43
Simplify expiration_policy persistence
xbreizh Mar 26, 2021
7167d27
Removed extra columns
xbreizh Mar 26, 2021
2b767dd
extracted ExpirationPolicy.toDBString to new class
xbreizh Mar 26, 2021
b2896bf
Updated date regex
xbreizh Apr 1, 2021
f3c585f
Update interval doc syntax
xbreizh Apr 1, 2021
b2f7f26
Added foreign key and cascade deletion
xbreizh Apr 1, 2021
8e9aa5a
Added applyJobExpirationPolicy.sql
xbreizh Apr 1, 2021
aa41e47
Minor changes and copyright
xbreizh Apr 6, 2021
6b1301f
Update changelog
xbreizh Apr 6, 2021
01f091f
Merge develop
xbreizh Apr 6, 2021
8484f3c
Fix merge conflicts
xbreizh Apr 6, 2021
a0963e3
Re-add delete procedures
xbreizh Apr 6, 2021
092c2fe
Remodel expiration_policy script
xbreizh Apr 6, 2021
1f30bdb
Replaces cascade with verbose delete
xbreizh Apr 7, 2021
74cde33
Add index on job_expiration_policy table
xbreizh Apr 7, 2021
6c23dac
Typo
xbreizh Apr 7, 2021
be601a4
Update duration regex
xbreizh Apr 7, 2021
f96932d
Remove index
xbreizh Apr 7, 2021
a7389b1
Fixed duration regex
xbreizh Apr 7, 2021
b25c540
Reworked update policy query
xbreizh Apr 7, 2021
b2a0dbe
Outer join
xbreizh Apr 7, 2021
d86f435
Function calling instead of procedure
xbreizh Apr 7, 2021
7d4e1e2
Update policy execution frequency
xbreizh Apr 7, 2021
5fc97a8
Remove unused import
xbreizh Apr 7, 2021
4b034d3
Dropped modified functions
xbreizh Apr 7, 2021
a61f0a8
Review changes
xbreizh Apr 8, 2021
ae05771
Adjustment for new Job Status
xbreizh Apr 8, 2021
022d186
Fixed typo
xbreizh Apr 8, 2021
391daaf
Add support for Seconds (duration)
xbreizh Apr 8, 2021
e4ff0a6
Add validation on expiryTime
xbreizh Apr 8, 2021
379504a
remove extra /
xbreizh Apr 8, 2021
6b06c06
Add second in documentation
xbreizh Apr 8, 2021
36f9759
Compile pattern a single time
dermot-hardy Apr 8, 2021
0ea0ba6
Just warn if a date in the past is specified
dermot-hardy Apr 8, 2021
6d12bc5
DateHelper: Added line breaks to JavaDoc
dermot-hardy Apr 8, 2021
5285766
ExpirationPolicyHelper: Make into utility class
dermot-hardy Apr 8, 2021
55301c0
Moved expirationDate validation
xbreizh Apr 8, 2021
0846a11
typo
xbreizh Apr 8, 2021
0ffc1e6
Fix getJob(), getJobs() on retrieving policies
xbreizh Apr 8, 2021
6fd6d72
Changed the apply_expiration_policy execution time
xbreizh Apr 9, 2021
9a1548d
ExpirationPolicyHelper: Review changes
dermot-hardy Apr 9, 2021
81fc55e
Update documentation and release notes
xbreizh Apr 13, 2021
15f2438
Added missing status to contract
xbreizh Apr 15, 2021
29618a1
Updated architecture page
dermot-hardy Apr 16, 2021
1180cb8
Architecture page: Further update
dermot-hardy Apr 16, 2021
e2a613a
Architecture page: Further update
dermot-hardy Apr 16, 2021
d1e4fc3
Added primary key to job_expiration_policy table
dermot-hardy Apr 16, 2021
f4dbd54
Release notes: Moved out of breaking changes
dermot-hardy Apr 16, 2021
c002b4a
PolicyBuilder: Updated to reduce duplication
dermot-hardy Apr 16, 2021
23e3b78
JobsPut: Moved policy checking into try block
dermot-hardy Apr 16, 2021
42a58c3
Auto stash before merge of "SCMOD-8730" and "origin/SCMOD-8730"
xbreizh Apr 16, 2021
6724b62
Added PolicyBuilderTest
xbreizh Apr 16, 2021
c42c8f4
Replaced CALL with SELECT * FROM
xbreizh Apr 19, 2021
6fd26c6
Applied review comments
dermot-hardy Apr 19, 2021
32d375e
Auto stash before merge of "SCMOD-8730" and "origin/SCMOD-8730"
xbreizh Apr 20, 2021
6319192
Review adjustments
xbreizh Apr 20, 2021
9adf2a7
Review db changes
xbreizh Apr 20, 2021
5b95353
Matching develop to prevent merge conflict
xbreizh Apr 20, 2021
7fdf6fd
Merge branch 'develop' into SCMOD-8730
xbreizh Apr 20, 2021
53e115a
Fixed bug on getJobs()
xbreizh Apr 21, 2021
164e8a9
Converted expire_job into procedure
xbreizh Apr 21, 2021
d27a46e
Added support for system default
xbreizh Apr 21, 2021
52e38d9
Refactoring applyJobExpirationPolicy
xbreizh Apr 22, 2021
f0d69db
Merge remote-tracking branch 'origin/develop' into SCMOD-8730
xbreizh Apr 22, 2021
c1235d4
Call procedure
xbreizh Apr 22, 2021
de7e9c3
Reworked apply_job_expiration_policy()
xbreizh Apr 22, 2021
d7ffbb9
format applyJobExpirationPolicy
xbreizh Apr 23, 2021
0dd06c5
Updated logs
xbreizh Apr 23, 2021
85c8123
Added default operation for deletePolicy
xbreizh Apr 26, 2021
4d92887
Added log for statusCheckIntervalSeconds
xbreizh Apr 27, 2021
9d42370
Updated deletePolicy json operation name
xbreizh Apr 28, 2021
00ba946
Merge remote-tracking branch 'origin/develop' into SCMOD-8730
xbreizh Apr 29, 2021
645556e
Applied review comments
dermot-hardy Apr 29, 2021
ec30ab8
Renamed policy to expirablePolicy and removed default
xbreizh Apr 30, 2021
a6260b7
Fixed the system policy filter
xbreizh Apr 30, 2021
1df5d97
Refactored policyBuilder
xbreizh Apr 30, 2021
4fb40c5
Added expiration_policer
xbreizh Apr 30, 2021
4b05423
Fixed policer transfer
xbreizh Apr 30, 2021
a93fa8d
Added internal_process_failed_dependent_jobs on deleteOrExpireJob()
xbreizh Apr 30, 2021
bebfde0
Added default expiration_time on contract
xbreizh Apr 30, 2021
d01b41b
cleaned contract
xbreizh Apr 30, 2021
047cb8c
Merge branch 'develop' into SCMOD-8730
xbreizh May 6, 2021
0158d92
Fixed test
xbreizh May 6, 2021
66e5575
Fixed test
xbreizh May 6, 2021
a336cdf
Merge remote-tracking branch 'origin/SCMOD-8730' into SCMOD-8730
xbreizh May 6, 2021
845543c
Fixed tests
xbreizh May 6, 2021
21b8fc0
Refactored apply_job_expiration_policy()
xbreizh May 28, 2021
b41dad3
Hard-coded PROP_DEPENDENT_JOB_FAILURES to True
xbreizh May 28, 2021
504fb26
Merge branch 'SCMOD-8780-bf-merge' into SCMOD-8730
xbreizh May 28, 2021
87e6406
Merge branch 'develop' into SCMOD-8730
xbreizh May 28, 2021
7b53b68
Fixed failing test
xbreizh May 28, 2021
f8dce69
Formatting and removed obsolete description
xbreizh Jun 11, 2021
970efaf
Removed propagateDependentJobFailures
xbreizh Jun 14, 2021
6e051be
Removed fd
xbreizh Jun 14, 2021
f3783c4
Merge branch 'develop' into SCMOD-8730
xbreizh Jun 14, 2021
9ac8631
Removed LEFT
xbreizh Jun 14, 2021
655d63e
Added default_job_expiration_policy table
xbreizh Jun 14, 2021
b699967
Added columns
xbreizh Jun 16, 2021
c3b0eba
Updated release notes
xbreizh Jun 16, 2021
e852efd
Merge branch 'develop' into SCMOD-8730
xbreizh Jun 16, 2021
b6597d7
Added insert_default_expiry
xbreizh Jun 16, 2021
4779ec4
Added refresh_default_expiry()
xbreizh Jun 16, 2021
1231e86
Removed policy building
xbreizh Jun 17, 2021
ba3ef1e
Removing policer
xbreizh Jun 17, 2021
a8a9c84
Updated internal_upsert_job_policy()
xbreizh Jun 17, 2021
ee73941
Added basic_policy
xbreizh Jun 17, 2021
8b4cc95
Using sub-composite
xbreizh Jun 18, 2021
1d5f410
Merge branch 'develop' into SCMOD-8730
xbreizh Jun 18, 2021
a6737ab
Updated apply_job_expiration_policy()
xbreizh Jun 21, 2021
03ceed2
Refactoring
xbreizh Jun 22, 2021
1045e66
formatting
xbreizh Jun 22, 2021
028790b
Removed propagate_failure
xbreizh Jun 22, 2021
c2e0802
Removed propagate_failures
xbreizh Jun 23, 2021
8ad751b
Refactoring applyJobExpirationPolicy()
xbreizh Jun 23, 2021
1a795fb
cleanup
xbreizh Jun 23, 2021
67f2766
Restored policer on get_job()
xbreizh Jun 23, 2021
0639162
Fixed get_jobs()
xbreizh Jun 23, 2021
42a91d1
Updated architecture doc
xbreizh Jun 23, 2021
e0a4c0a
Adding explanations
xbreizh Jun 23, 2021
17f96e9
More refactoring
xbreizh Jun 23, 2021
3ba3e87
Corrected typo
xbreizh Jun 23, 2021
ab59a3c
Formatting
xbreizh Jun 23, 2021
ed10b71
doc
xbreizh Jun 23, 2021
e137d2c
More formatting
xbreizh Jun 23, 2021
257ee06
doc
xbreizh Jun 23, 2021
7a0833f
Added constraints
xbreizh Jun 24, 2021
e87336a
Added getDefaultSystemExpiry()
xbreizh Jun 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion docs/pages/en-us/Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ This table stores Ids of dependent jobs i.e. jobs which must be completed before

### Job Task Data

This table stores information on jobs which have dependent jobs and must wait for execution. The table contains enough information for the Job Tracking Worker and Job Service Scheduled Executor to forward on the job, once it's dependent jobs have all completed.
This table stores information on jobs which have dependent jobs and must wait for execution. The table contains enough information for the Job Tracking Worker and Job Service Scheduled Executor to forward on the job, once its dependent jobs have all completed.

| **Column** | **Data Type** | **Nullable?** | **Primary Key?** |
|----------------------|---------------|---------------|------------------|
Expand All @@ -163,3 +163,38 @@ This table stores information on jobs which have dependent jobs and must wait fo
| target_pipe | varchar(255) | No | |
| eligible_to_run_date | timestamp | Yes | |

### Job Expiration Policy

This table stores information about the expiration policy related to the jobs. The Job Service Scheduled Executor runs
at regular interval in order to apply those policies.

| **Column** | **Data Type** | **Nullable?** | **Primary Key?** |
|----------------------|---------------------|---------------|------------------|
| partition_id | varchar(40) | No | Yes |
| job_id | varchar(48) | No | Yes |
| job_status | job_status | No | Yes |
| operation | expiration_operation| No | |
| expiration_time | varchar(58) | No | |
| exact_expiry_time | timestamp | Yes | |
| last_modified_offset | interval | Yes | |

### Default Job Expiration Policy

This table stores the default expiration_policy related to the jobs. Its role is to provide a policy whenever missing
from the job_expiration_policy table

| **Column** | **Data Type** | **Nullable?** | **Primary Key?** |
|----------------------|---------------------|---------------|------------------|
| job_status | job_status | No | Yes |
| operation | expiration_operation| No | |
| expiration_time | varchar(58) | No | |
| create_date_offset | varchar(12) | Yes | |
| last_modified_offset | interval | Yes | |

### Enumeration Types

| **Enumerated Type** | **Enum labels** |
|----------------------|----------------------------------------------------------------|
| expiration_operation | Expire, Delete |
| job_status | Active, Cancelled, Completed, Expired, Failed, Paused, Waiting |
| expiration_policer | User, System |
1 change: 1 addition & 0 deletions job-service-acceptance-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<datastore.enabled>true</datastore.enabled>
</systemPropertyVariables>
<environmentVariables>
<CAF_LOG_LEVEL>DEBUG</CAF_LOG_LEVEL>
<CAF_APPNAME>test/jobservice-acceptance</CAF_APPNAME>
<CAF_CONFIG_PATH>${project.basedir}/test-configs</CAF_CONFIG_PATH>
<CAF_JOB_SERVICE_IMAGE>${dockerJobServiceOrg}job-service${dockerProjectVersion}</CAF_JOB_SERVICE_IMAGE>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ paths:
in: query
type: string
required: false
description: All - no status filter is applied (Default); NotCompleted - only those results with statuses other than Completed will be returned; Completed - only those results with Completed status will be returned; Inactive - only those results with inactive statuses (i.e. Completed, Failed, Cancelled) will be returned; NotFinished - only those results with unfinished statuses (ie. Active, Paused, Waiting) will be returned.
description: All - no status filter is applied (Default); NotCompleted - only those results with statuses other than Completed will be returned; Completed - only those results with Completed status will be returned; Inactive - only those results with inactive statuses (i.e. Completed, Failed, Cancelled, Expired) will be returned; NotFinished - only those results with unfinished statuses (ie. Active, Paused, Waiting) will be returned.
enum:
- All
- NotCompleted
Expand Down Expand Up @@ -121,6 +121,21 @@ paths:
$ref: "#/definitions/job"
503:
description: The request failed due to a database connection error.
/partitions/default-expiry:
get:
tags:
- Jobs
summary: Gets the default expiry
description: Returns the default expiry settings.
operationId: getDefaultExpiry
responses:
200:
description: Returns the default expiry settings.
schema:
schema:
$ref: "#/definitions/expirationPolicy"
503:
description: The request failed due to a database connection error.
/partitions/{partitionId}/jobs/{jobId}:
parameters:
- $ref: '#/parameters/partitionId'
Expand Down Expand Up @@ -210,8 +225,8 @@ paths:
type: boolean
headers:
CacheableJobStatus:
description: A response that includes this header with the value ‘true’ is eligible for caching in a cache specific to job status responses.
type: boolean
description: A response that includes this header with the value ‘true’ is eligible for caching in a cache specific to job status responses.
type: boolean
400:
description: The `jobId` parameter contains invalid characters.
503:
Expand Down Expand Up @@ -239,8 +254,8 @@ paths:
$ref: "#/definitions/job-status"
headers:
CacheableJobStatus:
description: A response that includes this header with the value ‘true’ is eligible for caching in a cache specific to job status responses.
type: boolean
description: A response that includes this header with the value ‘true’ is eligible for caching in a cache specific to job status responses.
type: boolean
400:
description: The `jobId` parameter contains invalid characters.
404:
Expand Down Expand Up @@ -377,6 +392,8 @@ definitions:
description:
type: string
description: The description of the job
expiry:
$ref: "#/definitions/expirationPolicy"
externalData:
# TODO: Should we make this more structured than just string
# Name/Value Pairs perhaps
Expand All @@ -402,7 +419,7 @@ definitions:
delay:
type: integer
format: int32
default: 0
default: 0
description: The time in seconds after the prerequisite job identifiers have completed before this job is eligible for running.
labels:
type: object
Expand All @@ -414,6 +431,66 @@ definitions:
example:
"tag:4": "4"
owner: "bob"
expirationPolicy:
dermot-hardy marked this conversation as resolved.
Show resolved Hide resolved
dermot-hardy marked this conversation as resolved.
Show resolved Hide resolved
type: object
properties:
dermot-hardy marked this conversation as resolved.
Show resolved Hide resolved
"Active":
$ref: "#/definitions/expirablePolicy"
"Completed":
$ref: "#/definitions/deletePolicy"
"Failed":
$ref: "#/definitions/deletePolicy"
"Cancelled":
$ref: "#/definitions/deletePolicy"
"Waiting":
$ref: "#/definitions/expirablePolicy"
"Paused":
$ref: "#/definitions/expirablePolicy"
"Expired":
$ref: "#/definitions/deletePolicy"
description: The expiration policy to be applied on the job
dermot-hardy marked this conversation as resolved.
Show resolved Hide resolved
deletePolicy:
type: object
properties:
expiryTime:
type: string
pattern: '^(?<fullyear>\d{4})-(?<month>0[1-9]|1[0-2])-(?<mday>0[1-9]|[12][0-9]|3[01])T(?<hour>[01][0-9]|2[0-3]):(?<minute>[0-5][0-9]):(?<second>[0-5][0-9]|60)(?<secfrac>\.[0-9]+)?(Z|(\+|-)(?<offset_hour>[01][0-9]|2[0-3]):(?<offset_minute>[0-5][0-9]))$|^(lastUpdateTime|createTime)\+((P)\d+[DYM])$|^(lastUpdateTime|createTime)\+(PT)?(\d+[HMS])$|^none$'
example: 2021-04-12T23:20:50.52Z, lastUpdateTime+P1D, createTime+P90M, createTime+PT9H, none
description: The delay before expiration
operation:
type: string
dermot-hardy marked this conversation as resolved.
Show resolved Hide resolved
enum:
- Delete
default: Delete
description: The action to apply on expired jobs
policer:
$ref: "#/definitions/policer"
description: The expiration details to be applied on the job
expirablePolicy:
type: object
properties:
expiryTime:
type: string
pattern: '^(?<fullyear>\d{4})-(?<month>0[1-9]|1[0-2])-(?<mday>0[1-9]|[12][0-9]|3[01])T(?<hour>[01][0-9]|2[0-3]):(?<minute>[0-5][0-9]):(?<second>[0-5][0-9]|60)(?<secfrac>\.[0-9]+)?(Z|(\+|-)(?<offset_hour>[01][0-9]|2[0-3]):(?<offset_minute>[0-5][0-9]))$|^(lastUpdateTime|createTime)\+((P)\d+[DYM])$|^(lastUpdateTime|createTime)\+(PT)?(\d+[HMS])$|^none$'
example: 2021-04-12T23:20:50.52Z, lastUpdateTime+P1D, createTime+P90M, createTime+PT9H, none
description: The delay before expiration
operation:
type: string
enum:
- Expire
- Delete
default: Expire
description: The action to apply on expired jobs
policer:
$ref: "#/definitions/policer"
description: The expiration details to be applied on the job
policer:
type: string
enum:
- User
- System
default: User
description: The instance defining the policy
worker-action:
type: object
required:
Expand Down Expand Up @@ -451,6 +528,8 @@ definitions:
description:
type: string
description: The description of the job
expiry:
$ref: "#/definitions/expirationPolicy"
externalData:
type: string
description: |
Expand Down Expand Up @@ -492,6 +571,7 @@ definitions:
- Failed
- Paused
- Waiting
- Expired
failure:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
--
-- Copyright 2016-2021 Micro Focus or one of its affiliates.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

/*
* Name: apply_job_expiration_policy
*
* Description:
* Expires or deletes jobs in accordance with their expiry policies.
* Policies can be found in 2 tables:
* - job_expiration_policy if the user provided it on job's creation ( alias user_p)
* - default_job_expiration_policy ( alias default_p)
* Each of those tables have two columns, respectively related, to create_date and last_update_date such as:
* - default_job_expiration_policy -> create_date_offset(varchar), last_modified_offset(interval)
* - job_expiration_policy -> exact_expiry_time(timestamp), last_modified_offset(interval)
* Only 1 of those fields maximum, by table, can be filled (the other one should be null)
*
* User's policy is used in priority if provided, default is applied otherwise
*
*/
CREATE OR REPLACE PROCEDURE apply_job_expiration_policy(
)
LANGUAGE plpgsql
AS $$
BEGIN

PERFORM NULL
FROM (
SELECT partition_id,
job_id,
COALESCE(user_p.operation, default_p.operation) AS operation
FROM job j
CROSS JOIN LATERAL (
-- Getting the latest status
SELECT status AS current_status
FROM
get_job(
partition_id,
job_id
)
LIMIT 1
) latest_status
CROSS JOIN default_job_expiration_policy default_p -- default expiration policy table
LEFT JOIN job_expiration_policy user_p -- user defined expiration policy table
USING (
partition_id,
job_id,
job_status
)
WHERE job_status = status
-- Order:
-- user_p.exact_expiry_time (1)
-- user_p.last_modified_offset (2)
-- default_p.last_modified_offset (3)
-- default_p.create_date_offset (4)
AND COALESCE(
COALESCE(
user_p.exact_expiry_time, ---------------------------------------(1)
last_update_date + COALESCE(
user_p.last_modified_offset, ----------------------------(2)
CASE
WHEN
default_p.last_modified_offset IS NOT NULL
THEN
default_p.last_modified_offset::INTERVAL --------(3)
END
)
)
,
CASE --------------------------------------------------------------------(4)
WHEN default_p.create_date_offset = 'infinity'
THEN 'infinity'::TIMESTAMP
WHEN default_p.create_date_offset IS NULL
THEN NULL
ELSE
(create_date + default_p.create_date_offset::INTERVAL)::TIMESTAMP
END
) <= now() -- compare to now to get only the expired jobs
) expired_jobs
CROSS JOIN LATERAL
delete_or_expire_job(
partition_id,
job_id,
operation
);
END;
$$;
2 changes: 1 addition & 1 deletion job-service-db/src/main/resources/procedures/cancelJob.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ BEGIN

-- Only support Cancel operation on jobs with current status 'Waiting', 'Active' or 'Paused'
-- And take out an exclusive update lock on the job row
SELECT status IN ('Completed', 'Failed') INTO v_is_finished
SELECT status IN ('Expired', 'Completed', 'Failed') INTO v_is_finished
FROM job
WHERE partition_id = in_partition_id
AND job_id = in_job_id
Expand Down
39 changes: 39 additions & 0 deletions job-service-db/src/main/resources/procedures/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
When adding a new procedure add a corresponding changeSet here with `runOnChange="true"` set.
If modifying an existing procedure, DO NOT add a new changeSet. The changes will be applied automatically.
-->
<changeSet id="create_apply_job_expiration_policy_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/applyJobExpirationPolicy.sql"
procedureName="apply_job_expiration_policy"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_cancel_job_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/cancelJob.sql"
procedureName="cancel_job"
Expand Down Expand Up @@ -69,6 +75,12 @@
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_delete_or_expire_job_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/deleteOrExpireJob.sql"
procedureName="delete_or_expire_job"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_delete_task_table_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/deleteTaskTable.sql"
procedureName="internal_delete_task_table"
Expand All @@ -91,12 +103,24 @@
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_expire_job_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/expireJob.sql"
procedureName="internal_expire_job"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_get_dependent_jobs_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/getDependentJobs.sql"
procedureName="get_dependent_jobs"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_get_default_expiry_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/getDefaultSystemExpiry.sql"
procedureName="get_default_expiry"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_get_job_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/getJob.sql"
procedureName="get_job"
Expand Down Expand Up @@ -295,6 +319,12 @@
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="create_upsert_job_policy_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/upsertJobPolicy.sql"
procedureName="internal_upsert_job_policy"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="drop_deleted_task_tables_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/dropDeletedTaskTables.sql"
procedureName="drop_deleted_task_tables"
Expand All @@ -307,4 +337,13 @@
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="refresh_default_expiry_proc" runOnChange="true" author="Gamma Team">
<createProcedure path="procedures/refreshDefaultExpiry.sql"
procedureName="refresh_default_expiry"
schemaName="public">
</createProcedure>
</changeSet>
<changeSet id="run_refresh_default_expiry_proc" runOnChange="true" author="Gamma Team">
<sql>CALL refresh_default_expiry();</sql>
</changeSet>
</databaseChangeLog>
Loading