A
A
Ayan Bai2015-06-01 12:14:39
JavaScript
Ayan Bai, 2015-06-01 12:14:39

How to run 10-15 functions sequentially in google apps script?

Best day friends!
I wrote a script that requests a list of orders from sales representatives from the service.
I have 10 projects, they will continue to grow, plus it may be that some queries can take more than 5 minutes (this is the time that Google gives to download data from external sources, but this question is for another topic)
I have such a problem. I hang a trigger on functions, but for some reason only 3-4 of them are executed, and the rest are not loaded.

function addTriggers (){
ScriptApp.newTrigger("startUpdate").timeBased().everyHours(6).create();
}

function startUpdate(){
danon();
mars();
curren1();
curren2();
vilma();
seitek();  
radost();
rolls();
lysse();
}

How can I make them load? I can't think of a way to load each function at a specific time.
For example like this:
function addTriggers () {
ScriptApp.newTrigger("danon").timeBased().everyHours(6).create();
ScriptApp.newTrigger("mars").timeBased().everyHours(6).create();
ScriptApp.newTrigger("seitek").timeBased().everyHours(6).create();
}

I already tried this, but my script does not work correctly when filling in the table data.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Ivanov, 2020-06-13
@wolf47

With some degree of probability, we can assume that this will work

/**
 *
 */
const SETTINGS = Object.freeze({
  fns: [
    'danon',
    'mars',
    'curren1',
    'curren2',
    'vilma',
    'seitek',
    'radost',
    'rolls',
    'lysse',
  ],
});

/**
 *
 */
function addTriggers() {
  ScriptApp.getProjectTriggers().forEach((trigger) => {
    if (
      trigger.getEventType() === ScriptApp.EventType.CLOCK &&
      SETTINGS.fns.includes(trigger.getHandlerFunction())
    ) {
      ScriptApp.deleteTrigger(trigger);
    }
  });
  SETTINGS.fns.forEach((fn) =>
    ScriptApp.newTrigger(fn).timeBased().everyHours(6).create()
  );
}

Nothing prevents triggers from working in parallel, so there should be no errors.

K
Konstantin Kitmanov, 2015-06-01
@k12th

Maybe the third or fourth function crashes with an error, and therefore the execution does not go further?

S
scapp, 2015-06-04
@scapp

In the debugger, run your function in debugger mode - a button with a bug - it will tell you where the error is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question