Skip to content

Commit

Permalink
fix(sync): add lock for provider name (#284)
Browse files Browse the repository at this point in the history
* fix(sync): add lock for provider name

* migration
  • Loading branch information
samuelmasse committed Dec 13, 2021
1 parent dd5162c commit f92111c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions packages/server/src/migrations/0.1.20-fix-client-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Migration } from '@botpress/messaging-engine'

export class FixClientSchemaMigration extends Migration {
meta = {
name: FixClientSchemaMigration.name,
description: 'Fixes broken msg_clients table schema',
version: '0.1.20'
}

async valid() {
return this.trx.schema.hasTable('msg_clients')
}

async applied() {
return false
}

async up() {
return this.trx.schema.alterTable('msg_clients', (table) => {
table.uuid('providerId').nullable().alter()
})
}

async down() {}
}
3 changes: 2 additions & 1 deletion packages/server/src/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Migration } from '@botpress/messaging-engine'
import { StatusMigration } from './0.1.19-status'
import { FixClientSchemaMigration } from './0.1.20-fix-client-schema'

export const Migrations: { new (): Migration }[] = [StatusMigration]
export const Migrations: { new (): Migration }[] = [StatusMigration, FixClientSchemaMigration]
4 changes: 3 additions & 1 deletion packages/server/src/sync/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export class SyncService extends Service {
result = { id: client.id, token: client.token || req.token!, webhooks }
}

if (req.id) {
if (req.name) {
await this.distributed.using(`lock_dyn_sync_provider::${req.name}`, lockedTask)
} else if (req.id) {
await this.distributed.using(`lock_dyn_sync_client::${req.id}`, lockedTask)
} else {
await lockedTask()
Expand Down

0 comments on commit f92111c

Please sign in to comment.