summaryrefslogtreecommitdiff
path: root/src/queue/index.ts
blob: 691223de2d719601718fd8e6a775390335fb7113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createQueue } from 'kue';

import config from '../config';
import db from './processors/db';
import http from './processors/http';

const queue = createQueue({
	redis: {
		port: config.redis.port,
		host: config.redis.host,
		auth: config.redis.pass
	}
});

export function createHttp(data) {
	return queue
		.create('http', data)
		.attempts(16)
		.backoff({ delay: 16384, type: 'exponential' });
}

export function createDb(data) {
	return queue.create('db', data);
}

export function deliver(user, content, to) {
	return createHttp({
		type: 'deliver',
		user,
		content,
		to
	});
}

export default function() {
	queue.process('db', db);

	/*
		256 is the default concurrency limit of Mozilla Firefox and Google
		Chromium.
		a8af215e691f3a2205a3758d2d96e9d328e100ff - chromium/src.git - Git at Google
		https://chromium.googlesource.com/chromium/src.git/+/a8af215e691f3a2205a3758d2d96e9d328e100ff
		Network.http.max-connections - MozillaZine Knowledge Base
		http://kb.mozillazine.org/Network.http.max-connections
	*/
	queue.process('http', 256, http);
}