You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -198,9 +204,32 @@ When users perform inline searches, their queries hit this local copy instead of
198
204
199
205
The BullMQ-based approach makes this much more resilient than traditional cron scheduling. Check out [`src/workers/data-sync/`](../src/workers/data-sync/) for the implementation.
200
206
207
+
### Attachment Delivery Worker 📦
208
+
209
+
This worker handles file downloads and deliveries asynchronously, preventing the bot from being blocked by large file downloads. When users request attachments (calendars, timetables, announcements), the bot immediately queues the request and returns to serving other users. Here's how it works:
210
+
211
+
1.**Job Creation**: When a user requests files, the bot creates a job containing all attachment metadata and immediately returns
212
+
- Bot sends a friendly status message like _"⏳ Preparing your calendar... I'll send it shortly!"_
213
+
- The bot doesn't wait for downloads to complete
214
+
2.**Background Processing**: The worker picks up jobs from the queue and downloads all attachments
215
+
- Uses **all-or-nothing delivery** - if any file fails to download, nothing is sent to ensure users get complete data
216
+
- Downloads happen asynchronously without blocking other users
217
+
3.**Media Group Delivery**: Once all files are ready, sends them as media groups (batches of up to 10 files per Telegram API call)
218
+
- Much faster than individual file delivery
219
+
- Single caption listing all attachment names for clarity
220
+
4.**Graceful Error Handling**: Handles various failure scenarios without crashing
221
+
- If user blocks the bot, marks their chat as kicked and removes subscriptions
222
+
- If user deactivates account, cleans up their data from the database
223
+
- If rate limited by Telegram, pauses the entire queue for the specified duration, then resumes processing
224
+
5.**Status Updates**: Deletes the loading message once delivery is complete (or on failure)
225
+
- No chat pollution - the status message disappears after completion
226
+
- User receives their files cleanly without extra messages
227
+
228
+
This worker has a `concurrency` of `2` to prevent overwhelming Telegram's rate limits while still processing requests efficiently. All implementation lives in [`src/workers/attachment-delivery/`](../src/workers/attachment-delivery/)
229
+
201
230
## Health Checks and Monitoring
202
231
203
-
Each service exposes a health check endpoint (bot on port `3000`, workers on `3001-3003`) that verifies the service is running and can connect to its dependencies like the database and Redis. This enables zero-downtime deployments and automatic restarts if something goes wrong. The health check utility is in [`src/utils/healthCheck.ts`](../src/utils//healthCheck.ts) if you want to see how it works.
232
+
Each service exposes a health check endpoint (bot on port `3000`, workers on `3001-3004`) that verifies the service is running and can connect to its dependencies like the database and Redis. This enables zero-downtime deployments and automatic restarts if something goes wrong. The health check utility is in [`src/utils/healthCheck.ts`](../src/utils//healthCheck.ts) if you want to see how it works.
0 commit comments