Skip to content

Commit 9dd2916

Browse files
committed
feat(command): add a command to execut cron jobs with running deno task command:local
1 parent dd4b7fb commit 9dd2916

File tree

7 files changed

+52
-30
lines changed

7 files changed

+52
-30
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Neste projeto também foi incluido rotinas de Cron Jobs, para ele ficar escutand
1919
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.
2020

2121
### Comandos para rodar o projeto
22-
Para rodar o projeto com docker em background: `docker-compose up -d`
22+
Para rodar o projeto com docker em background: **`docker-compose up -d`**
23+
Para iniciar o projeto localmente na sua maquina recomendo usar o **`deno task local`** as variaveis de ambiente estao apontando para **http://localhost:5022**
2324
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.
25+
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`**
2426

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

deno.json

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
{
2-
"imports": {
3-
"$common": "./src/common/index.ts",
4-
"$deps": "./src/deps/index.ts",
5-
"$controllers": "./src/api/modules/v1/controllers/index.ts",
6-
"$controller/": "./src/api/modules/v1/controllers/",
7-
"$services": "./src/api/modules/v1/services/index.ts",
8-
"$service/": "./src/api/modules/v1/services/",
9-
"$repositories": "./src/api/modules/v1/repository/index.ts",
10-
"$repository/": "./src/api/modules/v1/repository/",
11-
"$components": "./src/api/modules/v1/components/index.ts",
12-
"$component/": "./src/api/modules/v1/components/",
13-
"$middlewares": "./src/api/middlewares/index.ts",
14-
"$models": "./src/api/modules/v1/models/index.ts",
15-
"$interfaces": "./src/common/interfaces/index.ts",
16-
"$enums": "./src/common/enums/index.ts",
17-
"$migrations": "./src/api/db/migrations/index.ts",
18-
"$routes": "./src/api/modules/v1/routes/index.ts",
19-
"$db": "./src/api/db/index.ts"
20-
},
2+
"importMap": "./import_map.json",
213
"tasks": {
224
"start": "APP_ENV=production deno run --allow-all src/main.ts",
235
"dev": "APP_ENV=development deno run --allow-all --watch src/main.ts",
246
"local": "APP_ENV=local deno run --allow-all --watch src/main.ts",
25-
"docker:dev": "docker-compose -f ./docker/docker-compose.yml up -d"
7+
"docker:dev": "docker-compose -f ./docker/docker-compose.yml up -d",
8+
"command:local": "APP_ENV=local deno run --allow-all --watch src/main.ts --slinger"
269
},
2710
"allow-net": "0.0.0.0:5001",
2811
"allow-read": "."

import_map.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"imports": {
3+
"$common": "./src/common/index.ts",
4+
"$deps": "./src/deps/index.ts",
5+
"$controllers": "./src/api/modules/v1/controllers/index.ts",
6+
"$controller/": "./src/api/modules/v1/controllers/",
7+
"$services": "./src/api/modules/v1/services/index.ts",
8+
"$service/": "./src/api/modules/v1/services/",
9+
"$repositories": "./src/api/modules/v1/repository/index.ts",
10+
"$repository/": "./src/api/modules/v1/repository/",
11+
"$components": "./src/api/modules/v1/components/index.ts",
12+
"$component/": "./src/api/modules/v1/components/",
13+
"$middlewares": "./src/api/middlewares/index.ts",
14+
"$models": "./src/api/modules/v1/models/index.ts",
15+
"$interfaces": "./src/common/interfaces/index.ts",
16+
"$enums": "./src/common/enums/index.ts",
17+
"$migrations": "./src/api/db/migrations/index.ts",
18+
"$routes": "./src/api/modules/v1/routes/index.ts",
19+
"$db": "./src/api/db/index.ts"
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Slinger } from "$component/Jobs/Slinger.ts";
2+
3+
export class Commands {
4+
private slingerArg = 0;
5+
6+
constructor() {
7+
this.init();
8+
}
9+
10+
private init() {
11+
return this.slinger();
12+
}
13+
14+
private async slinger() {
15+
const command = Deno.args[this.slingerArg];
16+
17+
if (command !== '--slinger') return;
18+
19+
new Slinger();
20+
}
21+
}
22+
23+
export default new Commands();

src/api/modules/v1/components/Commands/Slinger.ts renamed to src/api/modules/v1/components/Jobs/Slinger.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { FileService } from '$service/file/FileService.ts';
22
import { PersonService } from "$service/person/PersonService.ts";
33
import {
4-
everyMinute,
5-
hourly,
4+
weekly,
65
cron,
76
start,
87
} from '$deps';
@@ -17,7 +16,6 @@ export class Slinger {
1716
this.disparePersonIntoQueue();
1817
this.dispareFilesPayloadIntoQueue();
1918
start();
20-
this.init();
2119
}
2220

2321
private dispareFiles() {
@@ -33,4 +31,3 @@ export class Slinger {
3331
}
3432
}
3533

36-
export default new Slinger();
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import S3 from "./AWS/s3.component.ts";
22
import SQS from "./AWS/sqs.component.ts";
3-
import Slinger from "./Commands/Slinger.ts";
43

54
export {
65
S3,
76
SQS,
8-
Slinger
97
};

src/main.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import {
66
import { routing } from "$routes";
77
import { LoggerRoutes } from "$middlewares";
88
import { log, env } from "$common";
9-
import { Slinger as Command } from "$component/Commands/Slinger.ts";
109
import "$migrations";
10+
import "$component/Commands/Commands.ts"
1111

1212
class App {
1313
public app: Application;
14-
public commands: Command;
1514

1615
private corsOptions: CorsOptions = {
1716
origin: "*",
@@ -24,7 +23,6 @@ class App {
2423
this.middlewares();
2524
this.init();
2625
this.routes();
27-
this.commands = new Command();
2826
}
2927

3028
private middlewares() {

0 commit comments

Comments
 (0)