frappe-agent-architect
Use when designing multi-app Frappe architectures, deciding whether to split functionality into separate apps, or implementing cross-app communication…
Use when implementing scheduled tasks and background jobs in Frappe v14/v15/v16. Covers hooks.py scheduler_events, frappe.enqueue, queue selection, job deduplication, testing with bench execute/scheduler, monitoring via Scheduled Job Log and RQ Dashboard, error handling,
$ npx -y skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-impl-scheduler --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/frappe-impl-schedulerContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when implementing scheduled tasks and background jobs in Frappe v14/v15/v16. Covers hooks.py scheduler_events, frappe.enqueue, queue selection, job deduplication, testing with bench execute/scheduler, monitoring via Scheduled Job Log and RQ Dashboard, error handling,
name: frappe-impl-scheduler description: > Use when implementing scheduled tasks and background jobs in Frappe v14/v15/v16. Covers hooks.py scheduler_events, frappe.enqueue, queue selection, job deduplication, testing with bench execute/scheduler, monitoring via Scheduled Job Log and RQ Dashboard, error handling, long-running job patterns, email digest, data cleanup, and report generation. Keywords: schedule task, background job, cron job, async processing, queue selection, job deduplication, scheduler implementation, run task automatically, background process, scheduled task not running, async task. license: MIT compatibility: "Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16." metadata: author: OpenAEC-Foundation version: "2.0"
Workflow for implementing scheduled tasks and background jobs. For exact syntax, see `frappe-syntax-scheduler`.
**Version**: v14/v15/v16 compatible
---
WHAT ARE YOU BUILDING? | +-- Runs at fixed intervals/times? | +-- YES --> scheduler_events (hooks.py) | | Task receives NO arguments | | See: Workflow 1-2 | | | +-- NO --> Triggered by user action or code? | +-- YES --> frappe.enqueue() | | Pass any serializable data | | See: Workflow 3-4 | | | +-- NO --> Reconsider requirements
| Aspect | scheduler_events | frappe.enqueue | |--------|------------------|----------------| | Triggered by | Time/interval | Code execution | | Defined in | hooks.py | Python code | | Arguments | NONE (must be parameterless) | Any serializable data | | Use case | Daily cleanup, hourly sync | User-triggered long task | | Queue control | Event suffix (_long) | queue= parameter | | Restart behavior | Runs on schedule | Lost if worker restarts |
---
| Need | Event Key | Queue | |------|-----------|-------| | Every scheduler tick | `all` | short (NEVER >60s) | | Hourly (<5 min) | `hourly` | short | | Hourly (5-25 min) | `hourly_long` | long | | Daily (<5 min) | `daily` | short | | Daily (5-25 min) | `daily_long` | long | | Weekly (<5 min) | `weekly` | short | | Weekly (5-25 min) | `weekly_long` | long | | Monthly (<5 min) | `monthly` | short | | Monthly (5-25 min) | `monthly_long` | long | | Custom schedule | `cron["expr"]` | short |
**Rule**: ALWAYS use `*_long` suffix for tasks exceeding 5 minutes.
---
| Queue | Default Timeout | Use For | |-------|-----------------|---------| | `short` | 300s (5 min) | Quick operations (<1 min) | | `default` | 300s (5 min) | Standard tasks (1-5 min) | | `long` | 1500s (25 min) | Heavy processing (>5 min) |
**Rule**: ALWAYS specify `queue=` explicitly. NEVER rely on the default.
---
# myapp/tasks.py
import frappe
def daily_cleanup():
"""Daily cleanup - NO parameters allowed."""
cutoff = frappe.utils.add_days(frappe.utils.nowdate(), -30)
frappe.db.delete("Error Log", {"creation": ("<", cutoff)})
frappe.db.commit()# hooks.py
scheduler_events = {
"daily": ["myapp.tasks.daily_cleanup"]
}**After editing hooks.py**: ALWAYS run `bench migrate`.
---
# myapp/api.py
import frappe
from frappe.utils.background_jobs import is_job_enqueued
@frappe.whitelist()
def process_documents(doctype, filters):
job_id = f"process_{doctype}_{frappe.session.user}"
if is_job_enqueued(job_id):
return {"message": "Already in progress"}
frappe.enqueue(
"myapp.tasks.process_batch",
queue="long",
timeout=1800,
job_id=job_id,
enqueue_after_commit=True,
doctype=doctype,
filters=filters
)
return {"status": "queued"}---
# Run the function directly (no queue involved) bench --site mysite execute myapp.tasks.daily_cleanup
# Check scheduler status bench --site mysite scheduler status # Enable scheduler bench --site mysite scheduler enable # Trigger all pending scheduler events NOW bench --site mysite scheduler trigger # Run specific event type bench --site mysite execute frappe.utils.scheduler.trigger --args "['daily']"
bench --site mysite console
>>> frappe.enqueue("myapp.tasks.my_task", queue="short", now=True)
# now=True executes synchronously for testing1. Go to: Setup > Scheduled Job Type 2. Find: myapp.tasks.daily_cleanup 3. Verify: Frequency correct, Stopped = No 4. Click "Run Now" to trigger manually
---
Setup > Scheduled Job Log - Shows every scheduler run with status - Filter by: status (Success/Failed), creation date - Check execution time to detect slow tasks
# Start RQ monitor (development) bench --site mysite rq-dashboard # Opens at http://localhost:9181 # Show background job status bench --site mysite show-pending-jobs bench --site mysite show-failed-jobs
def scheduler_health_check():
failed = frappe.db.count("Scheduled Job Log", {
"status": "Failed",
"creation": [">=", frappe.utils.add_to_date(None, hours=-1)]
})
if failed > 5:
frappe.sendmail(
recipients=["admin@example.com"],
subject="Scheduler Alert: Many failures",
message=f"{failed} scheduler jobs failed in last hour"
)---
def sync_all_orders():
orders = get_pending_orders()
success, er60 deterministic Claude AI skills for Frappe Framework & ERPNext v14-v16 development and operations
Repo: Impertio-Studio/Frappe_Claude_Skill_Package
Use when designing multi-app Frappe architectures, deciding whether to split functionality into separate apps, or implementing cross-app communication…
Use when debugging Frappe errors, using bench console for live inspection, analyzing tracebacks, or reading Frappe log files. Prevents wasted debugging time…
Use when receiving vague or unclear ERPNext/Frappe development requests that need interpretation. Transforms requirements like 'make invoice auto-calculate' or…
Use when migrating a Frappe app between major versions, detecting breaking API changes, or resolving post-migration errors. Prevents failed migrations from…
Use when reviewing or validating Frappe/ERPNext code against best practices and common pitfalls. Checks generated code before deployment, validates against all…
Use when building ERPNext/Frappe API integrations (v14/v15/v16) including REST API, RPC API, authentication, webhooks, and rate limiting. Covers external API…