Compare commits
1 commit
main
...
fix/demo-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0564ec3923 |
2 changed files with 10 additions and 5 deletions
|
|
@ -13,17 +13,17 @@ import {
|
||||||
import { logger } from "../lib/logger.server.ts";
|
import { logger } from "../lib/logger.server.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate job. Fires every 90 minutes via pg-boss cron. Handler steps:
|
* Generate job. Fires every 30 minutes via pg-boss cron. Handler steps:
|
||||||
*
|
*
|
||||||
* 1. Bail if `DEMO_BOT_ENABLED` is not "true".
|
* 1. Bail if `DEMO_BOT_ENABLED` is not "true".
|
||||||
* 2. On first run (no synthetic rows yet) produce a small backfill so the
|
* 2. On first run (no synthetic rows yet) produce a small backfill so the
|
||||||
* demo user's profile has content immediately.
|
* demo user's profile has content immediately.
|
||||||
* 3. Otherwise apply the decide-to-walk gate (local hour + p=0.12) and
|
* 3. Otherwise apply the decide-to-walk gate (local hour + p=0.09) and
|
||||||
* daily cap; on pass, insert one route+activity via `generateOneWalk`.
|
* daily cap; on pass, insert one route+activity via `generateOneWalk`.
|
||||||
*/
|
*/
|
||||||
export const demoBotGenerateJob: JobDefinition = {
|
export const demoBotGenerateJob: JobDefinition = {
|
||||||
name: "demo-bot:generate",
|
name: "demo-bot:generate",
|
||||||
cron: "*/90 * * * *",
|
cron: "0,30 * * * *",
|
||||||
retryLimit: 1,
|
retryLimit: 1,
|
||||||
expireInSeconds: 120,
|
expireInSeconds: 120,
|
||||||
async handler() {
|
async handler() {
|
||||||
|
|
|
||||||
|
|
@ -640,13 +640,18 @@ export function berlinHour(now: Date): number {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The decide-to-walk gate: only within 07–21 local, Bernoulli p=0.12.
|
* The decide-to-walk gate: only within 07–21 local, Bernoulli p=0.09.
|
||||||
* Factored out so tests can replace `Math.random` / `now`.
|
* Factored out so tests can replace `Math.random` / `now`.
|
||||||
|
*
|
||||||
|
* Cadence math: the job ticks every 30 min, so the 14-hour daytime
|
||||||
|
* window (07:00–21:00 Berlin) covers 28 ticks/day. With p=0.09 the
|
||||||
|
* expected walks/day ≈ 28 * 0.09 ≈ 2.52, which lands in the target
|
||||||
|
* 2–3 walks/day band.
|
||||||
*/
|
*/
|
||||||
export function shouldWalkNow(now: Date, rand: () => number = Math.random): boolean {
|
export function shouldWalkNow(now: Date, rand: () => number = Math.random): boolean {
|
||||||
const hour = berlinHour(now);
|
const hour = berlinHour(now);
|
||||||
if (hour < 7 || hour >= 21) return false;
|
if (hour < 7 || hour >= 21) return false;
|
||||||
return rand() < 0.12;
|
return rand() < 0.09;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEMO_DAILY_CAP = 40;
|
export const DEMO_DAILY_CAP = 40;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue