feat: cron job to update repo periodically
This commit is contained in:
parent
6f6937f457
commit
930dcc6ae8
5 changed files with 32 additions and 3 deletions
|
@ -44,6 +44,7 @@
|
|||
"jsonwebtoken": "^8.5.1",
|
||||
"mock-fs": "^5.1.2",
|
||||
"node-cache": "^5.1.2",
|
||||
"node-cron": "^3.0.1",
|
||||
"node-port-scanner": "^3.0.1",
|
||||
"p-iteration": "^1.1.8",
|
||||
"pg": "^8.7.3",
|
||||
|
@ -70,6 +71,7 @@
|
|||
"@types/jsonwebtoken": "^8.5.8",
|
||||
"@types/mock-fs": "^4.13.1",
|
||||
"@types/node": "17.0.31",
|
||||
"@types/node-cron": "^3.0.2",
|
||||
"@types/pg": "^8.6.5",
|
||||
"@types/session-file-store": "^1.2.2",
|
||||
"@types/tcp-port-used": "^1.0.1",
|
||||
|
|
15
packages/system-api/src/core/jobs/jobs.ts
Normal file
15
packages/system-api/src/core/jobs/jobs.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import cron from 'node-cron';
|
||||
import config from '../../config';
|
||||
import logger from '../../config/logger/logger';
|
||||
import { updateRepo } from '../../helpers/repo-helpers';
|
||||
|
||||
const startJobs = () => {
|
||||
logger.info('Starting cron jobs...');
|
||||
|
||||
cron.schedule('0 * * * *', () => {
|
||||
logger.info('Cloning apps repo...');
|
||||
updateRepo(config.APPS_REPO_ID);
|
||||
});
|
||||
};
|
||||
|
||||
export default startJobs;
|
|
@ -258,9 +258,6 @@ describe('getUpdateInfo', () => {
|
|||
it('Should return update info', async () => {
|
||||
const updateInfo = await getUpdateInfo(app1.id);
|
||||
|
||||
console.log(app1);
|
||||
console.log(updateInfo);
|
||||
|
||||
expect(updateInfo?.latest).toBe(app1.tipi_version);
|
||||
expect(updateInfo?.current).toBe(1);
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ import appsService from './modules/apps/apps.service';
|
|||
import { runUpdates } from './core/updates/run';
|
||||
import recover from './core/updates/recover-migrations';
|
||||
import { cloneRepo, updateRepo } from './helpers/repo-helpers';
|
||||
import startJobs from './core/jobs/jobs';
|
||||
|
||||
let corsOptions = __prod__
|
||||
? {
|
||||
|
@ -75,6 +76,7 @@ const main = async () => {
|
|||
httpServer.listen(port, async () => {
|
||||
await cloneRepo(config.APPS_REPO_ID);
|
||||
await updateRepo(config.APPS_REPO_ID);
|
||||
startJobs();
|
||||
// Start apps
|
||||
appsService.startAllApps();
|
||||
console.info(`Server running on port ${port} 🚀 Production => ${__prod__}`);
|
||||
|
|
13
pnpm-lock.yaml
generated
13
pnpm-lock.yaml
generated
|
@ -148,6 +148,7 @@ importers:
|
|||
'@types/jsonwebtoken': ^8.5.8
|
||||
'@types/mock-fs': ^4.13.1
|
||||
'@types/node': 17.0.31
|
||||
'@types/node-cron': ^3.0.2
|
||||
'@types/pg': ^8.6.5
|
||||
'@types/session-file-store': ^1.2.2
|
||||
'@types/tcp-port-used': ^1.0.1
|
||||
|
@ -181,6 +182,7 @@ importers:
|
|||
jsonwebtoken: ^8.5.1
|
||||
mock-fs: ^5.1.2
|
||||
node-cache: ^5.1.2
|
||||
node-cron: ^3.0.1
|
||||
node-port-scanner: ^3.0.1
|
||||
nodemon: ^2.0.15
|
||||
p-iteration: ^1.1.8
|
||||
|
@ -218,6 +220,7 @@ importers:
|
|||
jsonwebtoken: 8.5.1
|
||||
mock-fs: 5.1.2
|
||||
node-cache: 5.1.2
|
||||
node-cron: 3.0.1
|
||||
node-port-scanner: 3.0.1
|
||||
p-iteration: 1.1.8
|
||||
pg: 8.7.3
|
||||
|
@ -243,6 +246,7 @@ importers:
|
|||
'@types/jsonwebtoken': 8.5.8
|
||||
'@types/mock-fs': 4.13.1
|
||||
'@types/node': 17.0.31
|
||||
'@types/node-cron': 3.0.2
|
||||
'@types/pg': 8.6.5
|
||||
'@types/session-file-store': 1.2.2
|
||||
'@types/tcp-port-used': 1.0.1
|
||||
|
@ -3884,6 +3888,10 @@ packages:
|
|||
resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}
|
||||
dev: false
|
||||
|
||||
/@types/node-cron/3.0.2:
|
||||
resolution: {integrity: sha512-SK/4GYWiWvGLPl/yv+Tm5oLYbzMx1V3y7CsNTvOb3vF8O9oXH11U6/zckISHnBl4YH8MvXHFIUXbYoBONSdmzw==}
|
||||
dev: true
|
||||
|
||||
/@types/node/10.17.60:
|
||||
resolution: {integrity: sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==}
|
||||
dev: false
|
||||
|
@ -9953,6 +9961,11 @@ packages:
|
|||
clone: 2.1.2
|
||||
dev: false
|
||||
|
||||
/node-cron/3.0.1:
|
||||
resolution: {integrity: sha512-RAWZTNn2M5KDIUV/389UX0EXsqvdFAwc9QwHQceh0Ga56dygqSRthqIjwpgZsoDspHGt2rkHdk9Z4RgfPMdALw==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
dev: false
|
||||
|
||||
/node-domexception/1.0.0:
|
||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||
engines: {node: '>=10.5.0'}
|
||||
|
|
Loading…
Add table
Reference in a new issue