add rate limit handling to trigger and action execution#41
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds configurable rate limit delays to trigger and action executions by reading rateLimit from cfg.nodeSettings and awaiting before proceeding.
- Introduces a wait after each API call in
trigger.jsandaction.js - Defaults the delay to 1700 ms if no valid
rateLimitis provided
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| templates/lib/triggers/trigger.js | Added a delay block after executeCall using rateLimit |
| templates/lib/actions/action.js | Added a delay block after executeCall using rateLimit |
| const { body, headers } = await executeCall.call(this, callParams); | ||
|
|
||
| // Wait for rate limit if specified | ||
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 1700; |
There was a problem hiding this comment.
Specify the radix when using parseInt (e.g., parseInt(cfg.nodeSettings.rateLimit, 10)) to avoid unexpected behavior with leading zeros.
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 1700; | |
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit, 10) : 1700; |
| const resp = await executeCall.call(this, callParams); | ||
|
|
||
| // Wait for rate limit if specified | ||
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 1700; |
There was a problem hiding this comment.
Add a radix parameter to parseInt (e.g., parseInt(cfg.nodeSettings.rateLimit, 10)) for consistent parsing across environments.
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 1700; | |
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit, 10) : 1700; |
| do { | ||
| const { body, headers } = await executeCall.call(this, callParams); | ||
|
|
||
| // Wait for rate limit if specified |
There was a problem hiding this comment.
The rate-limit logic is duplicated in both trigger and action modules; consider extracting it into a shared helper function to reduce code repetition.
| // Wait for rate limit if specified | ||
| const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 1700; | ||
| if (rateLimit > 0) { | ||
| this.logger.info(`Waiting for rate limit: ${rateLimit} ms`); |
There was a problem hiding this comment.
[nitpick] Rate-limit logs can be verbose at info level; consider using debug or a lower verbosity level to prevent log noise in production.
| this.logger.info(`Waiting for rate limit: ${rateLimit} ms`); | |
| this.logger.debug(`Waiting for rate limit: ${rateLimit} ms`); |
No description provided.