Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0] Handle configured 'trim' values in dashboard #461

Merged
merged 7 commits into from
Jan 12, 2019
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 }}
</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 }}
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