mirror of
				https://github.com/hackku21/loc-chain-backend.git
				synced 2025-06-13 12:53:59 +00:00 
			
		
		
		
	Force trylock to write description to rtdb
This commit is contained in:
		
							parent
							
								
									1423e1961e
								
							
						
					
					
						commit
						092f3d49f1
					
				| @ -4,10 +4,9 @@ import {LocalFilesystem, LocalFilesystemConfig} from "@extollo/util" | ||||
| export default { | ||||
|     debug: env('DEBUG_MODE', false), | ||||
| 
 | ||||
|     base_url: env('BASE_URL', 'http://localhost:8000/'), | ||||
|     base_url: env('BASE_URL', 'http://192.168.0.29:8000/'), | ||||
| 
 | ||||
|     peers: [ | ||||
|         'http://127.0.0.1:8100/', | ||||
|     ], | ||||
| 
 | ||||
|     session: { | ||||
|  | ||||
| @ -281,7 +281,7 @@ export class Blockchain extends Unit { | ||||
|             this.isSubmitting = true | ||||
|         } | ||||
| 
 | ||||
|         await this.firebase.trylock('block') | ||||
|         await this.firebase.trylock('block', 'Blockchain_refresh') | ||||
|         const validSeqID = (await this.read()).reverse()[0]?.seqID | ||||
| 
 | ||||
|         const peers = await this.getPeers() | ||||
|  | ||||
| @ -40,14 +40,16 @@ export class FirebaseUnit extends Unit { | ||||
|      * Try to lock the given database ref alias. | ||||
|      * Promise will sleep if lock is held, and will resolve once lock is acquired. | ||||
|      * @param name | ||||
|      * @param description | ||||
|      */ | ||||
|     async trylock(name: RTDBRef): Promise<any> { | ||||
|     async trylock(name: RTDBRef, description: string): Promise<any> { | ||||
|         return this._firebase.database() | ||||
|             .ref(`${this.config.get('app.firebase.rtdb.refs.locks')}/${name}`) | ||||
|             .transaction(current => { | ||||
|                 if ( !current || current.time < 1 ) { | ||||
|                     return { | ||||
|                         time: (new Date).getTime(), | ||||
|                         description, | ||||
|                     } | ||||
|                 } | ||||
|             }, undefined, false).then(async result => { | ||||
| @ -58,12 +60,12 @@ export class FirebaseUnit extends Unit { | ||||
| 
 | ||||
|                 this.logging.debug(`Unable to acquire lock: ${name}. Trying again soon...`) | ||||
|                 await this.sleep(500) | ||||
|                 return this.trylock(name) | ||||
|                 return this.trylock(name, description) | ||||
|             }) | ||||
|             .catch(async reason => { | ||||
|                 this.logging.debug(`Unable to acquire lock: ${name}. Trying again soon...`) | ||||
|                 await this.sleep(500) | ||||
|                 return this.trylock(name) | ||||
|                 return this.trylock(name, description) | ||||
|             }) | ||||
|     } | ||||
| 
 | ||||
| @ -74,7 +76,7 @@ export class FirebaseUnit extends Unit { | ||||
|     async unlock(name: RTDBRef) { | ||||
|         await this._firebase.database() | ||||
|             .ref(`${this.config.get('app.firebase.rtdb.refs.locks')}/${name}`) | ||||
|             .set({time: 0}, err => { | ||||
|             .set({time: 0, description: 'none'}, err => { | ||||
|                 if ( err ) this.logging.error(err) | ||||
|             }) | ||||
|     } | ||||
|  | ||||
| @ -47,7 +47,7 @@ export class Exposure extends Unit { | ||||
|         this.firebase.ref('exposure').on('child_added', async (snapshot) => { | ||||
|             this.logging.debug('Received child_added event for exposures reference.') | ||||
|             if ( !this.claim() ) return | ||||
|             await this.firebase.trylock('block') | ||||
|             await this.firebase.trylock('block', 'Exposure_child_added') | ||||
| 
 | ||||
|             const exposure: ExposureResourceItem = snapshot.val() | ||||
| 
 | ||||
|  | ||||
| @ -77,7 +77,7 @@ export class Transaction extends Unit { | ||||
|         this.firebase.ref("transaction").on("child_added", async () => { | ||||
|             this.logging.debug('Received child_added event for transactions reference.') | ||||
|             if ( !this.claim() ) return | ||||
|             await this.firebase.trylock('block') | ||||
|             await this.firebase.trylock('block', 'Transaction_child_added') | ||||
| 
 | ||||
|             // array of pairs of transaction resource items
 | ||||
|             let groupedTransactions: [TransactionResourceItem, TransactionResourceItem][] = [] | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user