Skip to content

Commit

Permalink
update default retention policy in sql
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed May 28, 2021
1 parent e362387 commit 4c7bdf8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
40 changes: 21 additions & 19 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,27 @@ If you need to interact with pg-boss outside of Node.js, such as other clients o
The following command is the definition of the primary job table. For manual job creation, the only required column is `name`. All other columns are nullable or have sensible defaults.

```sql
CREATE TABLE ${schema}.job (
id uuid primary key not null default gen_random_uuid(),
name text not null,
priority integer not null default(0),
data jsonb,
state ${schema}.job_state not null default('${states.created}'),
retryLimit integer not null default(0),
retryCount integer not null default(0),
retryDelay integer not null default(0),
retryBackoff boolean not null default false,
startAfter timestamp with time zone not null default now(),
startedOn timestamp with time zone,
singletonKey text,
singletonOn timestamp without time zone,
expireIn interval not null default interval '15 minutes',
createdOn timestamp with time zone not null default now(),
completedOn timestamp with time zone,
keepUntil timestamp with time zone NOT NULL default now() + interval '30 days'
)
CREATE TABLE ${schema}.job (
id uuid primary key not null default gen_random_uuid(),
name text not null,
priority integer not null default(0),
data jsonb,
state ${schema}.job_state not null default('${states.created}'),
retryLimit integer not null default(0),
retryCount integer not null default(0),
retryDelay integer not null default(0),
retryBackoff boolean not null default false,
startAfter timestamp with time zone not null default now(),
startedOn timestamp with time zone,
singletonKey text,
singletonOn timestamp without time zone,
expireIn interval not null default interval '15 minutes',
createdOn timestamp with time zone not null default now(),
completedOn timestamp with time zone,
keepUntil timestamp with time zone NOT NULL default now() + interval '14 days',
on_complete boolean not null default true,
output jsonb
)
```

# Events
Expand Down
6 changes: 4 additions & 2 deletions src/migrationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function getAll (schema, config) {
`CREATE INDEX IF NOT EXISTS job_fetch ON ${schema}.job (name text_pattern_ops, startAfter) WHERE state < 'active'`,
`ALTER TABLE ${schema}.job ADD output jsonb`,
`ALTER TABLE ${schema}.archive ADD output jsonb`,
`ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT false`
`ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT false`,
`ALTER TABLE ${schema}.job ALTER COLUMN keepuntil SET DEFAULT now() + interval '14 days'`
],
uninstall: [
`DROP INDEX ${schema}.job_fetch`,
Expand All @@ -87,7 +88,8 @@ function getAll (schema, config) {
`CREATE UNIQUE INDEX job_singletonKey ON ${schema}.job (name, singletonKey) WHERE state < 'completed' AND singletonOn IS NULL`,
`ALTER TABLE ${schema}.job DROP COLUMN output`,
`ALTER TABLE ${schema}.archive DROP COLUMN output`,
`ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT true`
`ALTER TABLE ${schema}.job ALTER COLUMN on_complete SET DEFAULT true`,
`ALTER TABLE ${schema}.job ALTER COLUMN keepuntil SET DEFAULT now() + interval '30 days'`
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function createJobTable (schema) {
expireIn interval not null default interval '15 minutes',
createdOn timestamp with time zone not null default now(),
completedOn timestamp with time zone,
keepUntil timestamp with time zone NOT NULL default now() + interval '30 days',
keepUntil timestamp with time zone NOT NULL default now() + interval '14 days',
on_complete boolean not null default true,
output jsonb
)
Expand Down

0 comments on commit 4c7bdf8

Please sign in to comment.