mirror of
https://github.com/feeddeck/feeddeck.git
synced 2026-04-28 09:57:47 -05:00
This commit refactors the existing tools, by moving the tools logic to a new `tools.ts` file, so that the main `cmd.ts` file remains clear. Besides that we also add a new tool `get-feed` which can be used to run the `getFeed` function from the command line. The function is called with a source and returns the generated source and items, as they are saved in the database by the `add-source-v1` Supabase edge function.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { log } from '../_shared/utils/log.ts';
|
|
import { runScheduler } from './scheduler/scheduler.ts';
|
|
import { runWorker } from './worker/worker.ts';
|
|
import { runTools } from './tools/tools.ts';
|
|
|
|
/**
|
|
* Next to the Supabase Edge functions we also have to create an command which
|
|
* can be run inside of a Docker container. This command is used to start the
|
|
* scheduler or worker, to refetch the feeds for all user sources.
|
|
*/
|
|
const main = (args: string[]) => {
|
|
if (args.length === 1 && args[0] === 'scheduler') {
|
|
log('info', 'Start scheduler...');
|
|
runScheduler().then(() => {
|
|
Deno.exit(0);
|
|
}).catch((err) => {
|
|
log('error', 'Scheduler crashed', { error: err.toString() });
|
|
Deno.exit(1);
|
|
});
|
|
} else if (args.length === 1 && args[0] === 'worker') {
|
|
log('info', 'Start worker...');
|
|
runWorker().then(() => {
|
|
Deno.exit(0);
|
|
}).catch((err) => {
|
|
log('error', 'Worker crashed', { error: err.toString() });
|
|
Deno.exit(1);
|
|
});
|
|
} else if (args.length >= 2 && args[0] === 'tools') {
|
|
log('info', 'Start tools...');
|
|
runTools(args).then(() => {
|
|
Deno.exit(0);
|
|
}).catch((err) => {
|
|
log('error', 'Tools crashed', { error: err.toString() });
|
|
Deno.exit(1);
|
|
});
|
|
} else {
|
|
log('error', 'Invalid command-line arguments', { args: args });
|
|
Deno.exit(1);
|
|
}
|
|
};
|
|
|
|
main(Deno.args);
|