-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f6fdea
commit 597a1aa
Showing
7 changed files
with
50 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import * as prometheus from "./prometheus.js"; | ||
import { Database } from "bun:sqlite"; | ||
import { select } from "./sqlite.js"; | ||
import * as sqlite from "./sqlite.js"; | ||
|
||
export async function checkHealth(){ | ||
const traces = new Database("./sqlite/sessionId.sqlite"); | ||
const session = select(traces, "sessionId").length | ||
const messages = await prometheus.getSingleMetric(`total_webhooks_sessions`) | ||
|
||
if (messages || session) return {data: "OK", status: { status: 200 }}; | ||
export async function checkHealth(db: Database) { | ||
const total_trace_id = sqlite.findAll(db, "traceId").length; | ||
if (total_trace_id) return {data: "OK", status: { status: 200 }}; | ||
return {data: "Error: No connected webhooks", status: { status: 400 }}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { IncomingMessage, ServerResponse } from "http"; | ||
|
||
export function toText(data: any, status = 200) { | ||
const headers = { 'Content-Type': 'text/plain; charset=utf-8' }; | ||
return new Response(data, { status, headers }); | ||
} | ||
|
||
export function toJSON(data: any, status = 200) { | ||
const body = JSON.stringify(data, null, 2); | ||
const headers = { 'Content-Type': 'application/json' }; | ||
return new Response(body, { status, headers }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
function create(db: any, column: string){ | ||
db.query(`create table if not exists data (${column} text primary key)`).run(); | ||
import Database from "bun:sqlite"; | ||
|
||
export function create(db: Database, table: string) { | ||
return db.query(`CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT)`).run(); | ||
} | ||
|
||
export function insert(db: Database, table: string, key: string, value: string|number) { | ||
return db.query(`INSERT OR REPLACE INTO ${table} (key, value) values (?, ?)`).all(key, value); | ||
} | ||
|
||
export function insert(db: any, data: string, column: string){ | ||
create(db, column) | ||
return db.query(`insert or ignore into data (${column}) values (?)`).all(data); | ||
export function findAll(db: Database, table: string) { | ||
return db.query(`SELECT * from ${table}`).all(); | ||
} | ||
|
||
export function select(db: any, column: string){ | ||
create(db, column) | ||
return db.query(`select ${column} from data`).all(); | ||
} | ||
export function find(db: Database, table: string, key: string) { | ||
return db.query(`SELECT * from ${table} WHERE key=${key}`).all(); | ||
} |