Jobs
Add scheduled tasks to your Magma agents
Overview
Jobs in Magma allow you to schedule recurring tasks for your agent to perform. Using the @job
decorator, you can define tasks that run on a specified schedule using cron syntax.
If a job is not declared as static, it will be scheduled to run on the agent’s instance, for every session of the agent. Learn more about sessions
Basic Implementation
Here’s a simple example of implementing a job:
Job Scheduling
Jobs use standard cron syntax for scheduling:
You can learn more about cron syntax here, and you can use the Cron Editor to help you create the correct syntax.
Advanced Job Configuration
Jobs can accept configuration options:
Static Jobs
Some jobs don’t need to access the agent’s context, and don’t need to be run on every session of the agent. You can declare them as static methods:
This job will be handled without instantiating the agent.
Common Use Cases
Data Synchronization
Maintenance Tasks
Report Generation
Agent completions
Use caution when using the main
method in a job. You should only use it if your agent will not be conducting conversations
Best Practices
-
Error Handling
-
Resource Management
- Consider server load during job scheduling
- Avoid overlapping job executions that modify the same resources
- Implement proper cleanup in case of failures
-
Monitoring
- Log job execution results
- Track execution time
- Monitor success/failure rates
Limitations
- Jobs must be async methods
- Maximum execution time is 5 minutes
- Timezone must be a valid IANA timezone string
For long-running tasks, consider breaking them into smaller sub-tasks or using a queue-based approach.