Skip to content

Commit dc591d5

Browse files
Merge pull request #16 from stardothosting/issue-15
Issue 15
2 parents 96a98be + 3619a7f commit dc591d5

10 files changed

Lines changed: 404 additions & 87 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Services\AlertService;
6+
use Illuminate\Console\Command;
7+
8+
class TestTimeoutAlerts extends Command
9+
{
10+
protected $signature = 'test:timeout-alerts';
11+
protected $description = 'Test timeout and connectivity alerts';
12+
13+
public function handle(AlertService $alertService): int
14+
{
15+
$this->info('Testing timeout alerts...');
16+
17+
// Test API timeout alert
18+
$this->info('Sending API timeout alert...');
19+
$alertService->apiTimeout(
20+
'Unwrangle API',
21+
'B0D8L7K9QR',
22+
120,
23+
[
24+
'attempt' => 3,
25+
'max_pages' => 10,
26+
'error_details' => 'cURL error 28: Operation timed out after 120 seconds'
27+
]
28+
);
29+
30+
// Test connectivity issue alert
31+
$this->info('Sending connectivity issue alert...');
32+
$alertService->connectivityIssue(
33+
'Unwrangle API',
34+
'CONNECTION_TIMEOUT_NO_DATA',
35+
'cURL error 28: Operation timed out with 0 bytes received',
36+
[
37+
'asin' => 'B0D8L7K9QR',
38+
'attempt' => 2
39+
]
40+
);
41+
42+
$this->info('✅ Timeout alerts sent successfully!');
43+
$this->info('Check your Pushover app and logs for the alerts.');
44+
45+
return self::SUCCESS;
46+
}
47+
}

app/Enums/AlertType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ enum AlertType: string
88
case OPENAI_QUOTA_EXCEEDED = 'openai_quota_exceeded';
99
case OPENAI_API_ERROR = 'openai_api_error';
1010
case AMAZON_API_ERROR = 'amazon_api_error';
11+
case API_TIMEOUT = 'api_timeout';
12+
case CONNECTIVITY_ISSUE = 'connectivity_issue';
1113
case SYSTEM_ERROR = 'system_error';
1214
case RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded';
1315
case DATABASE_ERROR = 'database_error';
@@ -25,6 +27,8 @@ public function getDisplayName(): string
2527
self::OPENAI_QUOTA_EXCEEDED => 'OpenAI Quota Exceeded',
2628
self::OPENAI_API_ERROR => 'OpenAI API Error',
2729
self::AMAZON_API_ERROR => 'Amazon API Error',
30+
self::API_TIMEOUT => 'API Timeout',
31+
self::CONNECTIVITY_ISSUE => 'Connectivity Issue',
2832
self::SYSTEM_ERROR => 'System Error',
2933
self::RATE_LIMIT_EXCEEDED => 'Rate Limit Exceeded',
3034
self::DATABASE_ERROR => 'Database Error',
@@ -45,6 +49,8 @@ public function getDefaultPriority(): int
4549
self::SECURITY_ALERT => 2, // Emergency priority
4650
self::DATABASE_ERROR => 2, // Emergency priority
4751
self::SYSTEM_ERROR => 1, // High priority
52+
self::API_TIMEOUT => 0, // Normal priority
53+
self::CONNECTIVITY_ISSUE => 1, // High priority - might indicate broader issues
4854
self::OPENAI_API_ERROR => 0, // Normal priority
4955
self::AMAZON_API_ERROR => 0, // Normal priority
5056
self::RATE_LIMIT_EXCEEDED => 0, // Normal priority
@@ -77,6 +83,8 @@ public function shouldThrottle(): bool
7783
self::OPENAI_QUOTA_EXCEEDED => true,
7884
self::RATE_LIMIT_EXCEEDED => true,
7985
self::PERFORMANCE_ALERT => true,
86+
self::API_TIMEOUT => true,
87+
self::CONNECTIVITY_ISSUE => true,
8088
default => false,
8189
};
8290
}
@@ -91,6 +99,8 @@ public function getThrottleDuration(): int
9199
self::OPENAI_QUOTA_EXCEEDED => 60, // 1 hour
92100
self::RATE_LIMIT_EXCEEDED => 30, // 30 minutes
93101
self::PERFORMANCE_ALERT => 15, // 15 minutes
102+
self::API_TIMEOUT => 15, // 15 minutes
103+
self::CONNECTIVITY_ISSUE => 30, // 30 minutes - more serious
94104
default => 0,
95105
};
96106
}

app/Services/AlertService.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@ public function securityAlert(string $message, array $context = []): void
141141
);
142142
}
143143

144+
/**
145+
* Send API timeout alert
146+
*/
147+
public function apiTimeout(string $service, string $asin, int $timeoutDuration, array $context = []): void
148+
{
149+
$this->alert(
150+
AlertType::API_TIMEOUT,
151+
"API timeout for {$service} after {$timeoutDuration}s (ASIN: {$asin})",
152+
array_merge($context, [
153+
'service' => $service,
154+
'asin' => $asin,
155+
'timeout_duration' => $timeoutDuration,
156+
'error_type' => 'timeout'
157+
])
158+
);
159+
}
160+
161+
/**
162+
* Send connectivity issue alert
163+
*/
164+
public function connectivityIssue(string $service, string $errorType, string $errorMessage, array $context = []): void
165+
{
166+
$this->alert(
167+
AlertType::CONNECTIVITY_ISSUE,
168+
"Connectivity issue with {$service}: {$errorType} - {$errorMessage}",
169+
array_merge($context, [
170+
'service' => $service,
171+
'error_type' => $errorType,
172+
'error_message' => $errorMessage
173+
]),
174+
1 // High priority
175+
);
176+
}
177+
144178
/**
145179
* Check if an alert type is currently throttled
146180
*/

0 commit comments

Comments
 (0)