Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// setup pipes
originalImageStream
.pipe(resizeTask)
.pipe(task.outputStream);
return {
cancel: () => {
originalImageStream.destroy();
resizeTask = null;
},
};
};
sharp.concurrency(3);
const imageProcessingQueue = new Queue(imageProcessingHandler, { concurrent: 3 });
function respondWithError(res, code, reason) {
res.writeHead(code, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: { reason } }));
}
WebApp.connectHandlers.use('/images/scale/', (req: http.IncomingMessage, res: http.ServerResponse) => {
setAccessControlHeaders(res, ['GET', 'HEAD', 'OPTIONS']);
if (req.method === 'OPTIONS') {
res.end();
return;
}
if (req.method !== 'GET' && req.method !== 'HEAD') {
respondWithError(res, 405, 'This endpoint only accepts GET and OPTIONS requests');
_setupQueue() {
let maxTimeout = settings.processing.device === 'GPU' ? (3 * 60 * 1000) : (10 * 60 * 1000)
if (this.file.mimetype === 'image/gif') {
maxTimeout += (30 * 60 * 1000)
}
this.queue = new Queue(this._run, {
maxTimeout,
// maxRetries: 2,
// retryDelay: 1000,
afterProcessDelay: 500,
batchSize: 1,
concurrent: 1,
store: new MemoryStore(),
})
this.queue.on('drain', () => {
this._logger.debug('All runs finished.')
this._onFinish()
})
this.queue.on('task_started', (runId, run) => {
this._logger.debug(`Run #${runId} started!`)
this.crop = {
startX: 0,
startY: 0,
endX: 0,
endY: 0,
}
// preferences
this.preferences = _.clone($settings.preferences)
// reset data
this.reset()
// jobs queue
this.queue = new Queue(
(job, cb) => {
job
.start()
.then(() => {
// eslint-disable-next-line promise/no-callback-in-promise
cb(null)
return true
})
.catch((err) => {
// eslint-disable-next-line promise/no-callback-in-promise
cb(err)
})
return {
cancel: () => {
job.cancel()
static setup() {
this.queue = new Queue(this._run, {
maxTimeout: (60 * 60 * 1000),
afterProcessDelay: 500,
batchSize: 1,
concurrent: 1,
store: new MemoryStore(),
})
this.queue.on('task_queued', (photoId, photo) => {
// eslint-disable-next-line no-param-reassign
photo.status = 'waiting'
})
}
// eslint-disable-next-line no-use-before-define
localQueue.push({
path: currentPath.concat([
queuedLink
]),
url: queuedLink.linkUrl
});
} else {
log.trace('link filtered out');
}
}
callback(null, resource);
};
const localQueue = new Queue(runQueueTask, {
concurrent: headlessCrawlerUserConfiguration.concurrency
});
const queue = (queueConfiguration: QueueConfigurationType) => {
localQueue.push({
path: [
{
lastAttemptedAt: null,
linkDepth: 0,
linkUrl: queueConfiguration.url,
originUrl: null,
path: []
}
]
});
return new Promise(resolve => {
let allData = [];
const { limit, offset } = this.cleanLimitOffset();
const q = new Queue(
async (page, cb) => {
this.cleanLimitOffset();
this.limit(limit);
this.offset(offset + page * limit);
const response = await this.request(url);
allData = allData.concat(response.data);
if (response.data.length >= limit) {
q.push(page + 1);
}
setTimeout(() => {
cb(null);
}, delay || 0);
},
{
concurrent: concurrency || 1,
store: new MemoryStore()