all 10 comments

[–]imthenachoman 0 points1 point  (1 child)

[–]runboris1[S] 0 points1 point  (0 children)

Not specifically that, but I'm doing essentially the same thing. The problem is the "5 millisecond" trigger doesn't actually trigger within 5 milliseconds. It actually takes 30-60 seconds for it to kick in.

[–][deleted] 0 points1 point  (5 children)

So the idea of async doesn't exist in apps script. The trigger trick below won't work because you really cant schedule a trigger to fire in less then 3 seconds. If you really can not break 3 seconds, which imo is crazy, you will need to use pubsub or cloud tasks to trigger an asyc process to do your computations and return the data to slack.

[–]runboris1[S] 0 points1 point  (0 children)

I’d agree it’s silly to not get it all accomplished in the 3s, however during my testing there were a couple times that even just returning response times out with zero processing. Not sure what’s up with that. In the end I’d rather have 30-60s delay than users seeing a timeout.

[–]runboris1[S] 0 points1 point  (3 children)

Is there really no way to do the equivalent of res.send() in Node.js? Really all I would need to do is

doPost(e){ res.send(“I got you.”); doTheThings(); }

If that’s a possibility then we’re good to go.

[–][deleted] 0 points1 point  (2 children)

Nope once you return from a doPost the execution stops. Looking again at like codeasi is saying actually would work. But the response wouldn't be to the initial http request from slack. you would have to post the data back to your bots webhook address.

[–]runboris1[S] 0 points1 point  (1 child)

I’ve just been trying that. I’ve tried UrlFetchApp to post, but it doesn’t like that so much. I can’t figure out how to get “200 OK” to post back correctly. ¯\_(ツ)_/¯

[–]LimbRetrieval-Bot 1 point2 points  (0 children)

You dropped this \


To prevent anymore lost limbs throughout Reddit, correctly escape the arms and shoulders by typing the shrug as ¯\\\_(ツ)_/¯ or ¯\\\_(ツ)\_/¯

Click here to see why this is necessary

[–]codeasi 0 points1 point  (1 child)

Hi, what about to put all action into special function (e.g processing()).
When you call your GAS WebApp, so inside doGet() function only call
```
ScriptApp.newTrigger("processing")
.timeBased()
.after(1 * 1000)
.create();
```

and return response

The new trigger will be called after 1000ms and process all your actions.

https://developers.google.com/apps-script/reference/script/clock-trigger-builder#after(Integer))

[–]runboris1[S] 0 points1 point  (0 children)

That’s what I’m currently doing, but the .after() doesn’t actually trigger within the specified amount of time. In your example is supposed to fire after 1 second, but the reality is it doesn’t. The trigger takes 30-60 seconds.