The job_run_logs table tracks scheduled job orchestration, not individual worker jobs. Worker info (worker_id, worker_hostname) belongs on dispensary_crawl_jobs, not job_run_logs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
2.2 KiB
JavaScript
80 lines
2.2 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Dutchie AZ Database Connection
|
|
*
|
|
* Isolated database connection for Dutchie Arizona data.
|
|
* Uses a separate database/schema to prevent cross-contamination with main app data.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getDutchieAZPool = getDutchieAZPool;
|
|
exports.query = query;
|
|
exports.getClient = getClient;
|
|
exports.closePool = closePool;
|
|
exports.healthCheck = healthCheck;
|
|
const pg_1 = require("pg");
|
|
// Consolidated DB naming:
|
|
// - Prefer CRAWLSY_DATABASE_URL (e.g., crawlsy_local, crawlsy_prod)
|
|
// - Then DUTCHIE_AZ_DATABASE_URL (legacy)
|
|
// - Finally DATABASE_URL (legacy main DB)
|
|
const DUTCHIE_AZ_DATABASE_URL = process.env.CRAWLSY_DATABASE_URL ||
|
|
process.env.DUTCHIE_AZ_DATABASE_URL ||
|
|
process.env.DATABASE_URL ||
|
|
'postgresql://dutchie:dutchie_local_pass@localhost:54320/crawlsy_local';
|
|
let pool = null;
|
|
/**
|
|
* Get the Dutchie AZ database pool (singleton)
|
|
*/
|
|
function getDutchieAZPool() {
|
|
if (!pool) {
|
|
pool = new pg_1.Pool({
|
|
connectionString: DUTCHIE_AZ_DATABASE_URL,
|
|
max: 10,
|
|
idleTimeoutMillis: 30000,
|
|
connectionTimeoutMillis: 5000,
|
|
});
|
|
pool.on('error', (err) => {
|
|
console.error('[DutchieAZ DB] Unexpected error on idle client:', err);
|
|
});
|
|
console.log('[DutchieAZ DB] Pool initialized');
|
|
}
|
|
return pool;
|
|
}
|
|
/**
|
|
* Execute a query on the Dutchie AZ database
|
|
*/
|
|
async function query(text, params) {
|
|
const p = getDutchieAZPool();
|
|
const result = await p.query(text, params);
|
|
return { rows: result.rows, rowCount: result.rowCount || 0 };
|
|
}
|
|
/**
|
|
* Get a client from the pool for transaction use
|
|
*/
|
|
async function getClient() {
|
|
const p = getDutchieAZPool();
|
|
return p.connect();
|
|
}
|
|
/**
|
|
* Close the pool connection
|
|
*/
|
|
async function closePool() {
|
|
if (pool) {
|
|
await pool.end();
|
|
pool = null;
|
|
console.log('[DutchieAZ DB] Pool closed');
|
|
}
|
|
}
|
|
/**
|
|
* Check if the database is accessible
|
|
*/
|
|
async function healthCheck() {
|
|
try {
|
|
const result = await query('SELECT 1 as ok');
|
|
return result.rows.length > 0 && result.rows[0].ok === 1;
|
|
}
|
|
catch (error) {
|
|
console.error('[DutchieAZ DB] Health check failed:', error);
|
|
return false;
|
|
}
|
|
}
|