Skip to content

Instantly share code, notes, and snippets.

@alexcusack
Last active August 24, 2017 23:24
Show Gist options
  • Select an option

  • Save alexcusack/8bb684beb46af55ea45c2a44db48cb10 to your computer and use it in GitHub Desktop.

Select an option

Save alexcusack/8bb684beb46af55ea45c2a44db48cb10 to your computer and use it in GitHub Desktop.

Revisions

  1. alexcusack revised this gist Aug 24, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion payment-supervisor.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ import {range} from 'lodash';
    import * as P from 'bluebird';

    function enqueueParallelExecutions(buckets, queueService) {
    const enqueuedRequests = _.range(buckets).map((bucket) => {
    const enqueuedRequests = range(buckets).map((bucket) => {
    return queueService.enqueue('payment-processor', {bucket, buckets});
    });
    return P.all(enqueuedRequests);
  2. alexcusack revised this gist Aug 24, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions payment-supervisor.js
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,9 @@
    * @returns {Promise(<Array>)} Array of queue receipts
    */

    import {range} from 'lodash';
    import * as P from 'bluebird';

    function enqueueParallelExecutions(buckets, queueService) {
    const enqueuedRequests = _.range(buckets).map((bucket) => {
    return queueService.enqueue('payment-processor', {bucket, buckets});
  3. alexcusack revised this gist Aug 24, 2017. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions payment-supervisor.js
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,7 @@

    function enqueueParallelExecutions(buckets, queueService) {
    const enqueuedRequests = _.range(buckets).map((bucket) => {
    const payload = {buckets: buckets, bucket: bucket};
    console.log('enqueuing payload', payload, 'debug');
    return queueService.enqueue('payment-processor', payload)
    .catch(function (e) {
    // catch and log errors for each enqueued job individually
    // since P.all() will reject with a single error if any reject
    console.log('enqueuing failed', payload, 'error');
    });
    return queueService.enqueue('payment-processor', {bucket, buckets});
    });
    return P.all(enqueuedRequests);
    }
  4. alexcusack created this gist Aug 24, 2017.
    21 changes: 21 additions & 0 deletions payment-supervisor.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    /**
    * A not-exactly-how-we-did-this-but-something-similar-implementation
    * Enqueues a payment-processor execution for 0 - (buckets - 1)
    * @param {Int} buckets: the number of Payment Processor executions to enqueue
    * @param {Object} queue: Amazon SQS queue
    * @returns {Promise(<Array>)} Array of queue receipts
    */

    function enqueueParallelExecutions(buckets, queueService) {
    const enqueuedRequests = _.range(buckets).map((bucket) => {
    const payload = {buckets: buckets, bucket: bucket};
    console.log('enqueuing payload', payload, 'debug');
    return queueService.enqueue('payment-processor', payload)
    .catch(function (e) {
    // catch and log errors for each enqueued job individually
    // since P.all() will reject with a single error if any reject
    console.log('enqueuing failed', payload, 'error');
    });
    });
    return P.all(enqueuedRequests);
    }