5 Commits

Author SHA1 Message Date
headlessdev
f024b0166f v0.0.5 uptime_fix->main
v0.0.5
2025-04-17 14:53:40 +02:00
headlessdev
d6889a27b5 Fix: Update online status check to account for HTTP 405 response 2025-04-17 14:41:50 +02:00
headlessdev
edbc72a7c9 Enhance application status check logging and error handling 2025-04-17 14:18:50 +02:00
headlessdev
7e82b42b29 HOTFIX: Agent context deadline fix 2025-04-17 11:36:35 +02:00
headlessdev
f5c835b5d9 Hotfix Docker file 'bcrypt' error 2025-04-16 14:55:09 +02:00
3 changed files with 58 additions and 34 deletions

View File

@@ -6,9 +6,13 @@ WORKDIR /app
COPY package.json package-lock.json* ./
COPY ./prisma ./prisma
# Install all dependencies (including devDependencies)
RUN npm install
# Generate Prisma client
RUN npx prisma generate
# Build the application
COPY . .
RUN npm run build
@@ -19,13 +23,16 @@ WORKDIR /app
ENV NODE_ENV production
# Install production dependencies INCLUDING prisma
# Copy package files
COPY package.json package-lock.json* ./
RUN npm install --production --ignore-scripts
# Copy needed Prisma files
COPY --from=builder /app/node_modules/.prisma /app/node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma /app/node_modules/@prisma
# Copy node_modules from builder
COPY --from=builder /app/node_modules ./node_modules
# Remove dev dependencies
RUN npm prune --production
# Copy Prisma files
COPY --from=builder /app/prisma ./prisma
# Copy built application
@@ -36,5 +43,5 @@ COPY --from=builder /app/next.config.js* ./
EXPOSE 3000
# Run migrations first, then start app
CMD ["sh", "-c", "npx prisma migrate deploy && npm start"]
# Run migrations and start
CMD ["sh", "-c", "npx prisma migrate deploy && npm start"]

View File

@@ -102,38 +102,70 @@ func getApplications(db *sql.DB) []Application {
}
func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
for _, app := range apps {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
fmt.Printf("Start checking %d applications at %v\n", len(apps), time.Now())
req, err := http.NewRequestWithContext(ctx, "HEAD", app.PublicURL, nil)
for i, app := range apps {
logPrefix := fmt.Sprintf("[App %d/%d URL: %s]", i+1, len(apps), app.PublicURL)
fmt.Printf("%s Starting check\n", logPrefix)
// HTTP Check
startHTTP := time.Now()
httpCtx, httpCancel := context.WithTimeout(context.Background(), 4*time.Second)
defer httpCancel()
req, err := http.NewRequestWithContext(httpCtx, "HEAD", app.PublicURL, nil)
if err != nil {
fmt.Printf("Error creating request: %v\n", err)
fmt.Printf("%s Request creation failed: %v\n", logPrefix, err)
continue
}
resp, err := client.Do(req)
isOnline := false
if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
isOnline = true
httpDuration := time.Since(startHTTP)
// Log HTTP details
if err != nil {
fmt.Printf("%s HTTP error after %v: %v\n", logPrefix, httpDuration, err)
} else {
fmt.Printf("%s HTTP %d after %v (ContentLength: %d)\n",
logPrefix, resp.StatusCode, httpDuration, resp.ContentLength)
resp.Body.Close() // Important to prevent leaks
}
_, err = db.ExecContext(ctx,
isOnline := err == nil && resp != nil && resp.StatusCode >= 200 && resp.StatusCode < 300 || resp.StatusCode == 405
// Database Update
dbCtx, dbCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer dbCancel()
startUpdate := time.Now()
updateRes, err := db.ExecContext(dbCtx,
`UPDATE application SET online = $1 WHERE id = $2`,
isOnline,
app.ID,
)
updateDuration := time.Since(startUpdate)
if err != nil {
fmt.Printf("Update failed for app %d: %v\n", app.ID, err)
fmt.Printf("%s UPDATE failed after %v: %v\n", logPrefix, updateDuration, err)
} else {
affected, _ := updateRes.RowsAffected()
fmt.Printf("%s UPDATE OK (%d rows) after %v\n", logPrefix, affected, updateDuration)
}
_, err = db.ExecContext(ctx,
// History Insert
startInsert := time.Now()
insertRes, err := db.ExecContext(dbCtx,
`INSERT INTO uptime_history ("applicationId", online, "createdAt") VALUES ($1, $2, now())`,
app.ID,
isOnline,
)
insertDuration := time.Since(startInsert)
if err != nil {
fmt.Printf("Insert into uptime_history failed for app %d: %v\n", app.ID, err)
fmt.Printf("%s INSERT failed after %v: %v\n", logPrefix, insertDuration, err)
} else {
inserted, _ := insertRes.RowsAffected()
fmt.Printf("%s INSERT OK (%d rows) after %v\n", logPrefix, inserted, insertDuration)
}
}
}

15
package-lock.json generated
View File

@@ -4545,21 +4545,6 @@
"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"
}
}
}
}