Permalink
Browse files

improve scheduler history

  • Loading branch information...
laurencei committed May 12, 2018
1 parent ee92126 commit 8f4fb5dae833dcc620ae67b75f4c4359963192d2
@@ -24,6 +24,6 @@ public function index()
->withNotifications(History::orderBy('acknowledged')->orderBy('created_at', 'desc')->get())
->withStatuses(Statuses::all())
->withQueues(Queue::with('latest_history')->get())
->withSchedulers(Scheduler::with('latest_history')->get());
->withSchedulers(Scheduler::all());
}
}
@@ -36,7 +36,7 @@ public function meta()
return [
'Command' => e($this->meta['scheduler']->command),
'Schedule' => e($this->meta['scheduler']->schedule),
'Last Run' => e($this->meta['scheduler']->latest_history->created_at->diffForHumans()),
'Last Run' => e($this->meta['scheduler']->last_run->diffForHumans()),
'Your alert threshold' => e($this->meta['scheduler']->alert_run_time_greater_than).' seconds',
'Actual cron job run time' => e(round($this->meta['time_to_run'], 1)).' seconds',
];
@@ -35,9 +35,9 @@ public function title()
public function meta()
{
try {
$last = e($this->meta['scheduler']->latest_history->created_at->diffForHumans());
$last = e($this->meta['scheduler']->last_run->diffForHumans());
} catch (Exception $e) {
$last = 'Unknown';
$last = 'Never';
}
return [
@@ -36,7 +36,7 @@ public function meta()
return [
'Command' => e($this->meta['scheduler']->command),
'Schedule' => e($this->meta['scheduler']->schedule),
'Last Run' => e($this->meta['scheduler']->latest_history->created_at->diffForHumans()),
'Started at' => e($this->meta['scheduler']->last_run->diffForHumans()),
'Your alert threshold' => e($this->meta['scheduler']->alert_run_time_greater_than).' seconds',
];
}
@@ -36,7 +36,7 @@ public function meta()
return [
'Command' => e($this->meta['scheduler']->command),
'Schedule' => e($this->meta['scheduler']->schedule),
'Last Run' => e($this->meta['scheduler']->latest_history->created_at->diffForHumans()),
'Started at' => e($this->meta['scheduler']->last_run->diffForHumans()),
'Your alert threshold' => e($this->meta['scheduler']->alert_run_time_greater_than).' seconds',
'Actual cron job run time' => e(round($this->meta['time_to_run'], 1)).' seconds',
];
@@ -19,7 +19,8 @@ class Scheduler extends Model
*
* @var array
*/
protected $casts = ['next_run_due' => 'datetime',
protected $casts = ['last_run' => 'datetime',
'next_run_due' => 'datetime',
'next_check_due' => 'datetime',
'created_at' => 'datetime'];
@@ -30,12 +31,4 @@ public function history()
{
return $this->hasMany(History::class)->latest();
}
/**
* Get the latest scheduler history that belong to this schedule.
*/
public function latest_history()
{
return $this->hasOne(History::class)->limit(1)->latest();
}
}
@@ -185,6 +185,7 @@ public function recordEventStart()
]);
} else {
$this->scheduler->fill([
'last_run' => date("Y-m-d H:i:s"),
'next_run_due' => $this->getNextRunDue($this->expression, $this->timezone),
'next_check_due' => $this->getNextCheckDue($this->expression, $this->timezone),
]);
@@ -196,7 +197,6 @@ public function recordEventStart()
'expected_completion' => $this->determineExpectedCompletion($this->scheduler),
]);
} catch (Exception $e) {
dd($e->getMessage());
app(Eye::class)->logger()->error('Unable to track scheduler',
$e->getMessage(),
['expresison' => $this->expression,
@@ -29,6 +29,7 @@
'on_one_server' => false,
'mutex' => uniqid(str_random(30), true),
'healthy' => 1,
'last_run' => date('Y-m-d H:i:s'),
'next_run_due' => date('Y-m-d H:i:s'),
'next_check_due' => date('Y-m-d H:i:s'),
'alert_on_missed' => 1,
@@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyEyewitnessIoSchedulersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection(config('eyewitness.eyewitness_database_connection'))->table('eyewitness_io_schedulers', function (Blueprint $table) {
$table->timestamp('last_run')->nullable()->default(null)->index();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection(config('eyewitness.eyewitness_database_connection'))->table('eyewitness_io_schedulers', function (Blueprint $table) {
$table->dropColumn('last_run');
});
}
}
@@ -27,8 +27,8 @@
<tr>
<td class="text-center text-sm py-3 font-hairline">{{ $scheduler->command }}</td>
<td class="text-center text-sm py-3 font-hairline hidden sm:table-cell"><span class="rounded py-1 px-2 uppercase font-semibold text-white text-sm bg-blue">{{ $scheduler->schedule }}</span></td>
@if ($scheduler->latest_history)
<td class="text-center text-sm py-3 font-hairline hidden sm:table-cell">{{ $scheduler->latest_history->created_at->diffForHumans() }}</td>
@if ($scheduler->last_run)
<td class="text-center text-sm py-3 font-hairline hidden sm:table-cell">{{ $scheduler->last_run->diffForHumans() }}</td>
@else
<td class="text-center hidden sm:table-cell"><span class="rounded py-1 px-2 uppercase font-semibold text-white text-xs bg-orange">Never</span></td>
@endif
@@ -43,8 +43,8 @@
</div>
<div class="w-1/2 md:w-3/4">
<p class="text-grey-darker ml-4">
@if ($scheduler->latest_history)
<td class="text-center text-sm py-3 font-hairline hidden sm:table-cell">{{ $scheduler->latest_history->created_at->diffForHumans() }}</td>
@if ($scheduler->last_run)
<td class="text-center text-sm py-3 font-hairline hidden sm:table-cell">{{ $scheduler->last_run->diffForHumans() }}</td>
@else
<td class="text-center hidden sm:table-cell"><span class="rounded py-1 px-2 uppercase font-semibold text-white text-xs bg-orange">Never</span></td>
@endif
@@ -42,5 +42,27 @@ public function test_schedulers_tab()
$response->assertSee($scheduler1->schedule);
$response->assertSee($scheduler2->schedule);
}
public function test_schedulers_tab_with_no_last_run()
{
$scheduler1 = factory(Scheduler::class)->create(['schedule' => '* 3 5 34 3', 'last_run' => null]);
$response = $this->withSession(['eyewitness:auth' => 1])
->get($this->home.'/dashboard');
$response->assertStatus(200);
$response->assertSee('Never');
}
public function test_schedulers_tab_with_previous_run()
{
$scheduler1 = factory(Scheduler::class)->create(['schedule' => '* 3 5 34 3', 'last_run' => '2016-01-01 01:01:01']);
$response = $this->withSession(['eyewitness:auth' => 1])
->get($this->home.'/dashboard');
$response->assertStatus(200);
$response->assertDontSee('Never');
}
}

0 comments on commit 8f4fb5d

Please sign in to comment.