This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable implicit-arrow-linebreak */ | ||
/* eslint-disable class-methods-use-this */ | ||
import { CronJob } from 'cron'; | ||
import AppQueue from './queue'; | ||
|
||
export default class AppCron { | ||
cron: CronJob; | ||
|
||
queue: AppQueue; | ||
|
||
constructor(queueInstance: AppQueue) { | ||
this.cron = new CronJob( | ||
'*/1 * * * *', | ||
this.job(), | ||
null, | ||
true, | ||
'America/Sao_Paulo', | ||
); | ||
this.queue = queueInstance; | ||
} | ||
|
||
setup() { | ||
this.cron.start(); | ||
} | ||
|
||
job() { | ||
return () => { | ||
console.log('[Cron] slow job started'); | ||
this.queue.enqueue( | ||
() => | ||
new Promise((resolve) => { | ||
setTimeout(() => { | ||
console.log('[Cron] slow job finished'); | ||
resolve('ok'); | ||
}, 3000); | ||
}), | ||
); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,49 @@ | ||
/* eslint-disable implicit-arrow-linebreak */ | ||
import dotenv from 'dotenv'; | ||
import express from 'express'; | ||
|
||
import { DiscordBot } from './discord'; | ||
import Controller from './core/controller'; | ||
// import { DiscordBot } from './discord'; | ||
// import Controller from './core/controller'; | ||
// import { parseFeed } from './feed'; | ||
// import { aaa } from './test'; | ||
import AppQueue from './core/queue'; | ||
import AppCron from './core/cron'; | ||
|
||
dotenv.config(); | ||
|
||
const app = express(); | ||
const PORT = 8000; | ||
let queueInstance: AppQueue; | ||
let cronInstance: AppCron; | ||
|
||
const setupDiscord = () => { | ||
const controller = new Controller(); | ||
const discord = new DiscordBot(controller); | ||
discord.start(); | ||
}; | ||
// const setupDiscord = () => { | ||
// const controller = new Controller(); | ||
// const discord = new DiscordBot(controller); | ||
// discord.start(); | ||
// }; | ||
|
||
app.use(express.json()); | ||
|
||
app.get('/', (req, res) => res.send('Express + TypeScript Server')); | ||
|
||
app.get('/test', async (req, res) => { | ||
// const ress = await parseFeed(); | ||
// res.json(ress); | ||
// aaa(); | ||
queueInstance.enqueue( | ||
() => | ||
new Promise((resolve) => { | ||
setTimeout(() => { | ||
console.log('slow job finished'); | ||
resolve('ok'); | ||
}, 3000); | ||
}), | ||
); | ||
res.json({}); | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`⚡️[server]: Server is running at http://localhost:${PORT}`); | ||
setupDiscord(); | ||
// setupDiscord(); | ||
queueInstance = new AppQueue(); | ||
queueInstance.start(); | ||
cronInstance = new AppCron(queueInstance); | ||
cronInstance.setup(); | ||
}); |