2 functions on one file keep running, why?

609 views
Skip to first unread message

J.A

unread,
Apr 24, 2021, 2:33:10 PM4/24/21
to Google Apps Script Community
Hi, I have 2 functions and I want one to run after another with some delay in between runs, 

when I run each code separately it works fine, the code is short and it takes a second to run. on the EXECUTION page, it shows "completed". after each run /by the trigger.

there is a trigger based on form submit.

I put the functions in one file, when the form submitted,  both functions run OK, one after another but on the EXECUTION page, it shows "running" under status.

 even if do one or more forms submit, the new task "running" appears, and the old one still there, it/they won't disappear unless I refresh the EXECUTION page. 

I have changed my actual functions and tested with a simple math function, to see if my functions caused the problem, and used the following codes, the result was the same, the functions work but the "running" status won't disappear.

Why the codes or one code keep running?
Does anyone know how to fix this, please?

if the method below is not right, please help me with how to run 2 or more functions in one file one after another with some delay in between, when the form submits.

I appreciate your help.


    function AutoMa() {
     a();
     Utilities.sleep(3000) 
     b();
      };

       function a() {
        var a = parseInt('4');
         var b = parseInt('3');
          Logger.log(a + b);   
           }


         function b() {
         var a = parseInt('44');
         var b = parseInt('33');
          Logger.log(a + b);  
           }


Alan Wells

unread,
Apr 24, 2021, 4:39:31 PM4/24/21
to Google Apps Script Community
The Executions log has always had an issue of sometimes not showing the correct status.
I have seen it often fail to show the status as "Completed" even when the status is "Completed."
That is an issue with the Executions log, it's not a problem with the code.
It can happen that some code could have an endless loop, or an error that causes a failure.
If you refresh the browser tab, and the status changes from running to completed,
then I'd guess that the issue is with the Executions log, not your code.
The Executions log often does not correctly update the status.
Is your On Form Submit function ever being triggered to run in rapid succession?
Like, multiple users all submitting the Form at the same time?

J.A

unread,
Apr 24, 2021, 6:19:44 PM4/24/21
to Google Apps Script Community
thank you for your reply, I don't know if this is an execution log problem, I was hoping to find a solution to prevent this to happen, this happens when two functions are in one file, I did use it myself just for testing my code out, I am the only one who runs it, either manually clicking the run button or with form submit, so there is not much of activity on the code,

Alan Wells

unread,
Apr 24, 2021, 6:28:28 PM4/24/21
to Google Apps Script Community
Are your function names literally "a" and "b" or is that just pseudo code to show an example?
If those are your function names then I'd create longer names.
I don't see anything in your code that would cause one of the functions to keep running.

J.A

unread,
Apr 25, 2021, 4:00:36 AM4/25/21
to Google Apps Script Community
Thanks for your reply, as I mentioned in my first post, I was trying with my code, when this "running" issue occurred, I tried to test using two simple functions to see what happened, so I use a simple match function that takes a fraction of sec. to run, just to see if this running happens again or not, which it did, I took off the "console.log" as well, it does not make any difference, I still get the "running" in the status. I have changed the function names to a longer name (myFunctionOne) and (myFunctionTwo), but it does have the same issue.
I know that there is nothing wrong with the code.

I can not come up with anything that just thinking it is the Apps script issues with 2 functions together. 

Alan Wells

unread,
Apr 25, 2021, 9:23:10 AM4/25/21
to Google Apps Script Community
Even though it states "running" in the status column of the Executions log, it may not be running.
Refresh the browser tab, and then look at the run times.
If the run time for the one that stated running is not a lot longer, then it wasn't really running.
If the one that states "running" does have a substantially longer run time, then I'd think something strange was happening.

Alan Wells

unread,
Apr 25, 2021, 9:42:02 AM4/25/21
to google-apps-sc...@googlegroups.com
The same function shouldn't be running twice unless you have more than one On Form Submit trigger installed.
So inspect your triggers and look for more than one trigger for the same function.
The other situation that can happen is if the Form is shared with a collaborator who has edit access,
and they also installed a trigger for the same Form.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/hcSOyjFc3mI/unsubscribe.
To unsubscribe from this group and all its topics, 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/dcbd4c62-b1d5-4bf5-b273-db8fb2403972n%40googlegroups.com.

J.A

unread,
Apr 25, 2021, 10:13:09 AM4/25/21
to Google Apps Script Community
thank you for your reply, no other people are using the form spreadsheet, I am using it to test it, I have already made changes to form and trigger to not be double run, but I figure out the problem, it is the  "Utilities.sleep"  , I run one of the test code:

function myfunctionOne() {

  var a = parseInt('4');
  var b = parseInt('3');
  Utilities.sleep(60000);

   console.log(a + b);  
     }

and run it manually, and watched the status on the Execution page, after 1 min sleep time, the result of log shows up, but the running does not disappear,
what is that? I am not sure how to deal with this.

Alan Wells

unread,
Apr 25, 2021, 10:44:33 AM4/25/21
to Google Apps Script Community
If you want to see log entries in "real time" of your code running,
then you may want to use something other than the Executions log.
Note that there is the Execution log, which is built into the new code editor,
and is displayed at the bottom,
and the Executions log which is a web app dashboard in a separate browser tab.
I just realized that we might be referencing two different things.
Then there is the Stackdriver log, which is something else.
For debugging, I most often log messages out to a spreadsheet.
But that requires your own "set up" to log messages.
Have you tried looking at the Stackdriver log?
If you are using the new code editor, then there is no easy way to get to your Stackdriver logs.
You'd need to use the Legacy code editor and the View -> Stackdriver Logging menu item.
Reply all
Reply to author
Forward
0 new messages