Integration executes more than once

Hello,

I’ve built an app which takes excel data - manipulates it, and:

  1. creating an item if there is no item yet
  2. insert the column values if there is an item on the board.

We are talking about huge amount of data that need to be insert (2500~ items)

Here is the example of the integration:

export async function post(boardId, project, token) {
  try {
    const mondayClient = initMondayClient()
    await mondayClient.setToken(token)

    for (let i = 0; i < 2500~; i++) {
      console.log('start of loop')

      const task = ...
      const taskId = ...
      const taskName = ...
      const itemId = await _getItemId(taskId, boardId, token)
      const columnValues = JSON.stringify({
         ....
      })

      if (!itemId) await deleyFunc(_createItem, 2000, boardId, columnValues, taskName, mondayClient, token)
      else await deleyFunc(_changeItem, 2000, boardId, itemId, columnValues, mondayClient, token)
     
      console.log('end of loop')
    }
  } catch (err) {
    console.log('file: monday-service.ts -> line 57 -> post-> err', err)
  }
}

async function _createItem(boardId, columnValues, taskName: string, mondayClient, token) {
  try {
    await mondayClient.setToken(token)

    const mutation= `mutation {
      create_item(board_id: ${boardId}, item_name: ${JSON.stringify(taskName)}, column_values:${JSON.stringify(columnValues)}, create_labels_if_missing: true) {
        id
      }
    }`
    const mutationResponse = await mondayClient.api(mutation)
    console.log('item created')
  } catch (err) {
    console.log('file: monday-service.ts -> line 90 -> _createItem -> err', err)
  }
}

async function _changeItem(boardId, itemId, columnValues, mondayClient, token) {
  try {
    await mondayClient.setToken(token)
    const mutation = `mutation {
      change_multiple_column_values (item_id: ${itemId}, board_id: ${boardId}, column_values: ${JSON.stringify(columnValues)}, create_labels_if_missing: true) {
        id
      }
    }`
    const mutationResponse = await mondayClient.api(mutation)
    console.log('columns changed')
  } catch (err) {
    console.log('file: monday-service.ts -> line 109 -> _changeItem -> err', err)
  }
}

In the first 300-400 items everything goes smooth, but then, I can see on my logs that the integration fires/executes again. The integration runs a few times in parallel.
I have simple console log right after entering to the base url endpoint:

Oct 19 11:53:49.123 fire
Oct 19 11:58:49.166 fire
Oct 19 11:59:19.166 fire
Oct 19 12:01:22.162 fire

We can see that the integration executes again after a few minutes which is a problem.
The integration triggered by button click. I obviously clicked once.
On the “Integrations Activity” I see only one activity and not many. But the integration is definitely repeating itself.

What can cause this? Thanks for any ideas.

Hi @Roy

This behavior looks like retrying from the monday side. Did you encounter complexity limits? Hitting complexity is one of the reasons monday retries.

Hello @basdebruin ,

I don’t see any complexity limits error on my logs (I’m logging each error/response).
And also I don’t believe creation of item/change column values can reach the complexity limit, right?

hi @Roy

Sure column changes can trigger complexity. You have 5.000.000 complexity credit refreshed each minute. A singel update (one item / one column) bares a costs of 30.001. So that leaves us with maximum 166 update per minute. Hitting complexity is is returned in response.errors[0].message.

Hey @basdebruin ,

It may be the problem but I do not see any response with error.
I also tried to timeout between each iteration for few seconds (3 seconds~) which did not help.

Do you maybe have any other idea why the integration rexecute?
Thanks!

hi @Roy

From your code it doesn’t look like you are checking the response at all. Errors like this do not throw an error because the API call was successful. You have to check the response, in your case:

if (mutationResponse.error_code) console.log (mutationResponse.errors[0]);

Instead of just logging “item created”. You might think the item is created (because you are writing that to the console) but you can’t tell without checking the response.

Hey @basdebruin ,

I added console.log, tested again and it is firing it again and I do not see any erors on my logs. I even increased the timeout for each API function for 10 seconds which did not help.

In my new test the console.log(‘fire’), which is on the endpoint post function


router.post('/monday/update', monday.update);
....

export async function update(req, res) {
  console.log('fire')
 .....
}

I can see that the ‘fire’ log is happening several times. Like the last time, exactly after 5 minutes the it execute the integration again, same behavior like the last test I posted:

Oct 19 16:36:57.451 fire
Oct 19 16:41:57.446 fire
more …

I believe now it is not related to the complexity issue, specially because the exact time that the intergation runs again and because I cannot see any error logs.

Thanks

hi @Roy

What does the mutation return? (ie what is the content of mutationResponse)

Complexity errors won’t throw an error, you have to inspect the response from the actual API call

Hey @basdebruin ,

Yes, I know it won’t throw an error. I am logging mutationResponse + log of the condition for:
“if (mutationResponse.error_code) console.log (mutationResponse.errors[0]);” that you mention.
“mutationResponse” returns the data object and the account_id as expected. no errors.
After the integration re-execute multiple times in a parallel, I get complexity error because I am doing same requests at the same time.

I found the solution for this case for poeple who might facing the same issue:

I figured out that if monday not recieving response 200 in 5 minutes the integration will re-execute.
So, I send response 200 ( res.status(200).send({}) ) immediately when entering the intagration and then I perform my tasks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.