Creating triggers
Guide to Contributing Triggers in Nanoservice-ts
Triggers in nanoservice-ts
allow workflows to be executed automatically in response to specific events. This guide provides an overview of how to create, test, and contribute new triggers to the framework.
What Are Triggers?
Triggers define when and how a workflow starts. They listen for external or internal events, such as:
- HTTP Requests (e.g., API calls)
- Scheduled Events (e.g., cron jobs)
- Database Changes (e.g., new records in Postgres)
- Queue Messages (e.g., Kafka, RabbitMQ events)
- Custom Events (e.g., user-defined triggers)
Triggers are stored in the /triggers
directory and are configurable via CLI.
Getting Started
Clone the repository and navigate to the triggers
directory:
Adding a New Trigger
- Create a new directory in
/triggers
- Use
http-trigger
as a template or build your own - Make sure you are using the TriggerBase class as the base class
- Document your code, create interface definitions, and make sure you follow ESlint rules
- Make sure you have tests for your trigger and you achieve full coverage after running
pnpm test
Submitting a Pull Request
- Follow Branch Naming Convention
- Ensure Code Quality
- Submit a PR with:
- A clear description of the trigger.
- Tests and configuration examples.
- Proper documentation updates.
Best Practices
✅ Keep triggers modular and lightweight.
✅ Ensure proper error handling and logging.
✅ Write clear documentation and tests.
✅ Follow the project’s TypeScript style guide.
Final Notes
Triggers are a key part of automation in nanoservice-ts. By contributing new triggers, you help expand the framework’s capabilities and enable more use cases. If you have any questions, open an issue or join the discussion! 🚀