Skip to content

Commit

Permalink
Merge pull request #461 from michaeldyrynda/2.0
Browse files Browse the repository at this point in the history
[2.0] Handle configured 'trim' values in dashboard
  • Loading branch information
taylorotwell committed Jan 12, 2019
2 parents de6b0ca + 3bfb94f commit 7144bd6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
35 changes: 33 additions & 2 deletions resources/assets/js/pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
stats: {},
workers: [],
workload: [],
ready: false,
};
},
Expand All @@ -38,6 +39,28 @@
},
computed: {
/**
* Determine the recent job period label.
*/
recentJobsPeriod() {
return ! this.ready
? 'Jobs past hour'
: `Jobs past ${this.determinePeriod(this.stats.periods.recentJobs)}`;
},
/**
* Determine the recently failed job period label.
*/
recentlyFailedPeriod() {
return ! this.ready
? 'Failed jobs past 7 days'
: `Failed jobs past ${this.determinePeriod(this.stats.periods.recentlyFailed)}`;
},
},
methods: {
/**
* Load the general stats.
Expand Down Expand Up @@ -121,6 +144,14 @@
return moment.duration(time, "seconds").humanize().replace(/^(.)|\s+(.)/g, function ($1) {
return $1.toUpperCase();
});
},
/**
* Determine the unit for the given timeframe.
*/
determinePeriod(minutes) {
return moment.duration(moment().diff(moment().subtract(minutes, "minutes"))).humanize().replace(/^An?/i, '');
}
}
}
Expand All @@ -143,14 +174,14 @@
</span>
</div>
<div class="stat col-3 p-4">
<h2 class="stat-title">Jobs past hour</h2>
<h2 class="stat-title" v-text="recentJobsPeriod"></h2>
<h3 class="stat-meta">&nbsp;</h3>
<span class="stat-value">
{{ stats.recentJobs.toLocaleString() }}
</span>
</div>
<div class="stat col-3 p-4">
<h2 class="stat-title">Failed Jobs past hour</h2>
<h2 class="stat-title" v-text="recentlyFailedPeriod"></h2>
<h3 class="stat-meta">&nbsp;</h3>
<span class="stat-value">
{{ stats.recentlyFailed.toLocaleString() }}
Expand Down
4 changes: 4 additions & 0 deletions src/Http/Controllers/DashboardStatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function index()
'recentJobs' => app(JobRepository::class)->countRecent(),
'status' => $this->currentStatus(),
'wait' => collect(app(WaitTimeCalculator::class)->calculate())->take(1),
'periods' => [
'recentJobs' => config('horizon.trim.recent'),
'recentlyFailed' => config('horizon.trim.failed'),
],
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Controller/DashboardStatsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function test_all_stats_are_correctly_returned()
'recentJobs' => 1,
'queueWithMaxRuntime' => 'default',
'queueWithMaxThroughput' => 'default',
'periods' => [
'recentJobs' => 60,
'recentlyFailed' => 10080,
],
]);
}

Expand Down

0 comments on commit 7144bd6

Please sign in to comment.