* Commit the transaction * * @returns {Promise}
()
| 53 | * @returns {Promise} |
| 54 | */ |
| 55 | async commit() { |
| 56 | if (this.finished) { |
| 57 | throw new Error(`Transaction cannot be committed because it has been finished with state: ${this.finished}`); |
| 58 | } |
| 59 | |
| 60 | try { |
| 61 | await this.sequelize.getQueryInterface().commitTransaction(this, this.options); |
| 62 | this.cleanup(); |
| 63 | } catch (e) { |
| 64 | console.warn(`Committing transaction ${this.id} failed with error ${JSON.stringify(e.message)}. We are killing its connection as it is now in an undetermined state.`); |
| 65 | await this.forceCleanup(); |
| 66 | |
| 67 | throw e; |
| 68 | } finally { |
| 69 | this.finished = 'commit'; |
| 70 | for (const hook of this._afterCommitHooks) { |
| 71 | await hook.apply(this, [this]); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Rollback (abort) the transaction |