How to use better-queue - 7 common examples

To help you get started, we’ve selected a few better-queue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sozialhelden / accessibility-cloud / server / image-scaling.js View on Github external
// 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');
github dreamnettech / dreamtime / src / modules / nudify / photo.js View on Github external
_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!`)
github dreamnettech / dreamtime / src / modules / models / photo.js View on Github external
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()
github dreamnettech / dreamtime / src / modules / nudify / nudify.js View on Github external
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'
    })
  }
github gajus / headless-crawler / src / factories / createHeadlessCrawler.js View on Github external
// 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: []
        }
      ]
    });
github igdb / node-apicalypse / src / index.js View on Github external
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()

better-queue

Better Queue for NodeJS

MIT
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis

Popular better-queue functions