feat: Convert workers to use js files

This commit is contained in:
Faruk AYDIN
2023-12-28 13:24:53 +01:00
parent 00c876dd93
commit d1427ffd54
6 changed files with 10 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import { Worker } from 'bullmq'; import { Worker } from 'bullmq';
import process from 'node:process';
import * as Sentry from '../helpers/sentry.ee'; import * as Sentry from '../helpers/sentry.ee';
import redisConfig from '../config/redis'; import redisConfig from '../config/redis';
@@ -12,19 +13,13 @@ import {
} from '../helpers/remove-job-configuration'; } from '../helpers/remove-job-configuration';
import delayAsMilliseconds from '../helpers/delay-as-milliseconds'; import delayAsMilliseconds from '../helpers/delay-as-milliseconds';
type JobData = {
flowId: string;
executionId: string;
stepId: string;
};
const DEFAULT_DELAY_DURATION = 0; const DEFAULT_DELAY_DURATION = 0;
export const worker = new Worker( export const worker = new Worker(
'action', 'action',
async (job) => { async (job) => {
const { stepId, flowId, executionId, computedParameters, executionStep } = const { stepId, flowId, executionId, computedParameters, executionStep } =
await processAction(job.data as JobData); await processAction(job.data);
if (executionStep.isFailed) return; if (executionStep.isFailed) return;

View File

@@ -1,11 +1,11 @@
import { Worker } from 'bullmq'; import { Worker } from 'bullmq';
import process from 'node:process';
import * as Sentry from '../helpers/sentry.ee'; import * as Sentry from '../helpers/sentry.ee';
import redisConfig from '../config/redis'; import redisConfig from '../config/redis';
import logger from '../helpers/logger'; import logger from '../helpers/logger';
import appConfig from '../config/app'; import appConfig from '../config/app';
import User from '../models/user'; import User from '../models/user';
import Execution from '../models/execution';
import ExecutionStep from '../models/execution-step'; import ExecutionStep from '../models/execution-step';
export const worker = new Worker( export const worker = new Worker(
@@ -23,7 +23,7 @@ export const worker = new Worker(
.$relatedQuery('executions') .$relatedQuery('executions')
.withSoftDeleted() .withSoftDeleted()
.select('executions.id') .select('executions.id')
).map((execution: Execution) => execution.id); ).map((execution) => execution.id);
await ExecutionStep.query() await ExecutionStep.query()
.withSoftDeleted() .withSoftDeleted()

View File

@@ -1,4 +1,5 @@
import { Worker } from 'bullmq'; import { Worker } from 'bullmq';
import process from 'node:process';
import * as Sentry from '../helpers/sentry.ee'; import * as Sentry from '../helpers/sentry.ee';
import redisConfig from '../config/redis'; import redisConfig from '../config/redis';
@@ -11,7 +12,7 @@ const isCloudSandbox = () => {
return appConfig.isCloud && !appConfig.isProd; return appConfig.isCloud && !appConfig.isProd;
}; };
const isAutomatischEmail = (email: string) => { const isAutomatischEmail = (email) => {
return email.endsWith('@automatisch.io'); return email.endsWith('@automatisch.io');
}; };

View File

@@ -1,4 +1,5 @@
import { Worker } from 'bullmq'; import { Worker } from 'bullmq';
import process from 'node:process';
import * as Sentry from '../helpers/sentry.ee'; import * as Sentry from '../helpers/sentry.ee';
import redisConfig from '../config/redis'; import redisConfig from '../config/redis';

View File

@@ -1,4 +1,5 @@
import { Worker } from 'bullmq'; import { Worker } from 'bullmq';
import process from 'node:process';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import * as Sentry from '../helpers/sentry.ee'; import * as Sentry from '../helpers/sentry.ee';
import redisConfig from '../config/redis'; import redisConfig from '../config/redis';

View File

@@ -1,6 +1,6 @@
import { Worker } from 'bullmq'; import { Worker } from 'bullmq';
import process from 'node:process';
import { IJSONObject, ITriggerItem } from '@automatisch/types';
import * as Sentry from '../helpers/sentry.ee'; import * as Sentry from '../helpers/sentry.ee';
import redisConfig from '../config/redis'; import redisConfig from '../config/redis';
import logger from '../helpers/logger'; import logger from '../helpers/logger';
@@ -12,18 +12,11 @@ import {
REMOVE_AFTER_7_DAYS_OR_50_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS,
} from '../helpers/remove-job-configuration'; } from '../helpers/remove-job-configuration';
type JobData = {
flowId: string;
stepId: string;
triggerItem?: ITriggerItem;
error?: IJSONObject;
};
export const worker = new Worker( export const worker = new Worker(
'trigger', 'trigger',
async (job) => { async (job) => {
const { flowId, executionId, stepId, executionStep } = await processTrigger( const { flowId, executionId, stepId, executionStep } = await processTrigger(
job.data as JobData job.data
); );
if (executionStep.isFailed) return; if (executionStep.isFailed) return;