mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-20 08:56:29 +00:00
HOTFIX: Agent context deadline fix
This commit is contained in:
parent
f5c835b5d9
commit
7e82b42b29
@ -103,10 +103,11 @@ func getApplications(db *sql.DB) []Application {
|
|||||||
|
|
||||||
func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
|
func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
|
||||||
for _, app := range apps {
|
for _, app := range apps {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
|
// Context for HTTP request
|
||||||
defer cancel()
|
httpCtx, httpCancel := context.WithTimeout(context.Background(), 4*time.Second)
|
||||||
|
defer httpCancel()
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "HEAD", app.PublicURL, nil)
|
req, err := http.NewRequestWithContext(httpCtx, "HEAD", app.PublicURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating request: %v\n", err)
|
fmt.Printf("Error creating request: %v\n", err)
|
||||||
continue
|
continue
|
||||||
@ -118,7 +119,12 @@ func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
|
|||||||
isOnline = true
|
isOnline = true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.ExecContext(ctx,
|
// Create a new context for database operations with a separate timeout
|
||||||
|
dbCtx, dbCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer dbCancel()
|
||||||
|
|
||||||
|
// Update application status
|
||||||
|
_, err = db.ExecContext(dbCtx,
|
||||||
`UPDATE application SET online = $1 WHERE id = $2`,
|
`UPDATE application SET online = $1 WHERE id = $2`,
|
||||||
isOnline,
|
isOnline,
|
||||||
app.ID,
|
app.ID,
|
||||||
@ -127,7 +133,8 @@ func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
|
|||||||
fmt.Printf("Update failed for app %d: %v\n", app.ID, err)
|
fmt.Printf("Update failed for app %d: %v\n", app.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.ExecContext(ctx,
|
// Insert into uptime_history
|
||||||
|
_, err = db.ExecContext(dbCtx,
|
||||||
`INSERT INTO uptime_history ("applicationId", online, "createdAt") VALUES ($1, $2, now())`,
|
`INSERT INTO uptime_history ("applicationId", online, "createdAt") VALUES ($1, $2, now())`,
|
||||||
app.ID,
|
app.ID,
|
||||||
isOnline,
|
isOnline,
|
||||||
|
|||||||
15
package-lock.json
generated
15
package-lock.json
generated
@ -4545,21 +4545,6 @@
|
|||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"node_modules/@next/swc-win32-x64-msvc": {
|
|
||||||
"version": "15.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.3.0.tgz",
|
|
||||||
"integrity": "sha512-vHUQS4YVGJPmpjn7r5lEZuMhK5UQBNBRSB+iGDvJjaNk649pTIcRluDWNb9siunyLLiu/LDPHfvxBtNamyuLTw==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"win32"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 10"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user