Full rewrite Laravel style
This commit is contained in:
parent
cc03a0cf03
commit
416f5294e6
15 changed files with 375 additions and 237 deletions
|
@ -2,21 +2,29 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use \Exception;
|
||||
use App\Models\Task;
|
||||
use App\Models\TaskHistory;
|
||||
use App\Models\Notification;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use \Exception;
|
||||
use Illuminate\Queue\Console\MonitorCommand;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
|
||||
class RunMonitoring extends Command
|
||||
{
|
||||
private $rounds = 50;
|
||||
private $max_tries = 3;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monitolite:monitoring:run {rounds?}';
|
||||
protected $signature = 'monitolite:monitoring:run
|
||||
{--rounds=50 : the number of tasks to handle in one run}
|
||||
{--task= : the ID of an individual task to handle}
|
||||
{--force : handles tasks even if they are pending}
|
||||
';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
@ -48,20 +56,47 @@ class RunMonitoring extends Command
|
|||
public function handle()
|
||||
{
|
||||
$count = 0;
|
||||
$rounds = $this->argument('rounds') ?? $this->rounds;
|
||||
$rounds = $this->option('rounds') ?? $this->rounds;
|
||||
$this->max_tries = env('NB_TRIES', $this->max_tries);
|
||||
|
||||
// If a force has been asked via command line
|
||||
$force = false;
|
||||
if (! empty($this->option('force'))) {
|
||||
if (empty($this->option('task'))) {
|
||||
if ($this->confirm('You asked me to force the execution (--force) but you did not specify a particular task ID (--task). I might have to handle a large amount of tasks. Are you sure?')) {
|
||||
$force = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$force = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Getting pending tasks
|
||||
$tasks = DB::table('tasks')
|
||||
->where(function($query) {
|
||||
$query->whereRaw('DATE_SUB(NOW(), INTERVAL frequency SECOND) > last_execution');
|
||||
$query->orWhereNull('last_execution');
|
||||
$tasks = Task::where(function($query) use ($force) {
|
||||
$query->whereRaw('DATE_SUB(NOW(), INTERVAL frequency SECOND) > executed_at');
|
||||
$query->orWhereBetween('attempts', [1, ($this->max_tries - 1)]);
|
||||
$query->orWhereNull('executed_at');
|
||||
|
||||
if ($force === true) {
|
||||
$query->orWhere('id', '>', 0);
|
||||
}
|
||||
})
|
||||
->where('active', 1)
|
||||
->orderBy('last_execution', 'ASC')
|
||||
->orderBy('attempts', 'DESC')
|
||||
->orderBy('executed_at', 'ASC')
|
||||
->take($rounds)
|
||||
->get()
|
||||
;
|
||||
|
||||
|
||||
// If a particular task has been set via the command line
|
||||
if (! empty($this->option('task'))) {
|
||||
$tasks = $tasks->where('id', '=', $this->option('task'));
|
||||
}
|
||||
|
||||
// Now getting tasks
|
||||
$tasks = $tasks->get();
|
||||
|
||||
if (is_null($tasks) || count($tasks) == 0) {
|
||||
$this->info('No task to process, going back to sleep');
|
||||
return true;
|
||||
|
@ -74,19 +109,10 @@ class RunMonitoring extends Command
|
|||
$bar->start();
|
||||
|
||||
foreach ($tasks as $task) {
|
||||
$last_status = $new_status = $output = null;
|
||||
$bar->advance();
|
||||
|
||||
// Getting current task last status
|
||||
$query = DB::table('tasks_history')
|
||||
->select('status')
|
||||
->where('task_id', $task->id)
|
||||
->orderBy('datetime', 'DESC')
|
||||
->first()
|
||||
;
|
||||
if ($query !== false && ! is_null($query)) {
|
||||
$last_status = $query->status;
|
||||
}
|
||||
$previous_status = $task->status;
|
||||
|
||||
try {
|
||||
switch ($task->type) {
|
||||
|
@ -103,13 +129,43 @@ class RunMonitoring extends Command
|
|||
continue 2;
|
||||
}
|
||||
|
||||
$this->saveHistory($task, true);
|
||||
$history = $this->saveHistory($task, true);
|
||||
}
|
||||
catch(MonitoringException $e) {
|
||||
$this->saveHistory($task, false, $e->getMessage());
|
||||
$history = $this->saveHistory($task, false, $e->getMessage());
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$this->saveHistory($task, false, $e->getMessage());
|
||||
$history = $this->saveHistory($task, false, $e->getMessage());
|
||||
}
|
||||
finally {
|
||||
// Changing task timestamps and status
|
||||
$task->executed_at = $history->created_at; # Using the same timestamp as the task history
|
||||
$task->attempts = $history->status == 1 ? 0 : $task->attempts + 1; # when success, resetting counter
|
||||
/**
|
||||
* We don't want to change the primary status in the task table
|
||||
* as long as failed tasks have reached the max tries limit
|
||||
* In the cast of a success, we can change the status straight away
|
||||
*/
|
||||
if ($history->status == 0 && $task->attempts >= $this->max_tries) {
|
||||
$task->status = 0;
|
||||
}
|
||||
else if ($history->status === 1) {
|
||||
$task->status = 1;
|
||||
}
|
||||
|
||||
if (! $task->save()) {
|
||||
throw new Exception('Cannot save task details');
|
||||
}
|
||||
|
||||
|
||||
// Task status has changed
|
||||
// But not from null (new task)
|
||||
if (! is_null($previous_status) && $task->status != $previous_status) {
|
||||
// If host is up, no double-check
|
||||
if ($task->status == 1 || ($task->status == 0 && $task->attempts == $this->max_tries)) {
|
||||
Notification::addNotificationTask($history);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$bar->finish();
|
||||
|
@ -117,42 +173,39 @@ class RunMonitoring extends Command
|
|||
|
||||
if (!empty($this->results)) {
|
||||
$this->table(
|
||||
['Host', 'Result', 'Message'],
|
||||
['ID', 'Host', 'Type', 'Result', 'Attempts', 'Message'],
|
||||
$this->results
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final private function saveHistory($task, $status, $output = null) {
|
||||
final private function saveHistory(Task $task, $status, $output = null) {
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
// Inserting new history
|
||||
$insert = new TaskHistory;
|
||||
$insert->status = $status === true ? 1 : 0;
|
||||
$insert->created_at = $date;
|
||||
$insert->output = $output ?? '';
|
||||
$insert->task_id = $task->id;
|
||||
if (! $insert->save()) {
|
||||
throw new Exception('Cannot insert history for task #'.$task->id);
|
||||
}
|
||||
|
||||
$this->results[] = [
|
||||
'id' => $task->id,
|
||||
'host' => $task->host,
|
||||
'type' => $task->type,
|
||||
'result' => $status === true ? 'OK' : 'FAILED',
|
||||
'attempts' => $task->attempts,
|
||||
'message' => $output
|
||||
];
|
||||
|
||||
$insert = DB::table('tasks_history')
|
||||
->insert([
|
||||
'status' => $status === true ? 1 : 0,
|
||||
'datetime' => $date,
|
||||
'output' => $output ?? '',
|
||||
'task_id' => $task->id
|
||||
]
|
||||
);
|
||||
|
||||
if (false !== $insert) {
|
||||
DB::table('tasks')
|
||||
->where('id', $task->id)
|
||||
->update([
|
||||
'last_execution' => $date
|
||||
])
|
||||
;
|
||||
return true;
|
||||
}
|
||||
return $insert;
|
||||
}
|
||||
|
||||
final private function checkPing($task) {
|
||||
final private function checkPing(Task $task) {
|
||||
if (! function_exists('exec') || ! is_callable('exec')) {
|
||||
throw new MonitoringException('The "exec" command is required');
|
||||
}
|
||||
|
@ -196,7 +249,11 @@ class RunMonitoring extends Command
|
|||
return true;
|
||||
}
|
||||
|
||||
final private function checkHttp($task) {
|
||||
final private function checkHttp(Task $task) {
|
||||
if (app()->environment() == 'local') {
|
||||
//throw new MonitoringException('Forcing error for testing');
|
||||
}
|
||||
|
||||
// Preparing cURL
|
||||
$opts = [
|
||||
CURLOPT_HTTPGET => true,
|
||||
|
|
|
@ -125,7 +125,7 @@ class SyncCustomers extends Command
|
|||
|
||||
// Inserting contacts
|
||||
foreach ($contacts as $c) {
|
||||
app('db')->insert('INSERT INTO notifications (`task_id`, `contact_id`) VALUES (:task_id, :contact_id)', [
|
||||
app('db')->insert('INSERT INTO contact_task (`task_id`, `contact_id`) VALUES (:task_id, :contact_id)', [
|
||||
'task_id' => $task_id,
|
||||
'contact_id' => $c->id
|
||||
]);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use Exception;
|
||||
use App\Models\Task;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
@ -22,14 +23,23 @@ class ApiController extends Controller
|
|||
public function getTasks() {
|
||||
$tasks = [];
|
||||
|
||||
$query = DB::select('
|
||||
SELECT DISTINCT t.id, t.host, t.type, t.params, t.frequency, t.creation_date, t.last_execution, t.active, t.group_id, h.status, h.output, g.name as group_name
|
||||
FROM `tasks` as t
|
||||
LEFT JOIN `tasks_history` as h ON (h.task_id = t.id)
|
||||
LEFT JOIN `groups` as g ON (g.id = t.group_id)
|
||||
WHERE (t.last_execution IS NULL OR h.datetime = t.last_execution)
|
||||
ORDER BY group_name ASC
|
||||
');
|
||||
$query = Task
|
||||
::leftJoin('groups', 'groups.id', 'tasks.group_id')
|
||||
->leftJoinSub(
|
||||
DB::table('task_history')
|
||||
->select('id', DB::raw('MAX(created_at) as created_at'), 'output', 'status', 'task_id')
|
||||
->groupBy('id')
|
||||
, 'task_history', function($join) {
|
||||
$join
|
||||
->on('task_history.task_id', '=', 'tasks.id')
|
||||
;
|
||||
})
|
||||
->select(
|
||||
'tasks.id', 'tasks.host', 'tasks.status', 'tasks.type', 'tasks.params', 'tasks.frequency', 'tasks.created_at', 'tasks.executed_at', 'tasks.active', 'tasks.group_id',
|
||||
'task_history.output',
|
||||
'groups.name as group_name')
|
||||
->get()
|
||||
;
|
||||
|
||||
foreach ($query as $t) {
|
||||
if (is_null($t->group_id)) {
|
||||
|
@ -56,41 +66,42 @@ class ApiController extends Controller
|
|||
|
||||
|
||||
public function getTaskDetails($id) {
|
||||
$query = DB::select('
|
||||
SELECT t.id, t.host, t.type, t.params, t.frequency, t.creation_date, t.last_execution, t.active, t.group_id, h.status, h.output, g.name as group_name
|
||||
FROM `tasks` as t
|
||||
LEFT JOIN `tasks_history` as h ON (h.task_id = t.id)
|
||||
LEFT JOIN `groups` as g ON (g.id = t.group_id)
|
||||
WHERE (t.last_execution IS NULL OR h.datetime = t.last_execution) AND t.id = :task_id
|
||||
LIMIT 1
|
||||
', [
|
||||
'task_id' => $id
|
||||
]);
|
||||
|
||||
if ($query) {
|
||||
foreach ($query as $q) {
|
||||
return response()->json($q);
|
||||
}
|
||||
$task = Task
|
||||
::leftJoin('groups', 'groups.id', 'tasks.group_id')
|
||||
->leftJoinSub(
|
||||
DB::table('task_history')
|
||||
->select('id', DB::raw('MAX(created_at) as created_at'), 'output', 'status', 'task_id')
|
||||
->groupBy('id')
|
||||
, 'task_history', function($join) {
|
||||
$join
|
||||
->on('task_history.task_id', '=', 'tasks.id')
|
||||
;
|
||||
})
|
||||
->select(
|
||||
'tasks.id', 'tasks.host', 'tasks.status', 'tasks.type', 'tasks.params', 'tasks.frequency', 'tasks.created_at', 'tasks.executed_at', 'tasks.active', 'tasks.group_id',
|
||||
'task_history.output',
|
||||
'groups.name as group_name')
|
||||
->findOrFail($id)
|
||||
;
|
||||
|
||||
if (! is_null($task)) {
|
||||
return response()->json($task);
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleTaskStatus(Request $request, $id) {
|
||||
if($active = $request->input('active')) {
|
||||
//throw new ApiException('Invalid parameters');
|
||||
}
|
||||
$active = $request->input('active', null);
|
||||
|
||||
if (is_null($active)) {
|
||||
throw new ApiException('Invalid parameters');
|
||||
}
|
||||
$active = intval($active);
|
||||
|
||||
$query = DB::update('
|
||||
UPDATE tasks
|
||||
SET active = :active
|
||||
WHERE id = :id
|
||||
', [
|
||||
'active' => $active,
|
||||
'id' => $id
|
||||
]);
|
||||
$task = Task::findOrFail($id);
|
||||
$task->active = $active;
|
||||
|
||||
if ($query !== false) {
|
||||
if ($task->save()) {
|
||||
return $this->getTaskDetails($id);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
class ExampleJob extends Job
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
22
app/Models/Contact.php
Normal file
22
app/Models/Contact.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Contact extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
24
app/Models/Group.php
Normal file
24
app/Models/Group.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Group extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
|
||||
public function tasks() {
|
||||
return $this->hasMany('App\Models\Task');
|
||||
}
|
||||
|
||||
}
|
40
app/Models/Notification.php
Normal file
40
app/Models/Notification.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Notification extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
public function contact() {
|
||||
return $this->belongsTo('App\Models\Contact');
|
||||
}
|
||||
|
||||
public function task_history() {
|
||||
return $this->belongsTo('App\Models\TaskHistory');
|
||||
}
|
||||
|
||||
public static function addNotificationTask(TaskHistory $history) {
|
||||
$contacts = $history->task->contacts()->get();
|
||||
if (! is_null($contacts)) {
|
||||
foreach ($contacts as $c) {
|
||||
$notification = new Notification;
|
||||
$notification->contact_id = $c->id;
|
||||
$notification->task_history_id = $history->id;
|
||||
$notification->status = 'pending';
|
||||
$notification->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
app/Models/Task.php
Normal file
40
app/Models/Task.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
public $timestamps = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'executed_at'
|
||||
];
|
||||
|
||||
public function group() {
|
||||
return $this->belongsTo('App\Models\Group');
|
||||
}
|
||||
|
||||
public function notifications() {
|
||||
return $this->hasMany('App\Models\Notification');
|
||||
}
|
||||
|
||||
public function contacts() {
|
||||
return $this->belongsToMany('App\Models\Contact');
|
||||
}
|
||||
|
||||
public function history() {
|
||||
return $this->hasMany('App\Models\TaskHistory');
|
||||
}
|
||||
}
|
22
app/Models/TaskContact.php
Normal file
22
app/Models/TaskContact.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TaskContact extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
29
app/Models/TaskHistory.php
Normal file
29
app/Models/TaskHistory.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TaskHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'task_history';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
public function notifications() {
|
||||
return $this->hasMany('App\Models\Notification');
|
||||
}
|
||||
|
||||
public function task() {
|
||||
return $this->belongsTo('App\Models\Task');
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ $app = new Laravel\Lumen\Application(
|
|||
|
||||
$app->withFacades();
|
||||
|
||||
// $app->withEloquent();
|
||||
$app->withEloquent();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -71,7 +71,7 @@ function setDbTimezone() {
|
|||
|
||||
$app->configure('app');
|
||||
$app->configure('database');
|
||||
|
||||
$app->configure('queue');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
DROP TABLE IF EXISTS `contact_task`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `contact_task` (
|
||||
`task_id` int unsigned NOT NULL,
|
||||
`contact_id` int unsigned NOT NULL,
|
||||
PRIMARY KEY (`task_id`,`contact_id`),
|
||||
KEY `contact_id` (`contact_id`),
|
||||
CONSTRAINT `contact_task_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `contact_task_ibfk_2` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
DROP TABLE IF EXISTS `contacts`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
|
@ -32,7 +44,7 @@ DROP TABLE IF EXISTS `migrations`;
|
|||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `migrations` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`batch` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
@ -41,12 +53,32 @@ DROP TABLE IF EXISTS `notifications`;
|
|||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `notifications` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`contact_id` int unsigned NOT NULL DEFAULT '0',
|
||||
`task_history_id` int unsigned NOT NULL DEFAULT '0',
|
||||
`status` enum('pending','sent','error') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'pending',
|
||||
`created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:01',
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `contact_id_frgn` (`contact_id`),
|
||||
KEY `task_history_id_frgn` (`task_history_id`),
|
||||
CONSTRAINT `contact_id_frgn` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `task_history_id_frgn` FOREIGN KEY (`task_history_id`) REFERENCES `task_history` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
DROP TABLE IF EXISTS `task_history`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `task_history` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`status` int unsigned NOT NULL,
|
||||
`output` text CHARACTER SET utf8 COLLATE utf8_general_ci,
|
||||
`task_id` int unsigned NOT NULL,
|
||||
`contact_id` int unsigned NOT NULL,
|
||||
PRIMARY KEY (`task_id`,`contact_id`),
|
||||
KEY `contact_id` (`contact_id`),
|
||||
CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `notifications_ibfk_2` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE
|
||||
`created_at` datetime NOT NULL,
|
||||
`updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:01',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `task_id` (`task_id`),
|
||||
CONSTRAINT `task_history_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
DROP TABLE IF EXISTS `tasks`;
|
||||
|
@ -57,11 +89,14 @@ CREATE TABLE `tasks` (
|
|||
`host` varchar(255) NOT NULL,
|
||||
`type` enum('ping','http') NOT NULL,
|
||||
`params` varchar(255) NOT NULL,
|
||||
`creation_date` datetime NOT NULL,
|
||||
`frequency` int unsigned NOT NULL,
|
||||
`last_execution` datetime DEFAULT NULL,
|
||||
`attempts` int unsigned NOT NULL DEFAULT '0',
|
||||
`active` int NOT NULL DEFAULT '0',
|
||||
`status` int unsigned DEFAULT NULL,
|
||||
`group_id` int unsigned DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`executed_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `host` (`host`,`type`),
|
||||
KEY `group_id_frgn` (`group_id`),
|
||||
|
@ -79,20 +114,6 @@ CREATE TABLE `tasks_archives` (
|
|||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
DROP TABLE IF EXISTS `tasks_history`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `tasks_history` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`status` int unsigned NOT NULL,
|
||||
`datetime` datetime NOT NULL,
|
||||
`output` text CHARACTER SET utf8 COLLATE utf8_general_ci,
|
||||
`task_id` int unsigned NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `task_id` (`task_id`),
|
||||
CONSTRAINT `tasks_history_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
|
@ -100,3 +121,5 @@ CREATE TABLE `tasks_history` (
|
|||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
INSERT INTO `migrations` VALUES (1,'2021_12_21_101954_create_jobs_table',1);
|
||||
INSERT INTO `migrations` VALUES (2,'2021_12_21_102355_create_failed_jobs_table',2);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -42,9 +42,9 @@
|
|||
</td>
|
||||
<td>
|
||||
<span
|
||||
v-if="task.last_execution"
|
||||
v-if="task.executed_at"
|
||||
>
|
||||
{{ moment(task.last_execution).fromNow() }}
|
||||
{{ moment(task.executed_at).fromNow() }}
|
||||
<img src="/img/info.svg" alt="Infos" width="16" :title="'Result: '+task.output" />
|
||||
</span>
|
||||
<span
|
||||
|
|
104
sql/create.sql
104
sql/create.sql
|
@ -1,104 +0,0 @@
|
|||
#
|
||||
# SQL Export
|
||||
# Created by Querious (300063)
|
||||
# Created: 19 December 2021 at 10:19:50 CET
|
||||
# Encoding: Unicode (UTF-8)
|
||||
#
|
||||
|
||||
|
||||
SET @ORIG_FOREIGN_KEY_CHECKS = @@FOREIGN_KEY_CHECKS;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
SET @ORIG_UNIQUE_CHECKS = @@UNIQUE_CHECKS;
|
||||
SET UNIQUE_CHECKS = 0;
|
||||
|
||||
SET @ORIG_TIME_ZONE = @@TIME_ZONE;
|
||||
SET TIME_ZONE = '+00:00';
|
||||
|
||||
SET @ORIG_SQL_MODE = @@SQL_MODE;
|
||||
SET SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO';
|
||||
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `tasks_history`;
|
||||
DROP TABLE IF EXISTS `notifications`;
|
||||
DROP TABLE IF EXISTS `tasks`;
|
||||
DROP TABLE IF EXISTS `groups`;
|
||||
DROP TABLE IF EXISTS `contacts`;
|
||||
|
||||
|
||||
CREATE TABLE `contacts` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`surname` varchar(200) NOT NULL,
|
||||
`firstname` varchar(200) NOT NULL,
|
||||
`email` varchar(250) NOT NULL,
|
||||
`phone` varchar(20) NOT NULL,
|
||||
`creation_date` datetime NOT NULL,
|
||||
`active` int NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
|
||||
CREATE TABLE `groups` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=244 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci;
|
||||
|
||||
|
||||
CREATE TABLE `tasks` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`host` varchar(255) NOT NULL,
|
||||
`type` enum('ping','http') NOT NULL,
|
||||
`params` varchar(255) NOT NULL,
|
||||
`creation_date` datetime NOT NULL,
|
||||
`frequency` int unsigned NOT NULL,
|
||||
`last_execution` datetime DEFAULT NULL,
|
||||
`active` int NOT NULL DEFAULT '0',
|
||||
`group_id` int unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `host` (`host`,`type`),
|
||||
KEY `group_id_frgn` (`group_id`),
|
||||
CONSTRAINT `group_id_frgn` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=147 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
|
||||
CREATE TABLE `notifications` (
|
||||
`task_id` int unsigned NOT NULL,
|
||||
`contact_id` int unsigned NOT NULL,
|
||||
PRIMARY KEY (`task_id`,`contact_id`),
|
||||
KEY `contact_id` (`contact_id`),
|
||||
CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `notifications_ibfk_2` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
|
||||
CREATE TABLE `tasks_history` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`status` int unsigned NOT NULL,
|
||||
`datetime` datetime NOT NULL,
|
||||
`output` text CHARACTER SET utf8 COLLATE utf8_general_ci,
|
||||
`task_id` int unsigned NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `task_id` (`task_id`),
|
||||
CONSTRAINT `tasks_history_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = @ORIG_FOREIGN_KEY_CHECKS;
|
||||
|
||||
SET UNIQUE_CHECKS = @ORIG_UNIQUE_CHECKS;
|
||||
|
||||
SET @ORIG_TIME_ZONE = @@TIME_ZONE;
|
||||
SET TIME_ZONE = @ORIG_TIME_ZONE;
|
||||
|
||||
SET SQL_MODE = @ORIG_SQL_MODE;
|
||||
|
||||
|
||||
|
||||
# Export Finished: 19 December 2021 at 10:19:50 CET
|
||||
|
Loading…
Add table
Reference in a new issue