From 6d4337febb2d030d256327213bb11f4ee08cd2d5 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 22 May 2025 16:54:24 +0700 Subject: [PATCH] Do not retry for some kind of errors in Github (#9055) Signed-off-by: Andrey Sobolev --- server-plugins/time-resources/src/index.ts | 10 +++-- .../pod-github/src/sync/pullrequests.ts | 4 +- services/github/pod-github/src/worker.ts | 37 ++++++++++++++++++- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/server-plugins/time-resources/src/index.ts b/server-plugins/time-resources/src/index.ts index d5de9bf25e..1e648da530 100644 --- a/server-plugins/time-resources/src/index.ts +++ b/server-plugins/time-resources/src/index.ts @@ -365,6 +365,11 @@ export async function OnToDoUpdate (txes: Tx[], control: TriggerControl): Promis const description = updTx.operations.description const visibility = updTx.operations.visibility if (doneOn != null) { + const todo = (await control.findAll(control.ctx, time.class.ToDo, { _id: updTx.objectId }))[0] + if (todo === undefined || todo.doneOn != null) { + // Do not process already processed todos. + continue + } const events = await control.findAll(control.ctx, time.class.WorkSlot, { attachedTo: updTx.objectId }) const resEvents: WorkSlot[] = [] for (const event of events) { @@ -405,10 +410,7 @@ export async function OnToDoUpdate (txes: Tx[], control: TriggerControl): Promis resEvents.push(event) } } - const todo = (await control.findAll(control.ctx, time.class.ToDo, { _id: updTx.objectId }))[0] - if (todo === undefined) { - continue - } + const funcs = control.hierarchy.classHierarchyMixin, OnToDo>( todo.attachedToClass, serverTime.mixin.OnToDo diff --git a/services/github/pod-github/src/sync/pullrequests.ts b/services/github/pod-github/src/sync/pullrequests.ts index 94645c5a94..b5e1bec54a 100644 --- a/services/github/pod-github/src/sync/pullrequests.ts +++ b/services/github/pod-github/src/sync/pullrequests.ts @@ -728,7 +728,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS if (allResolved) { // We need to complete or remove todo, in case all are resolved. if (!Array.from(approvedOrChangesRequested.values()).includes('CHANGES_REQUESTED')) { - const todos = allTodos.filter((it) => it.purpose === 'fix') + const todos = allTodos.filter((it) => it.purpose === 'fix' && it.doneOn == null) for (const t of todos) { await this.markDoneOrDeleteTodo(t) } @@ -853,7 +853,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS private async markDoneOrDeleteTodo (td: WithLookup): Promise { // Let's mark as done in any case - await this.client.update(td, { + await this.client.diffUpdate(td, { doneOn: Date.now() }) } diff --git a/services/github/pod-github/src/worker.ts b/services/github/pod-github/src/worker.ts index 4482cd4a65..5c18d4eb97 100644 --- a/services/github/pod-github/src/worker.ts +++ b/services/github/pod-github/src/worker.ts @@ -1156,6 +1156,30 @@ export class GithubWorker implements IntegrationManager { state: wrongAuthentications }) } + + const fixWrongLastGithubAccount = 'migrate-lastGithubAccount' + + if (migrations.find((it) => it.plugin === githubId && it.state === fixWrongLastGithubAccount) === undefined) { + while (true) { + const syncInfos = await this.client.findAll( + github.class.DocSyncInfo, + { lastGithubUser: { $ne: null } }, + { limit: 500 } + ) + if (syncInfos.length === 0) { + break + } + const ops = this._client.apply() + for (const auth of syncInfos) { + await ops.update(auth, { lastGithubUser: null }) + } + await ops.commit() + } + await derivedClient.createDoc(core.class.MigrationState, core.space.Configuration, { + plugin: githubId, + state: fixWrongLastGithubAccount + }) + } } async syncAndWait (): Promise { @@ -1606,7 +1630,18 @@ export class GithubWorker implements IntegrationManager { } const ops = derivedClient.apply() for (const d of withError) { - await ops.update(d, { error: null, needSync: '' }) + const errStr = JSON.stringify(d.error) + // Skip this error's and not retry + const skipError = + errStr.includes('Bad credentials') || + errStr.includes('Resource not accessible by integration') || + errStr.includes('does not have permission to update') || + errStr.includes('State cannot be changed') || + errStr.includes('Not Found') || + errStr.includes('Could not resolve to a node with the global') || + errStr.includes('Body is too long, Body is too long') + + await ops.update(d, { error: null, needSync: skipError ? githubSyncVersion : '' }) } await ops.commit() }