chore(ci): release database after closed (#4819)

* chore(ci): release database after closed

* chore: clean database

* chore: test
This commit is contained in:
ChengLei Shao 2024-07-04 21:48:51 +08:00 committed by GitHub
parent 88519c9c8f
commit 7084e8d35f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -111,7 +111,7 @@ jobs:
DB_SCHEMA: ${{ matrix.schema }} DB_SCHEMA: ${{ matrix.schema }}
COLLECTION_MANAGER_SCHEMA: ${{ matrix.collection_schema }} COLLECTION_MANAGER_SCHEMA: ${{ matrix.collection_schema }}
DB_TEST_DISTRIBUTOR_PORT: 23450 DB_TEST_DISTRIBUTOR_PORT: 23450
DB_TEST_PREFIX: test_ DB_TEST_PREFIX: test
timeout-minutes: 60 timeout-minutes: 60
mysql-test: mysql-test:

View File

@ -36,6 +36,11 @@ abstract class BaseClient<Client> {
await this._createDB(name); await this._createDB(name);
this.createdDBs.add(name); this.createdDBs.add(name);
// remove db after 3 minutes
setTimeout(async () => {
await this.removeDB(name);
}, 3 * 60 * 1000);
} }
async releaseAll() { async releaseAll() {
@ -51,6 +56,16 @@ abstract class BaseClient<Client> {
this.createdDBs.delete(name); this.createdDBs.delete(name);
} }
} }
async removeDB(name: string) {
if (!this._client) {
return;
}
if (this.createdDBs.has(name)) {
await this._removeDB(name);
this.createdDBs.delete(name);
}
}
} }
class PostgresClient extends BaseClient<pg.Client> { class PostgresClient extends BaseClient<pg.Client> {
@ -156,8 +171,9 @@ const server = http.createServer((req, res) => {
res.end(JSON.stringify({ error })); res.end(JSON.stringify({ error }));
}); });
} else if (trimmedPath === 'release') { } else if (trimmedPath === 'release') {
const name = parsedUrl.query.name as string | undefined;
dbClient dbClient
.releaseAll() .removeDB(name)
.then(() => { .then(() => {
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(); res.end();