-
Notifications
You must be signed in to change notification settings - Fork 12
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
20 changed files
with
373 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
APP_ENV=production | ||
APP_PORT=8080 | ||
HEADLESS=true | ||
HTTP=true | ||
WEBSOCKET=false | ||
WITH_DATABASE=false | ||
DB_URI=mongodb://localhost/shallty_crawler |
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,6 +1,6 @@ | ||
/node_modules | ||
/logs | ||
/Server/public/images/screenshot/* | ||
config.json | ||
deploy-key | ||
ecosystem.config.js | ||
ecosystem.config.js | ||
.env |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ language: node_js | |
node_js: | ||
- node | ||
before_install: | ||
- mv config.example.json config.json | ||
- mv .env.example .env |
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,25 @@ | ||
const mongoose = require('mongoose') | ||
const Schema = mongoose.Schema | ||
|
||
const ShortlinkSchema = new Schema({ | ||
original: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
}, | ||
parsed: { | ||
type: String, | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: new Date() | ||
}, | ||
updatedAt: { | ||
type: Date, | ||
default: new Date() | ||
}, | ||
}) | ||
|
||
const Shortlink = mongoose.model('Shortlink', ShortlinkSchema) | ||
|
||
module.exports = Shortlink |
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,51 @@ | ||
const crypto = require('crypto') | ||
const { sleep } = require('../utils/utils') | ||
|
||
class Queue { | ||
constructor() { | ||
this.runningJobs = 0 | ||
} | ||
|
||
register(task) { | ||
return { | ||
id: crypto.randomBytes(8).toString('hex'), | ||
task: task, | ||
result: undefined, | ||
} | ||
} | ||
|
||
async run(job) { | ||
if (this.runningJobs > 4) { | ||
return { | ||
finished: false | ||
} | ||
} | ||
|
||
this.runningJobs = this.runningJobs + 1 | ||
|
||
const result = await job.task() | ||
|
||
this.runningJobs = this.runningJobs - 1 | ||
|
||
return { | ||
finished: true, | ||
result: result, | ||
} | ||
} | ||
|
||
async dispatch(job) { | ||
let run = { | ||
finished: false | ||
} | ||
|
||
while (!run.finished) { | ||
await sleep(2000) | ||
|
||
run = await this.run(job) | ||
} | ||
|
||
return run.result | ||
} | ||
} | ||
|
||
module.exports = new Queue |
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
Oops, something went wrong.