RippleWorkers / src /scripts /check-connections.ts
damndeepesh
Initialize project with LavinMQ integration and Docker support
c7fbc2e
Raw History Blame Contribute Delete
3.75 kB
import { createClient } from '@supabase/supabase-js';
import { Redis } from '@upstash/redis';
import amqplib from 'amqplib';
import dotenv from 'dotenv';
import path from 'path';
// Load environment variables from .env.local
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
async function checkSupabase() {
console.log('--- Checking Supabase ---');
if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
console.error('❌ Missing Supabase credentials');
return;
}
try {
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
);
const { data, error } = await supabase.from('User').select('count', { count: 'exact', head: true });
if (error) {
console.error('❌ Supabase Connection Failed:', error.message);
} else {
console.log('βœ… Supabase Connected');
}
} catch (e: any) {
console.error('❌ Supabase Connection Error:', e.message);
}
}
async function checkUpstash() {
console.log('\n--- Checking QStash ---');
if (process.env.QSTASH_TOKEN) {
console.log('βœ… QStash Token found');
// Verify token validity by listing messages or similar if possible,
// but for now existence is a strong indicator.
// We can try to instantiate the client.
try {
// Basic import check was done at top.
// Real check:
const { Client } = await import("@upstash/qstash");
const client = new Client({ token: process.env.QSTASH_TOKEN });
// There isn't a simple "ping" in QStash client, but client creation is a start.
console.log('βœ… QStash Client initialized');
} catch (e: any) {
console.error('❌ QStash Client Init Failed:', e.message);
}
} else {
console.warn('⚠️ QStash Token (QSTASH_TOKEN) not found');
}
console.log('\n--- Checking Upstash Redis (Optional) ---');
if (!process.env.UPSTASH_REDIS_REST_URL || !process.env.UPSTASH_REDIS_REST_TOKEN) {
console.log('ℹ️ Upstash Redis credentials missing (Skipping)');
return;
}
try {
const redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL,
token: process.env.UPSTASH_REDIS_REST_TOKEN,
});
await redis.set('test_connection', 'ok');
const val = await redis.get('test_connection');
if (val === 'ok') {
console.log('βœ… Upstash Redis Connected');
await redis.del('test_connection');
} else {
console.error('❌ Upstash Redis Failed: Unexpected value');
}
} catch (e: any) {
console.error('❌ Upstash Redis Connection Error:', e.message);
}
}
async function checkLavinMQ() {
console.log('\n--- Checking LavinMQ ---');
const url = process.env.LAVINMQ_URL;
if (!url) {
console.warn('⚠️ LAVINMQ_URL not found in environment. Checking default localhost...');
}
const connectionUrl = url || 'amqp://guest:guest@localhost:5672';
try {
const conn = await amqplib.connect(connectionUrl);
const channel = await conn.createChannel();
console.log(`βœ… LavinMQ Connected to ${connectionUrl}`);
await channel.close();
await conn.close();
} catch (e: any) {
console.error('❌ LavinMQ Connection Failed:', e.message);
}
}
async function main() {
console.log('Starting Connection Checks...\n');
await checkSupabase();
await checkUpstash();
await checkLavinMQ();
console.log('\nDone.');
}
main();