diff --git a/.planning/REQUIREMENTS.md b/.planning/REQUIREMENTS.md index 8252aa2..07c7a19 100644 --- a/.planning/REQUIREMENTS.md +++ b/.planning/REQUIREMENTS.md @@ -242,7 +242,7 @@ Requirements for initial release. Each maps to roadmap phases. ### Scheduled Scanning -- [ ] **SCHED-01**: Cron-based recurring scan scheduling +- [x] **SCHED-01**: Cron-based recurring scan scheduling - [ ] **SCHED-02**: keyhunter schedule add/list/remove commands - [ ] **SCHED-03**: Auto-notify on scheduled scan completion diff --git a/.planning/STATE.md b/.planning/STATE.md index 1da07ac..054bd87 100644 --- a/.planning/STATE.md +++ b/.planning/STATE.md @@ -3,14 +3,14 @@ gsd_state_version: 1.0 milestone: v1.0 milestone_name: milestone status: executing -stopped_at: Completed 16-01-PLAN.md -last_updated: "2026-04-06T13:48:35.313Z" +stopped_at: Completed 17-02-PLAN.md +last_updated: "2026-04-06T14:28:16.926Z" last_activity: 2026-04-06 progress: total_phases: 18 completed_phases: 14 total_plans: 85 - completed_plans: 83 + completed_plans: 84 percent: 20 --- @@ -26,8 +26,8 @@ See: .planning/PROJECT.md (updated 2026-04-04) ## Current Position Phase: 17 -Plan: Not started -Status: Ready to execute +Plan: 2 of 5 +Status: executing Last activity: 2026-04-06 Progress: [██░░░░░░░░] 20% @@ -100,6 +100,7 @@ Progress: [██░░░░░░░░] 20% | Phase 15 P01 | 3min | 2 tasks | 13 files | | Phase 15 P03 | 4min | 2 tasks | 11 files | | Phase 16 P01 | 4min | 2 tasks | 6 files | +| Phase 17 P02 | 2min | 2 tasks | 8 files | ## Accumulated Context @@ -152,6 +153,7 @@ Recent decisions affecting current work: - [Phase 16]: VT uses x-apikey header per official API v3 spec - [Phase 16]: IX uses three-step flow: POST search, GET results, GET file content - [Phase 16]: URLhaus tag lookup with payload endpoint fallback +- [Phase 17]: Scheduler.ScanFunc callback decouples from engine; OnComplete bridges to notifications; disabled jobs stay in DB ### Pending Todos @@ -166,6 +168,6 @@ None yet. ## Session Continuity -Last session: 2026-04-06T13:46:09.383Z -Stopped at: Completed 16-01-PLAN.md +Last session: 2026-04-06T14:28:16.922Z +Stopped at: Completed 17-02-PLAN.md Resume file: None diff --git a/.planning/phases/17-telegram-scheduler/17-02-SUMMARY.md b/.planning/phases/17-telegram-scheduler/17-02-SUMMARY.md new file mode 100644 index 0000000..da13dfb --- /dev/null +++ b/.planning/phases/17-telegram-scheduler/17-02-SUMMARY.md @@ -0,0 +1,105 @@ +--- +phase: 17-telegram-scheduler +plan: 02 +subsystem: scheduler +tags: [gocron, sqlite, cron, scheduler, telegram] + +requires: + - phase: 01-foundation + provides: pkg/storage DB wrapper with schema.sql embed pattern +provides: + - pkg/scheduler/ package with gocron wrapper, start/stop lifecycle + - Storage CRUD for subscribers table (Add/Remove/List/IsSubscribed) + - Storage CRUD for scheduled_jobs table (Save/List/Get/Delete/UpdateLastRun/SetEnabled) + - subscribers and scheduled_jobs SQLite tables in schema.sql +affects: [17-telegram-scheduler, 17-03, 17-04, 17-05] + +tech-stack: + added: [gocron/v2 v2.19.1] + patterns: [scheduler wraps gocron with DB persistence, ScanFunc abstraction decouples from engine] + +key-files: + created: + - pkg/scheduler/scheduler.go + - pkg/scheduler/jobs.go + - pkg/scheduler/scheduler_test.go + - pkg/storage/subscribers.go + - pkg/storage/scheduled_jobs.go + modified: + - pkg/storage/schema.sql + - go.mod + - go.sum + +key-decisions: + - "Scheduler.ScanFunc callback decouples from engine -- Plan 17-04 wires the real scan logic" + - "OnComplete callback bridges scheduler to notification system without direct bot dependency" + - "Disabled jobs skipped during Start() but remain in DB for re-enabling" + +patterns-established: + - "Scheduler pattern: gocron wrapper with DB persistence and callback-based extensibility" + +requirements-completed: [SCHED-01] + +duration: 2min +completed: 2026-04-06 +--- + +# Phase 17 Plan 02: Scheduler + Storage Summary + +**gocron v2.19.1 wrapper with SQLite persistence for subscribers and scheduled scan jobs, callback-based scan/notify extensibility** + +## Performance + +- **Duration:** 2 min +- **Started:** 2026-04-06T14:25:04Z +- **Completed:** 2026-04-06T14:27:08Z +- **Tasks:** 2 +- **Files modified:** 8 + +## Accomplishments +- Created pkg/scheduler/ package wrapping gocron with Start/Stop lifecycle and DB-backed job persistence +- Implemented full CRUD for subscribers (Add/Remove/List/IsSubscribed) and scheduled_jobs (Save/List/Get/Delete/UpdateLastRun/SetEnabled) +- Added subscribers and scheduled_jobs tables to schema.sql +- All 5 tests pass: storage round-trip, subscriber round-trip, scheduler start/add/remove/run + +## Task Commits + +Each task was committed atomically: + +1. **Task 1: Add gocron dependency, create storage tables, and subscriber/job CRUD** - `c8f7592` (feat) +2. **Task 2 RED: Failing tests for scheduler package** - `89cc133` (test) +3. **Task 2 GREEN: Implement scheduler package** - `c71faa9` (feat) + +## Files Created/Modified +- `pkg/scheduler/scheduler.go` - Scheduler struct wrapping gocron with Start/Stop/AddJob/RemoveJob/RunJob/ListJobs +- `pkg/scheduler/jobs.go` - Job and JobResult types +- `pkg/scheduler/scheduler_test.go` - 5 tests covering storage, subscriber, and scheduler lifecycle +- `pkg/storage/subscribers.go` - Subscriber struct and CRUD methods on DB +- `pkg/storage/scheduled_jobs.go` - ScheduledJob struct and CRUD methods on DB +- `pkg/storage/schema.sql` - subscribers and scheduled_jobs CREATE TABLE statements +- `go.mod` - gocron/v2 v2.19.1 promoted to direct dependency +- `go.sum` - Updated checksums + +## Decisions Made +- ScanFunc callback decouples scheduler from engine -- Plan 17-04 wires real scan logic +- OnComplete callback bridges scheduler to notification system without direct bot dependency +- Disabled jobs skipped during Start() but remain in DB for re-enabling via SetJobEnabled + +## Deviations from Plan + +None - plan executed exactly as written. + +## Issues Encountered +None + +## User Setup Required +None - no external service configuration required. + +## Next Phase Readiness +- pkg/scheduler/ ready for CLI wiring in Plan 17-03 (schedule add/list/remove commands) +- Subscriber storage ready for bot /subscribe handler in Plan 17-01 +- OnComplete callback ready for notification bridge in Plan 17-04 + +--- +*Phase: 17-telegram-scheduler* +*Completed: 2026-04-06*