feat(cli): add start-worker command
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
import './config/orm';
|
||||
import './workers/processor';
|
||||
export { worker } from './workers/processor';
|
||||
|
@@ -4,7 +4,7 @@ import redisConfig from '../config/redis';
|
||||
import Flow from '../models/flow';
|
||||
import logger from '../helpers/logger';
|
||||
|
||||
const worker = new Worker(
|
||||
export const worker = new Worker(
|
||||
'processor',
|
||||
async (job) => {
|
||||
const flow = await Flow.query().findById(job.data.flowId).throwIfNotFound();
|
||||
|
1
packages/backend/worker.d.ts
vendored
Normal file
1
packages/backend/worker.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './dist/src/worker';
|
2
packages/backend/worker.js
Normal file
2
packages/backend/worker.js
Normal file
@@ -0,0 +1,2 @@
|
||||
/* eslint-disable */
|
||||
module.exports = require('./dist/src/worker.js');
|
49
packages/cli/src/commands/start-worker.ts
Normal file
49
packages/cli/src/commands/start-worker.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { Command, Flags } from '@oclif/core';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
export default class StartWorker extends Command {
|
||||
static description = 'Run automatisch worker';
|
||||
|
||||
static flags = {
|
||||
env: Flags.string({
|
||||
multiple: true,
|
||||
char: 'e',
|
||||
}),
|
||||
'env-file': Flags.string(),
|
||||
}
|
||||
|
||||
async prepareEnvVars(): Promise<void> {
|
||||
const { flags } = await this.parse(StartWorker);
|
||||
|
||||
if (flags['env-file']) {
|
||||
const envFile = readFileSync(flags['env-file'], 'utf8');
|
||||
const envConfig = dotenv.parse(envFile);
|
||||
|
||||
for (const key in envConfig) {
|
||||
const value = envConfig[key];
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags.env) {
|
||||
for (const env of flags.env) {
|
||||
const [key, value] = env.split('=');
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// must serve until more customization is introduced
|
||||
delete process.env.SERVE_WEB_APP_SEPARATELY;
|
||||
}
|
||||
|
||||
async runWorker(): Promise<void> {
|
||||
await import('@automatisch/backend/worker');
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
await this.prepareEnvVars();
|
||||
|
||||
await this.runWorker();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user