Add cron scheduler and heartbeat runner#42
Open
danbao wants to merge 2 commits intofastclaw-ai:mainfrom
Open
Conversation
- messaging/cron.go: CronScheduler with tick loop, robfig/cron parser - messaging/cron_store.go: JSON persistence at ~/.weclaw/cron/jobs.json - messaging/cron_commands.go: /cron add/list/delete/enable/disable commands - messaging/heartbeat.go: HeartbeatRunner with active hours, dedup, HEARTBEAT_OK suppression - config/config.go: HeartbeatConfig with target_user for iLink - cmd/start.go: start scheduler + heartbeat using first account client - messaging/handler.go: /cron routing, SetCronStore, exported GetDefaultAgent/GetAgent - 30+ tests, all passing with race detector - Updated both READMEs with Cron and Heartbeat sections Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- P1: Record userID on new cron jobs so results go to originating user - P1: Prevent concurrent duplicate execution with running map + pre-advance NextRunAt - P2: Reject non-positive heartbeat interval (prevents panic from time.NewTicker) - P2: Retry one-shot cron jobs when agent not ready instead of permanently disabling Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add two automation features: Cron Scheduler and Heartbeat Runner.
Cron Scheduler
Schedule recurring or one-shot tasks via chat commands:
every:5m), and one-shot (at:...)~/.weclaw/cron/jobs.jsonrobfig/cron/v3for expression parsingHeartbeat Runner
Periodic agent check-in driven by
~/.weclaw/HEARTBEAT.md:HEARTBEAT_OKrepliesConfig
{ "heartbeat": { "enabled": true, "interval": "30m", "active_hours": "09:00-18:00", "timezone": "Asia/Shanghai", "target_user": "wechat_user_id" } }Changes
messaging/cron.go— CronScheduler with tick loopmessaging/cron_store.go— JSON persistencemessaging/cron_commands.go—/cronchat command parsermessaging/heartbeat.go— HeartbeatRunnerconfig/config.go— HeartbeatConfig typecmd/start.go— Start scheduler + heartbeat using first account's clientmessaging/handler.go—/cronrouting, exported GetDefaultAgent/GetAgent-race