Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use queue job system to process voting from 3rd pt website
worse performance than proxy forward but i have no choice for now
- Loading branch information
Showing
12 changed files
with
100 additions
and
100 deletions.
There are no files selected for viewing
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
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
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,26 @@ | ||
const mongoose = require('mongoose') | ||
|
||
const config = require('../config.json') | ||
|
||
class DatabaseFactory { | ||
/** | ||
* @param {import('../chitanda')} client | ||
*/ | ||
constructor(client) { | ||
this.client = client; | ||
} | ||
|
||
connect() { | ||
return mongoose.connect(config.database, { useNewUrlParser: true }) | ||
.then(() => { | ||
this.client.errorLogger.info('Connected to mongodb', true); | ||
return true; | ||
}) | ||
.catch(err => { | ||
this.client.errorLogger.error(err); | ||
process.exit(1); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = DatabaseFactory; |
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
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,17 @@ | ||
const VoteScheduler = require('../schedulers/voteScheduler') | ||
|
||
class SchedulerManager { | ||
/** | ||
* @param {import('../chitanda')} client | ||
*/ | ||
constructor(client) { | ||
this.client = client; | ||
this.voteScheduler = new VoteScheduler(client); | ||
} | ||
|
||
startAll() { | ||
this.voteScheduler.start(); | ||
} | ||
} | ||
|
||
module.exports = SchedulerManager; |
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
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,3 +1,9 @@ | ||
const prodEnv = "PRODUCTION"; | ||
|
||
exports.randomTrue = () => { | ||
return Math.random() > 0.5; | ||
} | ||
|
||
exports.isProduction = () => { | ||
return process.env.CHITANDA_ENV && process.env.CHITANDA_ENV.toUpperCase() == prodEnv; | ||
} |
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,20 +1,47 @@ | ||
/**======= Copy right | ||
Sait 2018 | ||
Sait 2018 | ||
=====================*/ | ||
const express = require('express') | ||
const proxy = require('express-http-proxy') | ||
const bodyParser = require('body-parser') | ||
const agenda = require('agenda') | ||
|
||
const app = express() | ||
const jobQueue = new agenda() | ||
|
||
const config = require('./config.json') | ||
const VoteScheduler = require('./schedulers/voteScheduler') | ||
const path = '/dblwebhook' | ||
const port = process.env.PORT || 5555 | ||
|
||
app.use(path, proxy('localhost:5000')); | ||
jobQueue.database(config.database, VoteScheduler.voteCollection, { useNewUrlParser: true }); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
app.get('/', (req, res) => { | ||
res.send('How did you find this owo'); | ||
}) | ||
|
||
app.use(path, async (req, res) => { | ||
var auth = config.discordBotOrg.webhookAuth; | ||
if (auth && auth !== req.headers.authorization) { | ||
res.status(401).end(); | ||
return; | ||
} | ||
|
||
await jobQueue.start(); | ||
jobQueue.now(VoteScheduler.voteJob, { | ||
header: { | ||
host: req.headers.host, | ||
origin: req.headers.origin, | ||
// authorization: req.headers.authorization | ||
}, | ||
body: req.body | ||
}).then(() => { | ||
res.status(200).end(); | ||
}) | ||
}) | ||
|
||
app.listen(port, () => { | ||
console.log(`[Info] Webhook running at ${path} on port ${port}`); | ||
}) |