Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9843

Exceeded maximum excecution time. Google Apps Script. (simple script runs a thousand times)

$
0
0

Sorry for the bad language right away (I use a translator). I read many topics with this problem, unfortunately I could not find an answer. The problem is obvious, it takes longer than 6 minutes.But! I am using this simple script:

function simple(name, date) {  const searchSheet = SpreadsheetApp.getActive().getSheetByName(date);  if (searchSheet !== null) {    const names = searchSheet.getRange('B:B').getValues()    const index = [];    names.forEach(element => {      if (element[0] === name) index.push(names.indexOf(element) + 1);    });    if (index.length > 1) return 'двестрочки';    if (index.length === 0) return;    const all = searchSheet.getRange(index[0], 3, 1, 4).getValues();    const timeCome = all[0][0];    let timeEnd = all[0][1];    const checkTime = all[0][2];    const comment = all[0][3];    if (timeEnd < timeCome) timeEnd.setDate(timeEnd.getDate() + 1);    let countHours = (timeEnd - timeCome) / 1000 / 60 / 60;    if (/обед/i.test(comment.toLowerCase())) countHours -= 1;    if (countHours === checkTime) {      return checkTime;    } else {      return 'ОШИБКА'    }  }}

As you can see, the script is elementary, the problem is that I execute it in each cell XD. It turns out more than a thousand simultaneous executions. And then I see the following picture (wherever Error is - "Exceeded maximum excecution time").

enter image description here

As you can see, only a small part "freezes". the rest are working fine.

Please give advice on how to overcome this. Thank!

P.S. I tried to make a time trigger, it runs stably every 10 minutes, but the number of errors does not decrease.


Viewing all articles
Browse latest Browse all 9843

Trending Articles