How to check if a function is currently running?

1,178 views
Skip to first unread message

jmm0979

unread,
Dec 2, 2021, 8:04:49 PM12/2/21
to google-apps-sc...@googlegroups.com
Hi,
I would like to check if there is a way to validate if a certain function is currently running.

--> check status of "myfunction1"
if myfunction1 = "running", do not execute myfunction2,
if myfunction1 status = "completed" or "cancelled" or "terminated" or "timedout", run myfunction2. 

I'd like to automate this process. I have the script for "myfunction2" but I don't know how to check the status of a function using GAS. 

Any input is appreciated! TIA!

Tanaike

unread,
Dec 2, 2021, 8:19:56 PM12/2/21
to Google Apps Script Community
In your situation, in order to directly achieve your goal, how about using Google Apps Script API? When "Method: processes.list" of Apps Script API is used, when the function of `myFunction` is running now, you can see it as "processStatus": "RUNNING". You can test this method at Try this API
If this was not the direction you expect, I apologize.

Jonathan Butler

unread,
Dec 2, 2021, 9:24:17 PM12/2/21
to google-apps-sc...@googlegroups.com
Alternatively, if they are two different functions in the same script. You can just cache a value when it is running and delete the value when it is not. If they are two different scripts you can do the same thing with a library in between. 

On Thu, Dec 2, 2021 at 7:19 PM Tanaike <kanshi...@gmail.com> wrote:
In your situation, in order to directly achieve your goal, how about using Google Apps Script API? When "Method: processes.list" of Apps Script API is used, when the function of `myFunction` is running now, you can see it as "processStatus": "RUNNING". You can test this method at Try this API
If this was not the direction you expect, I apologize.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/48c3351c-4917-48e0-8fd2-724a34a36bf7n%40googlegroups.com.

JMR...

unread,
Dec 2, 2021, 11:14:34 PM12/2/21
to Google Apps Script Community
I am trying this - not sure if it is correct though.

function checkFunction() {
var functionIsRunning;
functionIsRunning = CacheService.getDocumentCache().put('runFiles', true, 600);
if (functionIsRunning) {
return;
} else {
runFiles();
}
}
Reply all
Reply to author
Forward
0 new messages