Skip to content

Commit

Permalink
Merge pull request #42 from aloware/fix/self-ddos-attack
Browse files Browse the repository at this point in the history
Fix Self-DDoS Attack
  • Loading branch information
hamed-aloware authored Jan 25, 2023
2 parents ec3a7d2 + 6d61551 commit 727f24b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/app.js": "/app.js?id=31d72bedd6a690baf59d53f3261836ab",
"/app.js": "/app.js?id=7542d73931f4d54c920ee18b026f37ef",
"/app-dark.css": "/app-dark.css?id=cd1d3557e4d1ad0ee48178571d428a17",
"/app.css": "/app.css?id=764ab48074813350c86491591a7e63b4"
}
12 changes: 9 additions & 3 deletions resources/js/screens/queues/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
data() {
return {
ready: false,
fetching: false,
saving: false,
page: 1,
perPage: 50,
Expand Down Expand Up @@ -46,6 +47,11 @@
* Load the monitored queues.
*/
loadQueues(starting = 0, refreshing = false) {
if(this.fetching) {
return;
}
this.fetching = true
if(!refreshing) {
this.ready = false;
}
Expand All @@ -55,9 +61,11 @@
this.queues = response.data;
this.ready = true;
this.fetching = false;
}).catch( error => {
this.$toasted.show('Error: ' + error.response.data.message);
this.ready = true;
this.ready = true;
this.fetching = false;
});
},
/**
Expand Down Expand Up @@ -144,7 +152,6 @@
<th>Queue</th>
<th>Partitions</th>
<th>Jobs</th>
<th>Signals</th>
<th>Processed In 1 Minute</th>
<th>Processed In 20 Minutes</th>
<th></th>
Expand All @@ -160,7 +167,6 @@
</td>
<td>{{ queue.partitions_count }}</td>
<td>{{ queue.jobs_count }}</td>
<td>{{ queue.signals_count }}</td>
<td>{{ queue.processed_jobs_count_1_min }}</td>
<td>{{ queue.processed_jobs_count_20_min }}</td>
<td class="gen-btn">
Expand Down
12 changes: 8 additions & 4 deletions resources/js/screens/queues/queue-partitions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
data() {
return {
ready: false,
fetching: false,
loadingNewEntries: false,
hasNewEntries: false,
isModalVisible: false,
Expand Down Expand Up @@ -59,6 +60,11 @@
* Load the partitions of the given queue.
*/
loadPartitions(queue, starting = 0, refreshing = false) {
if(this.fetching) {
return;
}
this.fetching = true;
if (!refreshing) {
this.ready = false;
}
Expand All @@ -74,9 +80,11 @@
}
this.ready = true;
this.fetching = false;
}).catch( error => {
this.$toasted.show('Error: ' + error.response.data.message);
this.ready = true;
this.fetching = false;
});
},
Expand Down Expand Up @@ -124,7 +132,6 @@
<tr>
<th>Partition Name</th>
<th>Number Of Jobs</th>
<th>Number Of Signals</th>
<th>ETA in Minutes</th>
<th>n/m</th>
</tr>
Expand All @@ -148,9 +155,6 @@
<td>
<span>{{ partition.count }}</span>
</td>
<td>
<span>{{ partition.signals_count }}</span>
</td>
<td>
<span>{{ partition.eta }}</span>
</td>
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/RedisKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function fairSignalKey($queue, $partition)
$horizon_prefix = config('horizon.prefix');

return sprintf(
'%s%s%s:%s:*',
'%s%s%s:%s:[0-9]*',
$horizon_prefix,
$signal_key_prefix_for_horizon,
$queue,
Expand Down
4 changes: 0 additions & 4 deletions src/Repositories/RedisRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ private function queuesWithPartitionsPrivate(
'queue' => $queue,
'partitions_count' => count($this->$partitionsResolver($queue)),
'jobs_count' => $this->totalJobsCount([$queue]),
'signals_count' => $this->countFairSignals($queue, '*'),
'processed_jobs_count_1_min' => $this->queueProcessedJobsInPastMinutes($queue, 1),
'processed_jobs_count_20_min' => $this->queueProcessedJobsInPastMinutes($queue, 20),
];
Expand Down Expand Up @@ -814,15 +813,12 @@ private function partitionsWithCountPrivate(
$partitionKey = $this->$partitionKeyResolver($queue, $partition);

$count = $redis->llen($partitionKey) ?: 0;
$signals_count = $this->countFairSignals($queue, $partition);
$per_minute = $this->partitionProcessedJobsInPastMinutes($queue, $partition, 1);
$eta = $per_minute ? ($count / $per_minute) : 0;

$item = [
'per_minute' => $per_minute,
'name' => $partition,
'count' => $count,
'signals_count' => $signals_count,
'eta' => round($eta, 2),
];

Expand Down

0 comments on commit 727f24b

Please sign in to comment.