Catch indexdb database destroy

This commit is contained in:
Chocobozzz 2018-05-15 16:52:19 +02:00
parent e998cf3cc7
commit 4935a6a1fd
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 12 additions and 15 deletions

View File

@ -183,25 +183,21 @@ export class PeertubeChunkStore extends EventEmitter {
private checkExpiration () { private checkExpiration () {
this.expirationDB.transaction('rw', this.expirationDB.databases, async () => { this.expirationDB.transaction('rw', this.expirationDB.databases, async () => {
try { // Update our database expiration since we are alive
// Update our database expiration since we are alive await this.expirationDB.databases.put({
await this.expirationDB.databases.put({ name: this.databaseName,
name: this.databaseName, expiration: new Date().getTime() + PeertubeChunkStore.CLEANER_EXPIRATION_MS
expiration: new Date().getTime() + PeertubeChunkStore.CLEANER_EXPIRATION_MS })
})
const now = new Date().getTime() const now = new Date().getTime()
const databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray() const databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray()
for (const databaseToDeleteInfo of databasesToDeleteInfo) { for (const databaseToDeleteInfo of databasesToDeleteInfo) {
await this.dropDatabase(databaseToDeleteInfo.name) await this.dropDatabase(databaseToDeleteInfo.name)
await this.expirationDB.databases.where({ name: databaseToDeleteInfo.name }).delete() await this.expirationDB.databases.where({ name: databaseToDeleteInfo.name }).delete()
}
} catch (err) {
console.error('Cannot check expiration.', err)
} }
}) }).catch(err => console.error('Cannot check expiration.', err))
} }
private dropDatabase (databaseName: string) { private dropDatabase (databaseName: string) {
@ -209,6 +205,7 @@ export class PeertubeChunkStore extends EventEmitter {
console.log('Deleting %s.', databaseName) console.log('Deleting %s.', databaseName)
return dbToDelete.delete() return dbToDelete.delete()
.catch(err => console.error('Cannot delete %s.', databaseName))
} }
private nextTick (cb, err, val?) { private nextTick (cb, err, val?) {