javascript - strip : throw errnoException(process. _errno, 'spawn' );

标签 javascript node.js callback stripe-payments

我有一段代码收集用户列表:here is the gist

当我运行代码时,我收到以下错误(我缺乏 JavaScript 技能是这里的主要问题)

  1. 我收集 Stripe 帐户
  2. 我将计数设置为 100
  3. 我收集了 100 个首批客户帐户
  4. 我循环 3,直到收集到所有帐户(如果计数 < size(最新客户列表)

child_process.js:927 throw errnoException(process._errno, 'spawn'); ^ Error: spawn EAGAIN

at errnoException (child_process.js:980:11)
at ChildProcess.spawn (child_process.js:927:11)
at exports.spawn (child_process.js:715:9)
at Object.exports.execFile (child_process.js:607:15)
at exports.exec (child_process.js:578:18)
at Object.Stripe.getClientUserAgent (/myProjectDir/node_modules/stripe/lib/stripe.js:125:5)
at Object.StripeResource._request (/myProjectDir/node_modules/stripe/lib/StripeResource.js:175:18)
at Object.list (/myProjectDir/node_modules/stripe/lib/StripeMethod.js:45:10)
at async.series.customers (/myProjectDir/app/lib/stripeKPIs.js:26:30)
at /myProjectDir/node_modules/async/lib/async.js:551:21

StripeDashboard.js

var url = require('url');
var nodedump = require('nodedump').init({ expand: true }).dump;
var stripeKPIs = require('../lib/stripeKPIs.js');
var async = require('async');
module.exports = function (app) {


    app.get('/stripe/dashboard', function (req, res) {


        var parts = url.parse(req.url, true);
        var queryString = parts.query;

        var payingCustomers = -1;
        var apiKey = req.session.user.credentials.access_token;

        console.log('/stripe/dashboard: queryString: ' + JSON.stringify(queryString));
        console.log('/stripe/dashboard: apiKey: ' + apiKey);

        async.waterfall([function (callback) {


            callback(null, stripeKPIs.payingCustomers(apiKey, new Date(2013, 1, 1), new Date(2013, 12, 1)));
        }],
            function (err, aSyncResults) {

                payingCustomers = aSyncResults[0];
                console.log('*********************');
                console.log('callback called! ' + JSON.stringify(payingCustomers));

            });


        res.render('stripe/stripeDashboard.html', {payingCustomers: payingCustomers, session: req.session});

    });
};

StripeKPIs.js

var async = require('async');

function StripeException(message) {
    this.message = message;
    this.name = "StripeException";
}


function payingCustomers(apiKey, startDate, endDate, callback) {
    // see https://stripe.com/docs/api/node#list_customers
    // return(how many customers)
    var kontinue = true;
    var result = []; //json containing all customers.data


    var stripe = require("stripe")(apiKey);
    var count = 100;
    var offset = 0;


    while (kontinue) {


        async.series([function (callback) {

            stripe.customers.list({count: count, offset: offset/*, gte: startDate, lte: endDate*/}, function (err, customers) {
                if (err) {
                    kontinue = false;
                    throw new StripeException('stripe.customers.list error: ' + err);
                }
                else {
                    console.log('collectCustomers: offset: ' + offset + ' - customers: ' + JSON.stringify(customers));
                    callback(null, customers);
                }
            });
        }],
            function (err, aSyncResults) {
                console.log('count(' + count + ') - offset(' + offset + ')');
                console.log('inside the callback');
                if (err) {
                    console.errror('async callback error: ' + err);
                    return next(err);
                }
                var customers = aSyncResults[0];

                result = result.concat(customers.data);
                if (customers.data.length < count) {
                    console.log('customers.data.length(' + customers.data.length + ') < count (' + count + ')');
                    kontinue = false;
                }


                offset = result.length;
                console.log('payingCustomers: offset: ' + offset + ' - result: ' + result.length);
                console.log('aSyncResults: offset: ' + offset + ' - result: ' + aSyncResults[0].data.length);
            });
    }
    return(result);
}

module.exports.payingCustomers = payingCustomers;

console.log 输出

Running "jshint:gruntfile" (jshint) task
>> 1 file lint free.

Running "jshint:lib" (jshint) task
>> 16 files lint free.

Running "jshint:test" (jshint) task
>> 1 file lint free.

Running "nodemon:dev" (nodemon) task
[nodemon] v1.0.13
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/**/*
[nodemon] starting `node --debug ./server.js dev`
debugger listening on port 5858
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
'development' === app.get('env')
listening to https://mymachine.local:3001
Connected to mongoose
/stripe/dashboard: queryString: {}
/stripe/dashboard: apiKey: sk_test_1234
startDate(Fri Mar 01 2013) - endDate(Thu Jan 01 2015)
*********************
callback called! undefined


collectCustomers: offset: 0 - customers: {"object":"list","count":14,"url":"/v1/customers","data":[{"object":"customer","created":1333799,"id":"cus_2LeD54sf3k","livemode":false,"description":"My test env","email":"your@email.com","delinquent":false,"metadata":{},"subscription":{"id":"sub_01","plan":{"interval":"year","name":"Standard plan billed yearly","created":13074184,"amount":2000,"currency":"eur","id":"StdYear","object":"plan","livemode":false,"interval_count":1,"trial_period_days":null,"metadata":{}}....]}

count(100) - offset(0)

inside the callback

customers.data.length(14) < count (100)

payingCustomers: offset: 14 - result: 14

aSyncResults: offset: 14 - result: 14

最佳答案

我遇到了 @Abdelkrim irl,我们通过用递归函数替换 while(kontinue) 循环解决了他的问题。

比照。此处解释模式:http://www.richardrodger.com/2011/04/21/node-js-how-to-write-a-for-loop-with-callbacks/#.UufBCD0o9hE

关于javascript - strip : throw errnoException(process. _errno, 'spawn' );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21394168/

相关文章:

Javascript 函数回调依赖于超时

javascript - 从 iframe 中的元素获取数据

javascript - 使用 jQuery 将 XML 解析为表

javascript - 合并 Node.js 流

javascript - 无法返回值以响应 mongoose/mongodb 和 nodejs

android - 在 webview 中加载本地 javascript 文件的问题

Javascript 应用 - React 中 Mixins 的示例

javascript - angularJS $scope.ons.navigator.pushPage 不起作用

node.js - Dynamoose .update 不像 AWS javascript SDK 那样工作。我需要使用SDK来更新项目吗?

Javascript 运行 "out of order"