Skip to content

Commit

Permalink
Merge pull request #1274 from Shelf-nu/1272-bug-max-client-connection…
Browse files Browse the repository at this point in the history
…s-reached

fix: issue with reaching max connections
  • Loading branch information
DonKoko authored Sep 2, 2024
2 parents 19d4b94 + 489f6ce commit 8011908
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 324 deletions.
1 change: 1 addition & 0 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { registerBookingWorkers } from "./modules/booking/worker.server";
import { ShelfError } from "./utils/error";
import { Logger } from "./utils/logger";
import * as schedulerService from "./utils/scheduler.server";
export * from "../server";

// === start: register scheduler and workers ===
schedulerService
Expand Down
10 changes: 7 additions & 3 deletions app/utils/scheduler.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ declare global {

export const init = async () => {
if (!scheduler) {
const url = DATABASE_URL.split("?")[0];
if (NODE_ENV === "production") {
scheduler = new PgBoss(DATABASE_URL);
scheduler = new PgBoss({
max: 4,
connectionString: url,
});
} else {
if (!global.scheduler) {
global.scheduler = new PgBoss({
max: 5,
connectionString: DATABASE_URL,
max: 4,
connectionString: url,
newJobCheckIntervalSeconds: 60 * 5,
noScheduling: true, //need to remove it, if we use cron schedulers in the future, but it comes with a cost of 2 additional polling every minute
});
Expand Down
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ port = 443
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = false
auto_stop_machines = "off"
auto_start_machines = false
min_machines_running = 1
processes = ["app"]
Expand Down
Loading

0 comments on commit 8011908

Please sign in to comment.