feat(stats): don't require a stats database url
This commit is contained in:
parent
2fea773d7e
commit
d1d0faaa7e
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
redis "github.com/go-redis/redis/v8"
|
redis "github.com/go-redis/redis/v8"
|
||||||
"github.com/jackc/pgx/v4/pgxpool"
|
"github.com/jackc/pgx/v4/pgxpool"
|
||||||
@ -22,8 +23,11 @@ func run_simple_pg_query(c *pgxpool.Pool, sql string) {
|
|||||||
func connect_dbs() {
|
func connect_dbs() {
|
||||||
data_db = pg_connect(get_env_var("DATA_DB_URI"))
|
data_db = pg_connect(get_env_var("DATA_DB_URI"))
|
||||||
messages_db = pg_connect(get_env_var("MESSAGES_DB_URI"))
|
messages_db = pg_connect(get_env_var("MESSAGES_DB_URI"))
|
||||||
stats_db = pg_connect(get_env_var("STATS_DB_URI"))
|
|
||||||
rdb = redis_connect(get_env_var("REDIS_ADDR"))
|
rdb = redis_connect(get_env_var("REDIS_ADDR"))
|
||||||
|
|
||||||
|
if uri, ok := os.LookupEnv("STATS_DB_URI"); ok {
|
||||||
|
stats_db = pg_connect(uri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pg_connect(url string) *pgxpool.Pool {
|
func pg_connect(url string) *pgxpool.Pool {
|
||||||
|
@ -70,6 +70,10 @@ func run_data_stats_query() map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func do_stats_insert(table string, value int) {
|
func do_stats_insert(table string, value int) {
|
||||||
|
if stats_db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sql := fmt.Sprintf("insert into %s values (now(), $1)", table)
|
sql := fmt.Sprintf("insert into %s values (now(), $1)", table)
|
||||||
log.Println("stats db query:", sql, "value:", value)
|
log.Println("stats db query:", sql, "value:", value)
|
||||||
_, err := stats_db.Exec(context.Background(), sql, value)
|
_, err := stats_db.Exec(context.Background(), sql, value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user