Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create table "integrationsBackup" as
select *
from "integrations"
where 1 = 2;

alter table "integrationsBackup"
add column "backupCreatedAt" timestamptz not null default now();

create index if not exists ix_integration_history_integration_id on "integrationsBackup" ("id");
create index if not exists ix_integration_history_history_created_at on "integrationsBackup" ("backupCreatedAt");
24 changes: 24 additions & 0 deletions services/apps/cron_service/src/jobs/integrationsBackup.job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import CronTime from 'cron-time-generator'

import { IS_PROD_ENV } from '@crowd/common'
import { WRITE_DB_CONFIG, getDbConnection } from '@crowd/data-access-layer/src/database'

import { IJobDefinition } from '../types'

const job: IJobDefinition = {
name: 'integrations-backup',
cronTime: CronTime.every(1).days(),
timeout: 60 * 60, // 1 hour = 60 * 60 seconds
enabled: async () => IS_PROD_ENV,
process: async (ctx) => {
ctx.log.info('Starting integrations backup job!')
const dbConnection = await getDbConnection(WRITE_DB_CONFIG(), 1, 0)
await dbConnection.query(`insert into "integrationsBackup" select * from "integrations";`)
await dbConnection.query(
`delete from "integrationsBackup" where "backupCreatedAt" < now() - interval '2 months'`,
)
ctx.log.info('Integrations backup job completed!')
},
}

export default job
Loading