aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/requests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-02 17:25:05 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-02 17:25:05 +0200
commite3647ae226d19ed1401d4c617d35a68de1c4657a (patch)
tree725380f4123702dfc19d208d8cf90be10a7c2b32 /server/models/requests.js
parenta6e7400f6470a657059225807cc2853144088dbc (diff)
downloadPeerTube-e3647ae226d19ed1401d4c617d35a68de1c4657a.tar.gz
PeerTube-e3647ae226d19ed1401d4c617d35a68de1c4657a.tar.zst
PeerTube-e3647ae226d19ed1401d4c617d35a68de1c4657a.zip
Rename pool requests --> requests scheduler
Diffstat (limited to 'server/models/requests.js')
-rw-r--r--server/models/requests.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/server/models/requests.js b/server/models/requests.js
new file mode 100644
index 000000000..2152ae0e9
--- /dev/null
+++ b/server/models/requests.js
@@ -0,0 +1,55 @@
1'use strict'
2
3const mongoose = require('mongoose')
4
5const logger = require('../helpers/logger')
6
7// ---------------------------------------------------------------------------
8
9const requestsSchema = mongoose.Schema({
10 type: String,
11 id: String, // Special id to find duplicates (video created we want to remove...)
12 request: mongoose.Schema.Types.Mixed
13})
14const RequestsDB = mongoose.model('requests', requestsSchema)
15
16// ---------------------------------------------------------------------------
17
18const Requests = {
19 create: create,
20 findById: findById,
21 list: list,
22 removeRequestById: removeRequestById,
23 removeRequests: removeRequests
24}
25
26function create (id, type, request, callback) {
27 RequestsDB.create({ id: id, type: type, request: request }, callback)
28}
29
30function findById (id, callback) {
31 RequestsDB.findOne({ id: id }, callback)
32}
33
34function list (callback) {
35 RequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback)
36}
37
38function removeRequestById (id, callback) {
39 RequestsDB.remove({ id: id }, callback)
40}
41
42function removeRequests (ids) {
43 RequestsDB.remove({ _id: { $in: ids } }, function (err) {
44 if (err) {
45 logger.error('Cannot remove requests from the requests database.', { error: err })
46 return // Abort
47 }
48
49 logger.info('Pool requests flushed.')
50 })
51}
52
53// ---------------------------------------------------------------------------
54
55module.exports = Requests