Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
var MssqlDB *sql.DB
|
||||
var UretimDB *sql.DB
|
||||
|
||||
func envInt(name string, fallback int) int {
|
||||
raw := strings.TrimSpace(os.Getenv(name))
|
||||
@@ -123,3 +124,37 @@ func ConnectMSSQL() error {
|
||||
func GetDB() *sql.DB {
|
||||
return MssqlDB
|
||||
}
|
||||
|
||||
// ConnectMSSQLUretim initializes the URETIM MSSQL connection from environment.
|
||||
func ConnectMSSQLUretim() error {
|
||||
connString := strings.TrimSpace(os.Getenv("URETIM_MSSQL_CONN"))
|
||||
if connString == "" {
|
||||
return fmt.Errorf("URETIM_MSSQL_CONN tanimli degil")
|
||||
}
|
||||
|
||||
connectionTimeoutSec := envInt("URETIM_MSSQL_CONNECTION_TIMEOUT_SEC", envInt("MSSQL_CONNECTION_TIMEOUT_SEC", 120))
|
||||
dialTimeoutSec := envInt("URETIM_MSSQL_DIAL_TIMEOUT_SEC", connectionTimeoutSec)
|
||||
connString = ensureMSSQLTimeouts(connString, connectionTimeoutSec, dialTimeoutSec)
|
||||
|
||||
var err error
|
||||
UretimDB, err = sql.Open("sqlserver", connString)
|
||||
if err != nil {
|
||||
return fmt.Errorf("URETIM MSSQL baglanti hatasi: %w", err)
|
||||
}
|
||||
|
||||
UretimDB.SetMaxOpenConns(envInt("URETIM_MSSQL_MAX_OPEN_CONNS", envInt("MSSQL_MAX_OPEN_CONNS", 40)))
|
||||
UretimDB.SetMaxIdleConns(envInt("URETIM_MSSQL_MAX_IDLE_CONNS", envInt("MSSQL_MAX_IDLE_CONNS", 40)))
|
||||
UretimDB.SetConnMaxLifetime(time.Duration(envInt("URETIM_MSSQL_CONN_MAX_LIFETIME_MIN", envInt("MSSQL_CONN_MAX_LIFETIME_MIN", 30))) * time.Minute)
|
||||
UretimDB.SetConnMaxIdleTime(time.Duration(envInt("URETIM_MSSQL_CONN_MAX_IDLE_MIN", envInt("MSSQL_CONN_MAX_IDLE_MIN", 10))) * time.Minute)
|
||||
|
||||
if err = UretimDB.Ping(); err != nil {
|
||||
return fmt.Errorf("URETIM MSSQL erisilemiyor: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("URETIM MSSQL baglantisi basarili (connection timeout=%ds, dial timeout=%ds)\n", connectionTimeoutSec, dialTimeoutSec)
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetUretimDB() *sql.DB {
|
||||
return UretimDB
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user