Skip to content

Commit 6d4337f

Browse files
authored
Do not retry for some kind of errors in Github (#9055)
Signed-off-by: Andrey Sobolev <[email protected]>
1 parent 39d1c0a commit 6d4337f

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

server-plugins/time-resources/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ export async function OnToDoUpdate (txes: Tx[], control: TriggerControl): Promis
365365
const description = updTx.operations.description
366366
const visibility = updTx.operations.visibility
367367
if (doneOn != null) {
368+
const todo = (await control.findAll(control.ctx, time.class.ToDo, { _id: updTx.objectId }))[0]
369+
if (todo === undefined || todo.doneOn != null) {
370+
// Do not process already processed todos.
371+
continue
372+
}
368373
const events = await control.findAll(control.ctx, time.class.WorkSlot, { attachedTo: updTx.objectId })
369374
const resEvents: WorkSlot[] = []
370375
for (const event of events) {
@@ -405,10 +410,7 @@ export async function OnToDoUpdate (txes: Tx[], control: TriggerControl): Promis
405410
resEvents.push(event)
406411
}
407412
}
408-
const todo = (await control.findAll(control.ctx, time.class.ToDo, { _id: updTx.objectId }))[0]
409-
if (todo === undefined) {
410-
continue
411-
}
413+
412414
const funcs = control.hierarchy.classHierarchyMixin<Class<Doc>, OnToDo>(
413415
todo.attachedToClass,
414416
serverTime.mixin.OnToDo

services/github/pod-github/src/sync/pullrequests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
728728
if (allResolved) {
729729
// We need to complete or remove todo, in case all are resolved.
730730
if (!Array.from(approvedOrChangesRequested.values()).includes('CHANGES_REQUESTED')) {
731-
const todos = allTodos.filter((it) => it.purpose === 'fix')
731+
const todos = allTodos.filter((it) => it.purpose === 'fix' && it.doneOn == null)
732732
for (const t of todos) {
733733
await this.markDoneOrDeleteTodo(t)
734734
}
@@ -853,7 +853,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
853853

854854
private async markDoneOrDeleteTodo (td: WithLookup<GithubTodo>): Promise<void> {
855855
// Let's mark as done in any case
856-
await this.client.update(td, {
856+
await this.client.diffUpdate(td, {
857857
doneOn: Date.now()
858858
})
859859
}

services/github/pod-github/src/worker.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,30 @@ export class GithubWorker implements IntegrationManager {
11561156
state: wrongAuthentications
11571157
})
11581158
}
1159+
1160+
const fixWrongLastGithubAccount = 'migrate-lastGithubAccount'
1161+
1162+
if (migrations.find((it) => it.plugin === githubId && it.state === fixWrongLastGithubAccount) === undefined) {
1163+
while (true) {
1164+
const syncInfos = await this.client.findAll(
1165+
github.class.DocSyncInfo,
1166+
{ lastGithubUser: { $ne: null } },
1167+
{ limit: 500 }
1168+
)
1169+
if (syncInfos.length === 0) {
1170+
break
1171+
}
1172+
const ops = this._client.apply()
1173+
for (const auth of syncInfos) {
1174+
await ops.update(auth, { lastGithubUser: null })
1175+
}
1176+
await ops.commit()
1177+
}
1178+
await derivedClient.createDoc(core.class.MigrationState, core.space.Configuration, {
1179+
plugin: githubId,
1180+
state: fixWrongLastGithubAccount
1181+
})
1182+
}
11591183
}
11601184

11611185
async syncAndWait (): Promise<void> {
@@ -1606,7 +1630,18 @@ export class GithubWorker implements IntegrationManager {
16061630
}
16071631
const ops = derivedClient.apply()
16081632
for (const d of withError) {
1609-
await ops.update(d, { error: null, needSync: '' })
1633+
const errStr = JSON.stringify(d.error)
1634+
// Skip this error's and not retry
1635+
const skipError =
1636+
errStr.includes('Bad credentials') ||
1637+
errStr.includes('Resource not accessible by integration') ||
1638+
errStr.includes('does not have permission to update') ||
1639+
errStr.includes('State cannot be changed') ||
1640+
errStr.includes('Not Found') ||
1641+
errStr.includes('Could not resolve to a node with the global') ||
1642+
errStr.includes('Body is too long, Body is too long')
1643+
1644+
await ops.update(d, { error: null, needSync: skipError ? githubSyncVersion : '' })
16101645
}
16111646
await ops.commit()
16121647
}

0 commit comments

Comments
 (0)