mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-03 23:14:13 +00:00 
			
		
		
		
	Impove the check_connect script
This commit is contained in:
		
							parent
							
								
									5496aa27db
								
							
						
					
					
						commit
						0386e52d6f
					
				
					 1 changed files with 27 additions and 5 deletions
				
			
		| 
						 | 
					@ -5,11 +5,33 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Redis from 'ioredis';
 | 
					import Redis from 'ioredis';
 | 
				
			||||||
import { loadConfig } from '../built/config.js';
 | 
					import { loadConfig } from '../built/config.js';
 | 
				
			||||||
 | 
					import { createPostgresDataSource } from '../built/postgres.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const config = loadConfig();
 | 
					const config = loadConfig();
 | 
				
			||||||
const redis = new Redis(config.redis);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
redis.on('connect', () => redis.disconnect());
 | 
					// createPostgresDataSource handels primaries and replicas automatically.
 | 
				
			||||||
redis.on('error', (e) => {
 | 
					// usually, it only opens connections first use, so we force it using
 | 
				
			||||||
	throw e;
 | 
					// .initialize()
 | 
				
			||||||
});
 | 
					createPostgresDataSource(config)
 | 
				
			||||||
 | 
						.initialize()
 | 
				
			||||||
 | 
						.then(c => { c.destroy() })
 | 
				
			||||||
 | 
						.catch(e => { throw e });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Connect to all redis servers
 | 
				
			||||||
 | 
					function connectToRedis(redisOptions) {
 | 
				
			||||||
 | 
						const redis = new Redis(redisOptions);
 | 
				
			||||||
 | 
						redis.on('connect', () => redis.disconnect());
 | 
				
			||||||
 | 
						redis.on('error', (e) => {
 | 
				
			||||||
 | 
							throw e;
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// If not all of these are defined, the default one gets reused.
 | 
				
			||||||
 | 
					// so we use a Set to only try connecting once to each **uniq** redis.
 | 
				
			||||||
 | 
					(new Set([
 | 
				
			||||||
 | 
						config.redis,
 | 
				
			||||||
 | 
						config.redisForPubsub,
 | 
				
			||||||
 | 
						config.redisForJobQueue,
 | 
				
			||||||
 | 
						config.redisForTimelines,
 | 
				
			||||||
 | 
					])).forEach(connectToRedis);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue