Google Cloud Async Processing return 200












0















I am using a google cloud function as a webhook to receive a payload from a 3rd party service. Typically when such services make requests to webhooks they expect a HTTP 200 as acknowledgement. However with a cloud function setup as below (and as recommended by google) the requesting service is returned a 408 when ongoing processing is happening.



In this situation the 3rd party service (in this case its cloudmailin but the same applies for any webhook I have attempted to integrate with) will retry the request even though it has been handled successfully.



My question is: how can I get the cloud function to return a 200 and still continue the async processing?



//This will return a 408 even though the request is processed successfully
exports.emailIngest = functions.https.onRequest((request, response) =>
{
//return the promise from the firestore admin SDK as per google docs
return admin.auth().getUserByEmail(request.body.envelope.from).then((user) => {
console.log('Successfully fetched user data:', user.toJSON());
}).catch(function (error) {
console.log('Error fetching user data:', error);
});
});









share|improve this question



























    0















    I am using a google cloud function as a webhook to receive a payload from a 3rd party service. Typically when such services make requests to webhooks they expect a HTTP 200 as acknowledgement. However with a cloud function setup as below (and as recommended by google) the requesting service is returned a 408 when ongoing processing is happening.



    In this situation the 3rd party service (in this case its cloudmailin but the same applies for any webhook I have attempted to integrate with) will retry the request even though it has been handled successfully.



    My question is: how can I get the cloud function to return a 200 and still continue the async processing?



    //This will return a 408 even though the request is processed successfully
    exports.emailIngest = functions.https.onRequest((request, response) =>
    {
    //return the promise from the firestore admin SDK as per google docs
    return admin.auth().getUserByEmail(request.body.envelope.from).then((user) => {
    console.log('Successfully fetched user data:', user.toJSON());
    }).catch(function (error) {
    console.log('Error fetching user data:', error);
    });
    });









    share|improve this question

























      0












      0








      0








      I am using a google cloud function as a webhook to receive a payload from a 3rd party service. Typically when such services make requests to webhooks they expect a HTTP 200 as acknowledgement. However with a cloud function setup as below (and as recommended by google) the requesting service is returned a 408 when ongoing processing is happening.



      In this situation the 3rd party service (in this case its cloudmailin but the same applies for any webhook I have attempted to integrate with) will retry the request even though it has been handled successfully.



      My question is: how can I get the cloud function to return a 200 and still continue the async processing?



      //This will return a 408 even though the request is processed successfully
      exports.emailIngest = functions.https.onRequest((request, response) =>
      {
      //return the promise from the firestore admin SDK as per google docs
      return admin.auth().getUserByEmail(request.body.envelope.from).then((user) => {
      console.log('Successfully fetched user data:', user.toJSON());
      }).catch(function (error) {
      console.log('Error fetching user data:', error);
      });
      });









      share|improve this question














      I am using a google cloud function as a webhook to receive a payload from a 3rd party service. Typically when such services make requests to webhooks they expect a HTTP 200 as acknowledgement. However with a cloud function setup as below (and as recommended by google) the requesting service is returned a 408 when ongoing processing is happening.



      In this situation the 3rd party service (in this case its cloudmailin but the same applies for any webhook I have attempted to integrate with) will retry the request even though it has been handled successfully.



      My question is: how can I get the cloud function to return a 200 and still continue the async processing?



      //This will return a 408 even though the request is processed successfully
      exports.emailIngest = functions.https.onRequest((request, response) =>
      {
      //return the promise from the firestore admin SDK as per google docs
      return admin.auth().getUserByEmail(request.body.envelope.from).then((user) => {
      console.log('Successfully fetched user data:', user.toJSON());
      }).catch(function (error) {
      console.log('Error fetching user data:', error);
      });
      });






      node.js google-cloud-functions cloudmailin






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 15:41









      Mike MillerMike Miller

      2,04611221




      2,04611221
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Since HTTP triggers are effectively terminated and cleaned up after they send a response, you won't be able to continue async work in the function after the response is sent. What you'll have to do is have the HTTP function delegate work to some other background function that continues outside of the scope of the HTTP request.



          One way to do that is to use a pubsub trigger. The HTTP trigger can broadcast a pubsub message, which then causes the pubsub trigger to execute. Pubsub requires billing to be enabled for the project.



          Another way is to write to some location in Realtime Database or Firestore and have another function trigger in response to that write. The other function will probably want to delete the written data before it terminates.






          share|improve this answer
























          • Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

            – Mike Miller
            Nov 15 '18 at 17:32











          • I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

            – Doug Stevenson
            Nov 15 '18 at 17:35













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322967%2fgoogle-cloud-async-processing-return-200%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Since HTTP triggers are effectively terminated and cleaned up after they send a response, you won't be able to continue async work in the function after the response is sent. What you'll have to do is have the HTTP function delegate work to some other background function that continues outside of the scope of the HTTP request.



          One way to do that is to use a pubsub trigger. The HTTP trigger can broadcast a pubsub message, which then causes the pubsub trigger to execute. Pubsub requires billing to be enabled for the project.



          Another way is to write to some location in Realtime Database or Firestore and have another function trigger in response to that write. The other function will probably want to delete the written data before it terminates.






          share|improve this answer
























          • Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

            – Mike Miller
            Nov 15 '18 at 17:32











          • I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

            – Doug Stevenson
            Nov 15 '18 at 17:35


















          0














          Since HTTP triggers are effectively terminated and cleaned up after they send a response, you won't be able to continue async work in the function after the response is sent. What you'll have to do is have the HTTP function delegate work to some other background function that continues outside of the scope of the HTTP request.



          One way to do that is to use a pubsub trigger. The HTTP trigger can broadcast a pubsub message, which then causes the pubsub trigger to execute. Pubsub requires billing to be enabled for the project.



          Another way is to write to some location in Realtime Database or Firestore and have another function trigger in response to that write. The other function will probably want to delete the written data before it terminates.






          share|improve this answer
























          • Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

            – Mike Miller
            Nov 15 '18 at 17:32











          • I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

            – Doug Stevenson
            Nov 15 '18 at 17:35
















          0












          0








          0







          Since HTTP triggers are effectively terminated and cleaned up after they send a response, you won't be able to continue async work in the function after the response is sent. What you'll have to do is have the HTTP function delegate work to some other background function that continues outside of the scope of the HTTP request.



          One way to do that is to use a pubsub trigger. The HTTP trigger can broadcast a pubsub message, which then causes the pubsub trigger to execute. Pubsub requires billing to be enabled for the project.



          Another way is to write to some location in Realtime Database or Firestore and have another function trigger in response to that write. The other function will probably want to delete the written data before it terminates.






          share|improve this answer













          Since HTTP triggers are effectively terminated and cleaned up after they send a response, you won't be able to continue async work in the function after the response is sent. What you'll have to do is have the HTTP function delegate work to some other background function that continues outside of the scope of the HTTP request.



          One way to do that is to use a pubsub trigger. The HTTP trigger can broadcast a pubsub message, which then causes the pubsub trigger to execute. Pubsub requires billing to be enabled for the project.



          Another way is to write to some location in Realtime Database or Firestore and have another function trigger in response to that write. The other function will probably want to delete the written data before it terminates.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 17:20









          Doug StevensonDoug Stevenson

          79.8k996114




          79.8k996114













          • Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

            – Mike Miller
            Nov 15 '18 at 17:32











          • I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

            – Doug Stevenson
            Nov 15 '18 at 17:35





















          • Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

            – Mike Miller
            Nov 15 '18 at 17:32











          • I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

            – Doug Stevenson
            Nov 15 '18 at 17:35



















          Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

          – Mike Miller
          Nov 15 '18 at 17:32





          Thanks for the input. I had thought of the same but in all cases I am going to have to call something async. If that is the case then I am in the same situation I think

          – Mike Miller
          Nov 15 '18 at 17:32













          I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

          – Doug Stevenson
          Nov 15 '18 at 17:35







          I don't understand what you just wrote here. In both of the cases I just offered, you can either send the message or do the database write without having to wait for the other function to complete. The HTTP response is sent from the first function, and the other function continues without the user having to wait.

          – Doug Stevenson
          Nov 15 '18 at 17:35






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322967%2fgoogle-cloud-async-processing-return-200%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python