Fix monitoring PF CI lint issues
This commit is contained in:
@@ -24,7 +24,4 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-python@v5
|
- run: python3 -m compileall app
|
||||||
with:
|
|
||||||
python-version: "3.12"
|
|
||||||
- run: python -m compileall app
|
|
||||||
|
|||||||
@@ -29,7 +29,11 @@ func main() {
|
|||||||
slog.Error("db_open_failed", "error", err)
|
slog.Error("db_open_failed", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer app.Close()
|
defer func() {
|
||||||
|
if err := app.Close(); err != nil {
|
||||||
|
slog.Warn("app_close_failed", "error", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
if !app.TG.Enabled() {
|
if !app.TG.Enabled() {
|
||||||
slog.Error("telegram_token_missing")
|
slog.Error("telegram_token_missing")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -24,7 +24,11 @@ func main() {
|
|||||||
slog.Error("db_open_failed", "error", err)
|
slog.Error("db_open_failed", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer app.Close()
|
defer func() {
|
||||||
|
if err := app.Close(); err != nil {
|
||||||
|
slog.Warn("app_close_failed", "error", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
interval := cfg.SchedulerInterval()
|
interval := cfg.SchedulerInterval()
|
||||||
slog.Info("monitoring_pf_scheduler_started", "interval", interval.String())
|
slog.Info("monitoring_pf_scheduler_started", "interval", interval.String())
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ func main() {
|
|||||||
slog.Error("db_open_failed", "error", err)
|
slog.Error("db_open_failed", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer app.Close()
|
defer func() {
|
||||||
|
if err := app.Close(); err != nil {
|
||||||
|
slog.Warn("app_close_failed", "error", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", cfg.WebHost, cfg.WebPort),
|
Addr: fmt.Sprintf("%s:%d", cfg.WebHost, cfg.WebPort),
|
||||||
|
|||||||
@@ -137,6 +137,14 @@ func (a *App) Close() error {
|
|||||||
return a.DB.Close()
|
return a.DB.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func closeRows(rows *sql.Rows) {
|
||||||
|
_ = rows.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func rollbackTx(tx *sql.Tx) {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) InitDB(ctx context.Context) error {
|
func (a *App) InitDB(ctx context.Context) error {
|
||||||
stmts := []string{
|
stmts := []string{
|
||||||
`CREATE TABLE IF NOT EXISTS employees (
|
`CREATE TABLE IF NOT EXISTS employees (
|
||||||
@@ -210,7 +218,7 @@ func (a *App) migrateEmployees(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer closeRows(rows)
|
||||||
columns := map[string]bool{}
|
columns := map[string]bool{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var cid int
|
var cid int
|
||||||
@@ -237,7 +245,7 @@ func (a *App) migrateCompetitorListings(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer closeRows(rows)
|
||||||
columns := map[string]bool{}
|
columns := map[string]bool{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var cid int
|
var cid int
|
||||||
@@ -325,15 +333,6 @@ func enumStatusOut(value string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func enumStatusIn(value string) string {
|
|
||||||
switch strings.ToLower(value) {
|
|
||||||
case "removed":
|
|
||||||
return "REMOVED"
|
|
||||||
default:
|
|
||||||
return "ACTIVE"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func timeOut(raw sql.NullString) *string {
|
func timeOut(raw sql.NullString) *string {
|
||||||
if !raw.Valid || strings.TrimSpace(raw.String) == "" {
|
if !raw.Valid || strings.TrimSpace(raw.String) == "" {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (a *App) ListEmployees(ctx context.Context, isAdmin bool, current *Employee
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer closeRows(rows)
|
||||||
return scanEmployees(rows)
|
return scanEmployees(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ func (a *App) ListProjects(ctx context.Context, ownerID int64) ([]Project, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer closeRows(rows)
|
||||||
items := []Project{}
|
items := []Project{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
p, err := a.scanProject(ctx, rows, false)
|
p, err := a.scanProject(ctx, rows, false)
|
||||||
@@ -353,7 +353,7 @@ func (a *App) DeleteProject(ctx context.Context, ownerID, projectID int64) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer rollbackTx(tx)
|
||||||
listingRows, err := tx.QueryContext(ctx, `SELECT id FROM competitor_listings WHERE project_id = ?`, projectID)
|
listingRows, err := tx.QueryContext(ctx, `SELECT id FROM competitor_listings WHERE project_id = ?`, projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -362,12 +362,12 @@ func (a *App) DeleteProject(ctx context.Context, ownerID, projectID int64) error
|
|||||||
for listingRows.Next() {
|
for listingRows.Next() {
|
||||||
var id int64
|
var id int64
|
||||||
if err := listingRows.Scan(&id); err != nil {
|
if err := listingRows.Scan(&id); err != nil {
|
||||||
listingRows.Close()
|
closeRows(listingRows)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
listingIDs = append(listingIDs, id)
|
listingIDs = append(listingIDs, id)
|
||||||
}
|
}
|
||||||
listingRows.Close()
|
closeRows(listingRows)
|
||||||
for _, id := range listingIDs {
|
for _, id := range listingIDs {
|
||||||
if _, err := tx.ExecContext(ctx, `DELETE FROM price_history WHERE listing_id = ?`, id); err != nil {
|
if _, err := tx.ExecContext(ctx, `DELETE FROM price_history WHERE listing_id = ?`, id); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -392,7 +392,7 @@ func (a *App) DeleteListing(ctx context.Context, ownerID, listingID int64) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer rollbackTx(tx)
|
||||||
if _, err := tx.ExecContext(ctx, `
|
if _, err := tx.ExecContext(ctx, `
|
||||||
DELETE FROM price_history
|
DELETE FROM price_history
|
||||||
WHERE listing_id IN (
|
WHERE listing_id IN (
|
||||||
@@ -508,10 +508,10 @@ func (a *App) ListingsForProject(ctx context.Context, projectID int64, withHisto
|
|||||||
items = append(items, *item)
|
items = append(items, *item)
|
||||||
}
|
}
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
rows.Close()
|
closeRows(rows)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rows.Close()
|
closeRows(rows)
|
||||||
if withHistory {
|
if withHistory {
|
||||||
for i := range items {
|
for i := range items {
|
||||||
history, err := a.PriceHistory(ctx, items[i].ID)
|
history, err := a.PriceHistory(ctx, items[i].ID)
|
||||||
@@ -562,7 +562,7 @@ func (a *App) TeamOverview(ctx context.Context, portalUserIDs []string, all bool
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer closeRows(rows)
|
||||||
items := []TeamOverviewRow{}
|
items := []TeamOverviewRow{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var item TeamOverviewRow
|
var item TeamOverviewRow
|
||||||
@@ -614,7 +614,7 @@ func (a *App) PriceHistory(ctx context.Context, listingID int64) ([]PricePoint,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer closeRows(rows)
|
||||||
out := []PricePoint{}
|
out := []PricePoint{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var p PricePoint
|
var p PricePoint
|
||||||
|
|||||||
Reference in New Issue
Block a user