🔨 Run once, graceful shutdown, db filename in env
- Refactored toISODateString function - Added Db filename to env - Added getOrDefault function for fetching envs, replaced LOG_LEVEL with getOrDefault - Added script to run job once then exit - Catch SIGINT signal and do a graceful shutdown
This commit is contained in:
12
config.ts
12
config.ts
@ -3,12 +3,14 @@ import dotenv from "dotenv"
|
||||
|
||||
dotenv.config()
|
||||
|
||||
// Actual
|
||||
export const ACTUAL_SYNC_ID = getOrThrow("ACTUAL_SYNC_ID")
|
||||
export const ACTUAL_SERVER_URL = getOrThrow("ACTUAL_SERVER_URL")
|
||||
export const ACTUAL_PASSWORD = getOrThrow("ACTUAL_PASSWORD")
|
||||
export const ACTUAL_ACCOUNT_IDS = getArrayOrThrow("ACTUAL_ACCOUNT_IDS")
|
||||
export const ACTUAL_DATA_DIR = ".cache"
|
||||
export const ACTUAL_DATA_DIR = getOrDefault("ACTUAL_DATA_DIR", ".cache")
|
||||
|
||||
// Bank
|
||||
export const BANK_INITIAL_REFRESH_TOKEN = getOrThrow(
|
||||
"BANK_INITIAL_REFRESH_TOKEN",
|
||||
)
|
||||
@ -16,6 +18,14 @@ export const BANK_OAUTH_CLIENT_ID = getOrThrow("BANK_OAUTH_CLIENT_ID")
|
||||
export const BANK_OAUTH_CLIENT_SECRET = getOrThrow("BANK_OAUTH_CLIENT_SECRET")
|
||||
export const BANK_ACCOUNT_IDS = getArrayOrThrow("BANK_ACCOUNT_IDS")
|
||||
|
||||
// Configuration
|
||||
export const DB_FILENAME = getOrDefault("DB_FILENAME", "default")
|
||||
export const LOG_LEVEL = getOrDefault("LOG_LEVEL", "info")
|
||||
|
||||
function getOrDefault(key: string, def: string): string {
|
||||
return process.env[key] || def
|
||||
}
|
||||
|
||||
function getOrThrow(key: string): string {
|
||||
const value = process.env[key]
|
||||
assert(value, `Missing environment variable: ${key}`)
|
||||
|
Reference in New Issue
Block a user