Skip to content

Commit b5e7e42

Browse files
committed
Add Task Manager worker for auto GitHub issue creation
Introduces a new worker at workers/task-manager that automatically creates GitHub issues for events meeting a threshold, with daily rate limiting and atomic usage tracking. Includes environment setup, documentation, and updates @hawk.so/types to v0.5.3.
1 parent 2cb3e5b commit b5e7e42

8 files changed

Lines changed: 499 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@babel/parser": "^7.26.9",
5454
"@babel/traverse": "7.26.9",
5555
"@hawk.so/nodejs": "^3.1.1",
56-
"@hawk.so/types": "^0.2.0",
56+
"@hawk.so/types": "^0.5.3",
5757
"@types/amqplib": "^0.8.2",
5858
"@types/jest": "^29.2.3",
5959
"@types/mongodb": "^3.5.15",

workers/task-manager/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Maximum number of auto-created tasks per project per day
2+
# Default: 10
3+
MAX_AUTO_TASKS_PER_DAY=10
4+
5+
# Number of tasks handling simultaneously
6+
# Default: 1
7+
SIMULTANEOUS_TASKS=1

workers/task-manager/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Task Manager Worker
2+
3+
Worker for automatically creating GitHub issues for errors that meet the threshold.
4+
5+
## Description
6+
7+
This worker processes tasks to automatically create GitHub issues for events that:
8+
- Have `totalCount >= taskThresholdTotalCount`
9+
- Don't have a `taskManagerItem` (not yet processed)
10+
- Occurred after `taskManager.connectedAt`
11+
12+
## Rate Limiting
13+
14+
The worker implements daily rate limiting:
15+
- Maximum `MAX_AUTO_TASKS_PER_DAY` (default: 10) tasks per project per day
16+
- Uses atomic increment to prevent race conditions
17+
- Resets daily budget at the start of each UTC day
18+
19+
## Environment Variables
20+
21+
- `REGISTRY_URL` - RabbitMQ registry connection URL
22+
- `MAX_AUTO_TASKS_PER_DAY` - Maximum auto tasks per day (default: 10)
23+
24+
## Usage
25+
26+
The worker is triggered by cron tasks with routing key `cron-tasks/task-manager` and payload:
27+
```json
28+
{
29+
"type": "auto-task-creation"
30+
}
31+
```

workers/task-manager/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "hawk-worker-task-manager",
3+
"version": "1.0.0",
4+
"main": "src/index.ts",
5+
"license": "MIT",
6+
"workerType": "hawk-worker-task-manager"
7+
}

workers/task-manager/src/env.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as path from 'path';
2+
import * as dotenv from 'dotenv';
3+
4+
/**
5+
* Load environment variables from .env file
6+
*/
7+
dotenv.config({ path: path.resolve(__dirname, '../.env') });

0 commit comments

Comments
 (0)