Merge branch 'main' into feat/stripe

This commit is contained in:
Pierre Maurice Schwang
2022-11-28 19:28:33 +01:00
committed by GitHub
17 changed files with 111 additions and 50 deletions

View File

@@ -13,5 +13,8 @@ ENCRYPTION_KEY=sample-encryption-key
APP_SECRET_KEY=sample-app-secret-key
REDIS_PORT=6379
REDIS_HOST=127.0.0.1
REDIS_USERNAME=redis_username
REDIS_PASSWORD=redis_password
REDIS_TLS=true
ENABLE_BULLMQ_DASHBOARD=false
SERVE_WEB_APP_SEPARATELY=true

View File

@@ -21,6 +21,9 @@ type AppConfig = {
serveWebAppSeparately: boolean;
redisHost: string;
redisPort: number;
redisUsername: string;
redisPassword: string;
redisTls: boolean;
enableBullMQDashboard: boolean;
bullMQDashboardUsername: string;
bullMQDashboardPassword: string;
@@ -55,14 +58,17 @@ const appConfig: AppConfig = {
postgresUsername:
process.env.POSTGRES_USERNAME || 'automatisch_development_user',
postgresPassword: process.env.POSTGRES_PASSWORD,
postgresEnableSsl: process.env.POSTGRES_ENABLE_SSL === 'true' ? true : false,
postgresEnableSsl: process.env.POSTGRES_ENABLE_SSL === 'true',
encryptionKey: process.env.ENCRYPTION_KEY || '',
appSecretKey: process.env.APP_SECRET_KEY || '',
serveWebAppSeparately,
redisHost: process.env.REDIS_HOST || '127.0.0.1',
redisPort: parseInt(process.env.REDIS_PORT || '6379'),
redisUsername: process.env.REDIS_USERNAME,
redisPassword: process.env.REDIS_PASSWORD,
redisTls: process.env.REDIS_TLS === 'true',
enableBullMQDashboard:
process.env.ENABLE_BULLMQ_DASHBOARD === 'true' ? true : false,
process.env.ENABLE_BULLMQ_DASHBOARD === 'true',
bullMQDashboardUsername: process.env.BULLMQ_DASHBOARD_USERNAME,
bullMQDashboardPassword: process.env.BULLMQ_DASHBOARD_PASSWORD,
baseUrl,

View File

@@ -1,9 +1,24 @@
import appConfig from './app';
const redisConfig = {
type TRedisConfig = {
host: string,
port: number,
username?: string,
password?: string,
tls?: Record<string, unknown>,
enableOfflineQueue: boolean,
}
const redisConfig: TRedisConfig = {
host: appConfig.redisHost,
port: appConfig.redisPort,
username: appConfig.redisUsername,
password: appConfig.redisPassword,
enableOfflineQueue: false,
};
if (appConfig.redisTls) {
redisConfig.tls = {};
}
export default redisConfig;

View File

@@ -1,12 +1,17 @@
import type { AxiosResponse, AxiosError } from 'axios';
import { IJSONObject } from '@automatisch/types';
import BaseError from './base';
export default class HttpError extends BaseError {
constructor(error: IJSONObject) {
response: AxiosResponse;
constructor(error: AxiosError) {
const computedError =
((error.response as IJSONObject)?.data as IJSONObject) ||
(error.message as string);
error.response?.data as IJSONObject ||
error.message as string;
super(computedError);
this.response = error.response;
}
}

View File

@@ -1,5 +1,6 @@
import Context from '../../types/express/context';
import flowQueue from '../../queues/flow';
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../../helpers/remove-job-configuration';
type Params = {
input: {
@@ -51,6 +52,8 @@ const updateFlowStatus = async (
{
repeat: repeatOptions,
jobId: flow.id,
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS
}
);
} else {

View File

@@ -0,0 +1,10 @@
export const REMOVE_AFTER_30_DAYS_OR_150_JOBS = {
age: 30 * 24 * 3600,
count: 150,
};
export const REMOVE_AFTER_7_DAYS_OR_50_JOBS = {
age: 7 * 24 * 3600,
count: 50,
};

View File

@@ -4,6 +4,7 @@ import logger from '../helpers/logger';
import Step from '../models/step';
import actionQueue from '../queues/action';
import { processAction } from '../services/action';
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../helpers/remove-job-configuration';
type JobData = {
flowId: string;
@@ -31,7 +32,12 @@ export const worker = new Worker(
stepId: nextStep.id,
};
await actionQueue.add(jobName, jobPayload);
const jobOptions = {
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
}
await actionQueue.add(jobName, jobPayload, jobOptions);
},
{ connection: redisConfig }
);
@@ -42,7 +48,7 @@ worker.on('completed', (job) => {
worker.on('failed', (job, err) => {
logger.info(
`JOB ID: ${job.id} - FLOW ID: ${job.data.flowId} has failed22 to start with ${err.message}`
`JOB ID: ${job.id} - FLOW ID: ${job.data.flowId} has failed to start with ${err.message}`
);
});

View File

@@ -4,6 +4,7 @@ import logger from '../helpers/logger';
import triggerQueue from '../queues/trigger';
import { processFlow } from '../services/flow';
import Flow from '../models/flow';
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../helpers/remove-job-configuration';
export const worker = new Worker(
'flow',
@@ -17,6 +18,11 @@ export const worker = new Worker(
const reversedData = data.reverse();
const jobOptions = {
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
}
for (const triggerItem of reversedData) {
const jobName = `${triggerStep.id}-${triggerItem.meta.internalId}`;
@@ -26,7 +32,7 @@ export const worker = new Worker(
triggerItem,
};
await triggerQueue.add(jobName, jobPayload);
await triggerQueue.add(jobName, jobPayload, jobOptions);
}
if (error) {
@@ -38,7 +44,7 @@ export const worker = new Worker(
error,
};
await triggerQueue.add(jobName, jobPayload);
await triggerQueue.add(jobName, jobPayload, jobOptions);
}
},
{ connection: redisConfig }

View File

@@ -5,6 +5,7 @@ import { IJSONObject, ITriggerItem } from '@automatisch/types';
import actionQueue from '../queues/action';
import Step from '../models/step';
import { processTrigger } from '../services/trigger';
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../helpers/remove-job-configuration';
type JobData = {
flowId: string;
@@ -32,7 +33,12 @@ export const worker = new Worker(
stepId: nextStep.id,
};
await actionQueue.add(jobName, jobPayload);
const jobOptions = {
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
}
await actionQueue.add(jobName, jobPayload, jobOptions);
},
{ connection: redisConfig }
);