agentcron
v0.0.1
Published
Cron scheduling module using BullMQ with user-specific task handling
Maintainers
Readme
agentcron
AgentCron is a TypeScript-based task scheduling module built on top of BullMQ. It allows you to schedule, update, list, and delete tasks for individual users with ease.
✨ Features
- Add tasks with JSON payloads for specific users
- Supports delayed and repeated tasks
- List all tasks per user
- Update task payload, delay, and priority
- Delete tasks by ID or by user
- Written in clean, typed TypeScript
- Built for reliability with production-ready practices
📦 Installation
pnpm add agentcron
# or
npm install agentcron
# or
yarn add agentcron🚀 Usage
import { TaskScheduler } from 'agentcron';
import IORedis from 'ioredis';
const redis = new IORedis();
const scheduler = new TaskScheduler(redis);
// Add a task
await scheduler.addTask({
userId: 'user-123',
payload: { type: 'email', message: 'Hello!' },
delay: 5000, // optional (ms)
repeat: 3, // optional, default = 1
});
// List tasks for a user
const tasks = await scheduler.listTasksByUser('user-123');
// Update a task
await scheduler.updateTask({
jobId: tasks[0].id!,
updates: {
payload: { type: 'notification' },
delay: 3000,
priority: 2,
},
});
// Delete a task by ID
await scheduler.deleteTaskById(tasks[0].id!);
// Delete all tasks for a user
await scheduler.deleteTasksByUser('user-123');
// Close queue when done
await scheduler.close();
await redis.quit();🧪 Running Tests
pnpm test
pnpm test:cov🧱 Project Structure
agentcron/
├── src/
│ └── scheduler.ts # Main module
├── test/
│ └── scheduler.test.ts # Tests
├── package.json
├── tsconfig.json
├── jest.config.cjs
└── README.md📜 License
This project is licensed under the Apache License 2.0.
🧠 Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
💬 Feedback
Open an issue or discussion on GitHub to share feedback, suggestions, or bugs.
Built with ❤️ for open source.
