Skip to content

Commit 71c8a76

Browse files
committed
feat: update cron handling for decay and content jobs
1 parent e0164a1 commit 71c8a76

6 files changed

Lines changed: 25 additions & 18 deletions

File tree

backend/.env.example

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ FELT_ROLE_ID=your_felt_role_id
1616
# Database (PostgreSQL connection string)
1717
DATABASE_URL=postgres://user:password@localhost:5432/daimyo
1818

19-
# Reputation Thresholds
19+
# Decay Check
20+
# Cron schedule (optional - if not set, job won't run automatically)
21+
# Example: 1st of month at midnight UTC
22+
DECAY_CHECK_CRON=0 0 1 * *
2023
DECAY_WINDOW_DAYS=360
2124
SENPAI_REACTION_THRESHOLD=50
2225
SENPAI_UNIQUE_PERCENT=0.10
@@ -27,13 +30,14 @@ SENSEI_UNIQUE_PERCENT=0.20
2730
OHAYO_CHANNEL_ID=your_ohayo_channel_id
2831

2932
# Content Pipeline Configuration
33+
# Cron schedule (optional - if not set, job won't run automatically)
34+
# Example: Sunday midnight UTC
35+
CONTENT_PIPELINE_CRON=0 0 * * 0
3036
# How many days back to scan for messages
3137
CONTENT_PIPELINE_DAYS_BACK=7
3238
# Target number of stories per run
3339
CONTENT_PIPELINE_MIN_STORIES=3
3440
CONTENT_PIPELINE_MAX_STORIES=10
35-
# Cron schedule (default: Sunday 9am UTC)
36-
CONTENT_PIPELINE_CRON=0 9 * * 0
3741

3842
# AI Configuration
3943
LLM_MODEL=claude-sonnet-4-20250514

backend/src/jobs/contentPipeline.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,15 @@ async function runContentPipeline(client: Client, dryRun = false): Promise<void>
154154

155155
/**
156156
* Schedule and start the content pipeline cron job
157-
* Default: Runs weekly on Sunday at 09:00 UTC
158157
*/
159158
export function startContentPipelineJob(client: Client): void {
160159
const cronSchedule = config.contentPipelineCron;
160+
161+
if (!cronSchedule) {
162+
console.log('⏰ Content pipeline not scheduled (CONTENT_PIPELINE_CRON not set)');
163+
return;
164+
}
165+
161166
console.log(`⏰ Scheduling content pipeline: ${cronSchedule}`);
162167

163168
cron.schedule(cronSchedule, () => {

backend/src/jobs/decayCheck.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,18 @@ async function runDecayCheck(client: Client): Promise<void> {
5858

5959
/**
6060
* Schedule and start the decay check cron job
61-
* Runs monthly at 12:00 UTC on the 1st (0 12 1 * *)
62-
* Set DECAY_CHECK_ENABLED=true to enable
6361
*/
6462
export function startDecayCheckJob(client: Client): void {
65-
const enabled = process.env.DECAY_CHECK_ENABLED === 'true';
63+
const cronSchedule = config.decayCheckCron;
6664

67-
if (!enabled) {
68-
console.log('⏰ Decay check job disabled (set DECAY_CHECK_ENABLED=true to enable)');
65+
if (!cronSchedule) {
66+
console.log('⏰ Decay check not scheduled (DECAY_CHECK_CRON not set)');
6967
return;
7068
}
7169

72-
console.log('⏰ Scheduling monthly decay check for 12:00 UTC on the 1st (0 12 1 * *)');
70+
console.log(`⏰ Scheduling decay check: ${cronSchedule}`);
7371

74-
// Schedule: minute hour day month dayOfWeek
75-
// 0 12 1 * * = 12:00 UTC on the 1st of every month
76-
cron.schedule('0 12 1 * *', () => {
72+
cron.schedule(cronSchedule, () => {
7773
runDecayCheck(client);
7874
});
7975

backend/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export interface Config {
5959
// Database
6060
databaseUrl: string;
6161

62-
// Thresholds
62+
// Decay
63+
decayCheckCron: string;
6364
decayWindowDays: number;
6465
senpaiReactionThreshold: number;
6566
senpaiUniquePercent: number;

backend/src/utils/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export function loadConfig(): Config {
6363
// Database
6464
databaseUrl: getRequiredEnv('DATABASE_URL'),
6565

66-
// Thresholds
66+
// Decay
67+
decayCheckCron: process.env.DECAY_CHECK_CRON || '',
6768
decayWindowDays: getNumberEnv('DECAY_WINDOW_DAYS', 360),
6869
senpaiReactionThreshold: getNumberEnv('SENPAI_REACTION_THRESHOLD', 50),
6970
senpaiUniquePercent: getNumberEnv('SENPAI_UNIQUE_PERCENT', 0.1),
@@ -78,7 +79,7 @@ export function loadConfig(): Config {
7879
contentPipelineDaysBack: getNumberEnv('CONTENT_PIPELINE_DAYS_BACK', 7),
7980
contentPipelineMinStories: getNumberEnv('CONTENT_PIPELINE_MIN_STORIES', 3),
8081
contentPipelineMaxStories: getNumberEnv('CONTENT_PIPELINE_MAX_STORIES', 10),
81-
contentPipelineCron: process.env.CONTENT_PIPELINE_CRON || '0 9 * * 0',
82+
contentPipelineCron: process.env.CONTENT_PIPELINE_CRON || '',
8283

8384
// AI Configuration
8485
llmModel: process.env.LLM_MODEL || 'claude-sonnet-4-20250514',

spec/CONTENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ CONTENT_PIPELINE_DAYS_BACK=7
7070
CONTENT_PIPELINE_MIN_STORIES=3
7171
CONTENT_PIPELINE_MAX_STORIES=10
7272

73-
# Cron schedule (default: Sunday 9am UTC)
74-
CONTENT_PIPELINE_CRON=0 9 * * 0
73+
# Cron schedule (optional - if not set, job won't run automatically)
74+
CONTENT_PIPELINE_CRON=0 0 * * 0
7575

7676
# AI (uses Claude Sonnet 4 via Anthropic)
7777
LLM_MODEL=claude-sonnet-4-20250514

0 commit comments

Comments
 (0)