magento-events-cron
Implement Magento 2 events, observers, cron jobs, and message queues. Use when building event-driven logic, scheduled tasks, or asynchronous processing.
Best use case
magento-events-cron is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Implement Magento 2 events, observers, cron jobs, and message queues. Use when building event-driven logic, scheduled tasks, or asynchronous processing.
Teams using magento-events-cron should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/magento-events-cron/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How magento-events-cron Compares
| Feature / Agent | magento-events-cron | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Implement Magento 2 events, observers, cron jobs, and message queues. Use when building event-driven logic, scheduled tasks, or asynchronous processing.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Magento 2 Events, Observers, Cron & Message Queues
## Before writing code
**Fetch live docs**:
1. Fetch `https://developer.adobe.com/commerce/php/development/components/events-and-observers/` for events/observers guide
2. Web-search `site:developer.adobe.com commerce php development components message-queues` for message queue guide
3. Web-search `site:developer.adobe.com commerce php development components cron` for cron development
## Events and Observers
### How Events Work
Publish-subscribe pattern: code dispatches named events, and observers respond.
### Dispatching Events
```php
$this->eventManager->dispatch('event_name', ['key' => $value]);
```
`EventManagerInterface` is injected via constructor.
### Observer Configuration (events.xml)
Observers are bound to events in `etc/events.xml` (global), `etc/frontend/events.xml`, or `etc/adminhtml/events.xml`:
- `event name` — event to observe
- `observer name` — unique identifier
- `instance` — observer class (fully qualified)
### Observer Classes
- Located in `Observer/` directory
- Implement `Magento\Framework\Event\ObserverInterface`
- Single method: `execute(Observer $observer)` — access event data via `$observer->getEvent()`
### Area Scoping
- `etc/events.xml` — runs in ALL areas
- `etc/frontend/events.xml` — storefront only
- `etc/adminhtml/events.xml` — admin only
- Use the most specific scope to avoid unintended side effects
### Common Events
Magento dispatches hundreds of events. Common categories:
- `catalog_product_save_before/after` — product save lifecycle
- `checkout_submit_all_after` — order placement
- `customer_register_success` — customer registration
- `sales_order_place_after` — order placed
- `controller_action_predispatch/postdispatch` — request lifecycle
## Cron Jobs
### Configuration (crontab.xml)
Cron jobs are declared in `etc/crontab.xml`:
- `job name` — unique identifier
- `instance` — class name
- `method` — method to call (usually `execute`)
- `schedule` — cron expression (minute hour day month weekday)
- `group` — cron group (default, index; Adobe Commerce also has staging, catalog_event)
### Cron Class
Any class with an `execute()` method. No interface required. Constructor injection for dependencies.
### Cron Groups
- **default** — general tasks
- **index** — indexer-related tasks
- **staging** — staging-related tasks (Adobe Commerce only)
- **catalog_event** — catalog event tasks (Adobe Commerce only)
- Custom groups configurable in `etc/cron_groups.xml`
### Running Cron
```bash
bin/magento cron:run # Run all due cron jobs
bin/magento cron:install # Install system crontab entry
```
## Message Queues
### When to Use
For asynchronous, resource-intensive, or decoupled operations. Supports AMQP (RabbitMQ) and MySQL-based queues.
### Configuration Files
- `communication.xml` — defines topics and request/response types
- `queue_consumer.xml` — maps queues to consumer handler classes
- `queue_topology.xml` — exchanges, queues, routing
- `queue_publisher.xml` — defines where topics publish to
### Consumer Pattern
Consumer class with a `process($message)` method. Started via:
```bash
bin/magento queue:consumers:start <consumer_name>
```
## Best Practices
- Keep observers lightweight — offload heavy work to cron or queues
- Use area-specific events.xml to minimize scope
- Prefer message queues over synchronous observers for slow operations
- Use `index` cron group for indexer-related jobs
- Log cron execution for debugging
- Handle exceptions in observers gracefully — a failing observer blocks the event chain
Fetch the events/observers and cron documentation for exact XML schemas, event names, and cron expression syntax before implementing.Related Skills
spree-events-webhooks
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
magento-testing
Write tests for Magento 2 — PHPUnit unit tests, integration tests, MFTF functional tests, and API tests. Use when implementing test coverage for modules, debugging, or setting up CI/CD test pipelines.
magento-setup
Set up a Magento 2 Open Source project — installation, Composer setup, system requirements verification, and initial configuration. Use when starting a new Magento project or setting up a development environment.
magento-service-contracts
Implement Magento 2 service contracts — repository interfaces, data interfaces, SearchCriteria, and the repository pattern. Use when building module APIs, data access layers, or integrating with Magento's Web API.
magento-security
Implement Magento 2 security — CSP, 2FA, CSRF protection, ACL, admin security configuration, input validation, and security best practices. Use when hardening a Magento installation or reviewing security posture.
magento-plugins-interceptors
Implement Magento 2 plugins (interceptors) — before, after, and around methods for modifying class behavior without inheritance. Use when extending core or third-party module functionality.
magento-performance
Optimize Magento 2 performance — full page cache (Varnish), Redis, indexer tuning, JavaScript/CSS optimization, database optimization, and profiling. Use when diagnosing slow pages, optimizing load times, or configuring caching.
magento-module-dev
Create Magento 2 custom modules — registration, directory structure, models, resource models, collections, declarative schema, and data/schema patches. Use when building new modules or understanding module architecture.
magento-frontend
Build Magento 2 frontend — layout XML, blocks, PHTML templates, ViewModels, themes, JavaScript (RequireJS/KnockoutJS), and LESS/CSS. Use when customizing the storefront, building themes, or working with frontend components.
magento-eav-attributes
Work with Magento 2 EAV (Entity-Attribute-Value) system — create custom attributes, attribute sets, manage EAV tables, and understand the EAV data model. Use when adding product/category/customer attributes or working with the attribute system.
magento-di
Configure Magento 2 dependency injection — di.xml, types, virtual types, preferences, argument replacement, and Object Manager. Use when wiring dependencies, creating class variations, or configuring module integrations.
magento-deploy
Deploy Magento 2 — deployment modes, static content deployment, DI compilation, CLI commands, zero-downtime strategies, and CI/CD pipeline setup. Use when preparing for production deployment or building deployment automation.