Skip to content

feat(scheduler): add env_vars parameter for per-job environment overrides - #13

Merged
cagataycali merged 1 commit into
mainfrom
feat/scheduler-env-vars
Apr 28, 2026
Merged

feat(scheduler): add env_vars parameter for per-job environment overrides#13
cagataycali merged 1 commit into
mainfrom
feat/scheduler-env-vars

Conversation

@cagataycali

Copy link
Copy Markdown
Owner

Summary

Scheduled jobs can now inject arbitrary environment variables into the spawned DevDuck instance (e.g. TELEGRAM_BOT_TOKEN, API keys, feature flags).

Previously only model, tools, system_prompt, and max_tokens could be overridden per-job — anything else had to live in the global process env, which breaks when one scheduler runs jobs for different services.

Changes

  • New env_vars: Optional[Dict[str, str]] parameter on scheduler(action='add', ...)
  • Persisted to jobs.json → survives restarts
  • Applied via the existing _EnvOverride context manager → global env stays clean after the job completes
  • Docstring + status line updated

Example

scheduler(
    action="add",
    name="telegram-morning",
    schedule="0 9 * * *",
    prompt="send daily summary to chat",
    tools="telegram",
    env_vars={
        "TELEGRAM_BOT_TOKEN": "...",
        "TELEGRAM_CHAT_ID": "...",
    },
)

Each fired job will have those vars set for the duration of the spawned DevDuck session, then cleaned up.

Backwards compatibility

✅ Fully backwards compatible — env_vars defaults to None, existing jobs keep working. Old jobs.json entries without the field are handled via job.get("env_vars") or {}.

…ides

Scheduled jobs can now inject arbitrary environment variables into the
spawned DevDuck instance (e.g. TELEGRAM_BOT_TOKEN, API keys, feature flags).

env_vars are persisted to jobs.json so they survive restarts, and applied
via the existing _EnvOverride context manager so global state stays clean
after the job completes.

Example:
    scheduler(
        action='add',
        name='telegram-morning',
        schedule='0 9 * * *',
        prompt='send daily summary',
        tools='telegram',
        env_vars={'TELEGRAM_BOT_TOKEN': '...', 'TELEGRAM_CHAT_ID': '...'},
    )
@github-actions

Copy link
Copy Markdown

✅ Autonomous Review - LGTM

Analyzed the changes and they look excellent:

Strengths

  1. Clean API Design - env_vars: Optional[Dict[str, str]] = None parameter follows existing patterns
  2. Proper Integration - Uses existing _EnvOverride context manager → no env pollution
  3. Persistence - Stored in jobs.json → survives scheduler restarts
  4. Backwards Compatible - Defaults to None, handles via job.get("env_vars") or {}
  5. Well Documented - Clear examples in PR description + docstring updated

Implementation Quality

  • ✅ Minimal diff (13 additions, 1 deletion) - surgical change
  • ✅ Reuses existing infrastructure (_EnvOverride)
  • ✅ Follows type hints consistently
  • ✅ No breaking changes to existing jobs

Use Case Impact

Solves real problem: Multi-service schedulers can now inject credentials per-job without global env conflicts. Perfect for Telegram bots, API integrations, feature flags.

Recommendation

Merge-ready

The PR is mergeable, implementation is clean, and backwards compatibility is maintained. No blocking issues found.


Reviewed autonomously by DevDuck GitHub Agent

@cagataycali
cagataycali merged commit f5a27bd into main Apr 28, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

Merged successfully!

The scheduler now supports per-job environment variables via the new env_vars parameter. This enables isolated configuration for different scheduled tasks without polluting the global environment.

Key capabilities unlocked:

  • Telegram/Slack/WhatsApp bot tokens per scheduled job
  • API keys and secrets scoped to specific tasks
  • Feature flags and configuration overrides per job
  • Full backwards compatibility with existing jobs

Example usage:

scheduler(
    action="add",
    name="telegram-morning",
    schedule="0 9 * * *",
    prompt="send daily summary",
    tools="telegram",
    env_vars={
        "TELEGRAM_BOT_TOKEN": "...",
        "TELEGRAM_CHAT_ID": "..."
    }
)

Changes: 1 file modified (+13/-1)
Commit: f5a27bd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant