do-web / curl-request

cURL Request is a cURL wrapper, support all options and infos from cURL. Use promises, https, http, proxies and more!
MIT License
25 stars 18 forks source link

Error: Handle already running! at Error (native) at Curl.perform #6

Open wahyuandi840 opened 5 years ago

wahyuandi840 commented 5 years ago

i have error in google cloud function. Error: Handle already running! at Error (native) at Curl.perform (/user_code/node_modules/curl-request/node_modules/node-libcurl/lib/Curl.js:1051:11) at e (/user_code/node_modules/curl-request/index.js:169:27) at _submit (/user_code/node_modules/curl-request/index.js:141:16) at post (/user_code/node_modules/curl-request/index.js:93:21) at /user_code/index.js:112:9 at f (/user_code/node_modules/@google-cloud/storage/node_modules/once/once.js:25:25) at ConcatStream. (/user_code/node_modules/@google-cloud/storage/node_modules/concat-stream/index.js:37:43) at emitNone (events.js:91:20) at ConcatStream.emit (events.js:185:7)

my code is /**

exports.getEmail = (event, callback) => { const file = event.data; const eventAge = Date.now() - Date.parse(event.timestamp); const eventMaxAge = 10000;

// Ignore events that are too old if (eventAge > eventMaxAge) { console.log(Dropping event ${event} with age ${eventAge} ms.); callback(); return; }

//console.log(Event: ${event.eventId}); //console.log(Event Type: ${event.eventType}); //console.log(Bucket: ${file.bucket}); // console.log(File: ${file.name}); //console.log(Metageneration: ${file.metageneration}); //console.log(Created: ${file.timeCreated}); //console.log(Updated: ${file.updated});

if (file.name.match('registerfolder/')) { storage. bucket(file.bucket). file(file.name). download(function(err, contents) { var obj = JSON.parse(contents.toString());

  curl
   .setBody({
    'from' : obj.from,
    'fromName': obj.sender,
    'apikey': process.env.API_KEY,
    'subject': obj.subject,
    'to': obj.to,
    'bodyHtml': obj.text,
    'isTransactional': true
   })
   .post(process.env.API_URL + 'email/send')
   .then(({
    statusCode,
    body,
    headers
   }) => {
    console.log(statusCode, body, headers)
   })
   .catch((e) => {
    console.log(e);
   });

 });

} callback(); };

franciskim commented 5 years ago

Getting the same issue. I think you can only run 1 task at once.

franciskim commented 5 years ago

Just do a new (require( 'curl-request' ))() each time to avoid this

soulreaper02 commented 5 years ago

const CurlRequest = require('curl-request'); sites.forEach(site => { console.log(site); const curl = new CurlRequest; curl.get('https://' + site).then(...); });