Skip to content

Commit

Permalink
feat(command): add a command to execut cron jobs with running deno ta…
Browse files Browse the repository at this point in the history
…sk command:local
  • Loading branch information
douglasfdev committed Nov 15, 2023
1 parent dd4b7fb commit 9dd2916
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 30 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Neste projeto também foi incluido rotinas de Cron Jobs, para ele ficar escutand
Projeto feito com muito carinho, obviamente tem muito a melhorar, mas o intuito foi pegar algo que eu desconhecia completamente que era o Deno, juntamente da AWS e completar esse projeto.

### Comandos para rodar o projeto
Para rodar o projeto com docker em background: `docker-compose up -d`
Para rodar o projeto com docker em background: **`docker-compose up -d`**
Para iniciar o projeto localmente na sua maquina recomendo usar o **`deno task local`** as variaveis de ambiente estao apontando para **http://localhost:5022**
Este comando vai baixar a imagem do MySQL na versão 8, do LocalStack na ultima versão e do Deno na última versão LTS.
Para rodar o cron que fica lançando para o S3 ou para o SQS caso o S3 esteja fora do ar basta rodar no terminal **`deno task command:local`**

Para rodar o projeto em local basta rodar o comando `deno task local` na máquina

Expand Down
23 changes: 3 additions & 20 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
{
"imports": {
"$common": "./src/common/index.ts",
"$deps": "./src/deps/index.ts",
"$controllers": "./src/api/modules/v1/controllers/index.ts",
"$controller/": "./src/api/modules/v1/controllers/",
"$services": "./src/api/modules/v1/services/index.ts",
"$service/": "./src/api/modules/v1/services/",
"$repositories": "./src/api/modules/v1/repository/index.ts",
"$repository/": "./src/api/modules/v1/repository/",
"$components": "./src/api/modules/v1/components/index.ts",
"$component/": "./src/api/modules/v1/components/",
"$middlewares": "./src/api/middlewares/index.ts",
"$models": "./src/api/modules/v1/models/index.ts",
"$interfaces": "./src/common/interfaces/index.ts",
"$enums": "./src/common/enums/index.ts",
"$migrations": "./src/api/db/migrations/index.ts",
"$routes": "./src/api/modules/v1/routes/index.ts",
"$db": "./src/api/db/index.ts"
},
"importMap": "./import_map.json",
"tasks": {
"start": "APP_ENV=production deno run --allow-all src/main.ts",
"dev": "APP_ENV=development deno run --allow-all --watch src/main.ts",
"local": "APP_ENV=local deno run --allow-all --watch src/main.ts",
"docker:dev": "docker-compose -f ./docker/docker-compose.yml up -d"
"docker:dev": "docker-compose -f ./docker/docker-compose.yml up -d",
"command:local": "APP_ENV=local deno run --allow-all --watch src/main.ts --slinger"
},
"allow-net": "0.0.0.0:5001",
"allow-read": "."
Expand Down
21 changes: 21 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"imports": {
"$common": "./src/common/index.ts",
"$deps": "./src/deps/index.ts",
"$controllers": "./src/api/modules/v1/controllers/index.ts",
"$controller/": "./src/api/modules/v1/controllers/",
"$services": "./src/api/modules/v1/services/index.ts",
"$service/": "./src/api/modules/v1/services/",
"$repositories": "./src/api/modules/v1/repository/index.ts",
"$repository/": "./src/api/modules/v1/repository/",
"$components": "./src/api/modules/v1/components/index.ts",
"$component/": "./src/api/modules/v1/components/",
"$middlewares": "./src/api/middlewares/index.ts",
"$models": "./src/api/modules/v1/models/index.ts",
"$interfaces": "./src/common/interfaces/index.ts",
"$enums": "./src/common/enums/index.ts",
"$migrations": "./src/api/db/migrations/index.ts",
"$routes": "./src/api/modules/v1/routes/index.ts",
"$db": "./src/api/db/index.ts"
}
}
23 changes: 23 additions & 0 deletions src/api/modules/v1/components/Commands/Commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Slinger } from "$component/Jobs/Slinger.ts";

export class Commands {
private slingerArg = 0;

constructor() {
this.init();
}

private init() {
return this.slinger();
}

private async slinger() {
const command = Deno.args[this.slingerArg];

if (command !== '--slinger') return;

new Slinger();
}
}

export default new Commands();
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { FileService } from '$service/file/FileService.ts';
import { PersonService } from "$service/person/PersonService.ts";
import {
everyMinute,
hourly,
weekly,
cron,
start,
} from '$deps';
Expand All @@ -17,7 +16,6 @@ export class Slinger {
this.disparePersonIntoQueue();
this.dispareFilesPayloadIntoQueue();
start();
this.init();
}

private dispareFiles() {
Expand All @@ -33,4 +31,3 @@ export class Slinger {
}
}

export default new Slinger();
2 changes: 0 additions & 2 deletions src/api/modules/v1/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import S3 from "./AWS/s3.component.ts";
import SQS from "./AWS/sqs.component.ts";
import Slinger from "./Commands/Slinger.ts";

export {
S3,
SQS,
Slinger
};
4 changes: 1 addition & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
import { routing } from "$routes";
import { LoggerRoutes } from "$middlewares";
import { log, env } from "$common";
import { Slinger as Command } from "$component/Commands/Slinger.ts";
import "$migrations";
import "$component/Commands/Commands.ts"

class App {
public app: Application;
public commands: Command;

private corsOptions: CorsOptions = {
origin: "*",
Expand All @@ -24,7 +23,6 @@ class App {
this.middlewares();
this.init();
this.routes();
this.commands = new Command();
}

private middlewares() {
Expand Down

0 comments on commit 9dd2916

Please sign in to comment.