Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wahyuandi840 opened this issue Nov 8, 2018 · 3 comments
Open

Comments

@wahyuandi840
Copy link

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
/**

  • Triggered from a change to a Cloud Storage bucket.
  • @param {!Object} event Event payload and metadata.
  • @param {!Function} callback Callback function to signal completion.
    */
    const storage = require("@google-cloud/storage")();
    const curl = new(require('curl-request'))();

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
Copy link

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

@franciskim
Copy link

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

@soulreaper02
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants