Skip to content

Commit ad8eb5f

Browse files
authored
refactor : frequencies, form and kernel
1 parent 18db305 commit ad8eb5f

File tree

14 files changed

+264
-156
lines changed

14 files changed

+264
-156
lines changed

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/app.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/app.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/less/uikit-themes/totem/divider.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@divider-icon-color: @global-primary-background;
1111
@divider-icon-width: 70px;
12-
@divider-icon-height: 8px;
13-
@divider-icon-line-border-width: 0;
12+
@divider-icon-height: 20px;
13+
@divider-icon-line-border-width: 1px;
1414
@internal-divider-icon-image: "../../../uikit-themes/totem/images/divider-icon.svg";
1515

1616
@divider-small-width: 45px;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<footer class="main-footer">
22
<div class="uk-container">
3-
<p class="uk-text-center"> © Laravel Totem. All rights reserved.</p>
3+
<p class="uk-text-center"> © <a target="_blank" href="https://twitter.com/@roshangautam">Roshan Gautam</a>. All rights reserved.</p>
44
</div>
55
</footer>

resources/views/tasks/form.blade.php

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- {{ $task->exists ? 'Update' : 'Create'}} Task
55
@stop
66
@section('main-panel-before')
7-
<form action="{{ request()->fullUrl() }}" method="POST" class="uk-form-horizontal">
7+
<form action="{{ request()->fullUrl() }}" method="POST">
88
{{csrf_field()}}
99
@stop
1010
@section('title')
@@ -13,20 +13,26 @@
1313
</div>
1414
@stop
1515
@section('main-panel-content')
16-
<div class="uk-margin">
17-
<label class="uk-form-label">Description</label>
18-
<div class="uk-form-controls">
19-
<input class="uk-input" placeholder="A brief description" name="description" id="description" value="{{old('description', $task->description)}}" type="text">
16+
<div class="uk-grid">
17+
<div class="uk-width-1-3">
18+
<label class="uk-form-label">Description</label>
19+
<div class="uk-text-meta">Provide a descriptive name for your task</div>
20+
</div>
21+
<div class="uk-width-2-3">
22+
<input class="uk-input" placeholder="e.g. Daily Backups" name="description" id="description" value="{{old('description', $task->description)}}" type="text">
2023
@if($errors->has('description'))
2124
<p class="uk-text-danger">{{$errors->first('description')}}</p>
2225
@endif
2326
</div>
2427
</div>
25-
<div class="uk-margin">
26-
<label class="uk-form-label">Command</label>
27-
<div class="uk-form-controls">
28+
<div class="uk-grid">
29+
<div class="uk-width-1-3">
30+
<label class="uk-form-label">Command</label>
31+
<div class="uk-text-meta">Select an artisan command to schedule</div>
32+
</div>
33+
<div class="uk-width-2-3">
2834
<select id="command" name="command" class="uk-select" placeholder="Click here to select one of the available commands">
29-
<option value="">Click here to select one of the available commands</option>
35+
<option value="">Select a command</option>
3036
@foreach ($commands as $command)
3137
<option value="{{$command->getName()}}" {{old('command', $task->command) == $command->getName() ? 'selected' : ''}}>{{$command->getDescription()}}</option>
3238
@endforeach
@@ -36,27 +42,37 @@
3642
@endif
3743
</div>
3844
</div>
39-
<div class="uk-margin">
40-
<label class="uk-form-label">Parameters</label>
41-
<div class="uk-form-controls">
42-
<input class="uk-input" placeholder="Any command parameters required to run the selected command" name="parameters" id="parameters" value="{{old('parameters', $task->parameters)}}" type="text">
45+
<div class="uk-grid">
46+
<div class="uk-width-1-3">
47+
<label class="uk-form-label">Parameters (Optional)</label>
48+
<div class="uk-text-meta">Command parameters required to run the selected command</div>
49+
</div>
50+
<div class="uk-width-2-3">
51+
<input class="uk-input" placeholder="e.g. --type=all" name="parameters" id="parameters" value="{{old('parameters', $task->parameters)}}" type="text">
4352
</div>
4453
</div>
45-
<div class="uk-margin">
46-
<label class="uk-form-label">Timezone</label>
47-
<div class="uk-form-controls">
48-
<select id="timezone" name="timezone" class="uk-select" placeholder="Click here to select one of the available commands">
54+
<hr class="uk-divider-icon">
55+
<div class="uk-grid">
56+
<div class="uk-width-1-3">
57+
<label class="uk-form-label">Timezone</label>
58+
<div class="uk-text-meta">Select a timezone for your task. App timezone is selected by default</div>
59+
</div>
60+
<div class="uk-width-2-3">
61+
<select id="timezone" name="timezone" class="uk-select" placeholder="Select a timezone">
4962
@foreach ($timezones as $key => $timezone)
5063
<option value="{{$timezone}}" {{old('timezone', $task->exists ? $task->timezone : config('app.timezone')) == $timezone ? 'selected' : ''}}>{{$timezone}}</option>
5164
@endforeach
5265
</select>
5366
</div>
5467
</div>
5568
<task-type inline-template current="{{old('type', $task->expression ? 'expression' : 'frequency')}}" :existing="{{old('frequencies') ? json_encode(old('frequencies')) : $task->frequencies}}" >
56-
<div>
57-
<div class="uk-margin">
58-
<div class="uk-form-label">Type</div>
59-
<div class="uk-form-controls uk-form-controls-text">
69+
<div class="uk-margin">
70+
<div class="uk-grid">
71+
<div class="uk-width-1-3">
72+
<div class="uk-form-label">Type</div>
73+
<div class="uk-text-meta">Choose whether to define a cron expression or to add frequencies</div>
74+
</div>
75+
<div class="uk-width-2-3 uk-form-controls-text">
6076
<label>
6177
<input type="radio" name="type" v-model="type" value="expression"> Expression
6278
</label><br>
@@ -65,18 +81,24 @@
6581
</label>
6682
</div>
6783
</div>
68-
<div class="uk-margin" v-if="isCron">
69-
<label class="uk-form-label">Cron Expression</label>
70-
<div class="uk-form-controls">
84+
<div class="uk-grid" v-if="isCron">
85+
<div class="uk-width-1-3">
86+
<label class="uk-form-label">Cron Expression</label>
87+
<div class="uk-text-meta">Add a cron expression for your task</div>
88+
</div>
89+
<div class="uk-width-2-3">
7190
<input class="uk-input" placeholder="e.g * * * * * to run this task all the time" name="expression" id="expression" value="{{old('expression', $task->expression)}}" type="text">
7291
@if($errors->has('expression'))
7392
<p class="uk-text-danger">{{$errors->first('expression')}}</p>
7493
@endif
7594
</div>
7695
</div>
77-
<div class="uk-margin" v-if="managesFrequencies">
78-
<label class="uk-form-label"></label>
79-
<div class="uk-form-controls">
96+
<div class="uk-grid" v-if="managesFrequencies">
97+
<div class="uk-width-1-3">
98+
<label class="uk-form-label">Frequencies</label>
99+
<div class="uk-text-meta">Add frequencies to your task. These frequencies will be converted into a cron expression while scheduling the task</div>
100+
</div>
101+
<div class="uk-width-2-3">
80102
<a class="uk-button uk-button-small uk-button-link" @click.self.prevent="showModal = true">Add Frequency</a>
81103
@include('totem::dialogs.frequencies.add')
82104
<table class="uk-table uk-table-divider uk-margin-remove">
@@ -128,36 +150,51 @@
128150
</div>
129151
</div>
130152
</task-type>
131-
<div class="uk-margin">
132-
<label class="uk-form-label">Email Notification</label>
133-
<div class="uk-form-controls">
134-
<input type="text" id="email" name="notification_email_address" value="{{old('notification_email_address', $task->notification_email_address)}}" class="uk-input" placeholder="Leave empty if you do not wish to receive email notifications">
153+
<hr class="uk-divider-icon">
154+
<div class="uk-grid">
155+
<div class="uk-width-1-3">
156+
<label class="uk-form-label">Email Notification (optional)</label>
157+
<div class="uk-text-meta">Add an email address to receive notifications when this task gets executed. Leave empty if you do not wish to receive email notifications</div>
158+
</div>
159+
<div class="uk-width-2-3">
160+
<input type="text" id="email" name="notification_email_address" value="{{old('notification_email_address', $task->notification_email_address)}}" class="uk-input" placeholder="e.g. john.doe@name.tld">
135161
@if($errors->has('notification_email_address'))
136162
<p class="uk-text-danger">{{$errors->first('notification_email_address')}}</p>
137163
@endif
138164
</div>
139165
</div>
140-
<div class="uk-margin">
141-
<label class="uk-form-label">SMS Notification</label>
142-
<div class="uk-form-controls">
143-
<input type="text" id="phone" name="notification_phone_number" value="{{old('notification_phone_number', $task->notification_phone_number)}}" class="uk-input" placeholder="Leave empty if you do not wish to receive sms notifications">
166+
<div class="uk-grid">
167+
<div class="uk-width-1-3">
168+
<label class="uk-form-label">SMS Notification (optional)</label>
169+
<div class="uk-text-meta">Add a phone number to receive SMS notifications. Leave empty if you do not wish to receive sms notifications</div>
170+
</div>
171+
<div class="uk-width-2-3">
172+
<input type="text" id="phone" name="notification_phone_number" value="{{old('notification_phone_number', $task->notification_phone_number)}}" class="uk-input" placeholder="e.g. 18701234567">
144173
@if($errors->has('notification_phone_number'))
145174
<p class="uk-text-danger">{{$errors->first('notification_phone_number')}}</p>
146175
@endif
147176
</div>
148177
</div>
149-
<div class="uk-margin">
150-
<label class="uk-form-label">Slack Notification</label>
151-
<div class="uk-form-controls">
152-
<input type="text" id="slack" name="notification_slack_webhook" value="{{old('notification_slack_webhook', $task->notification_slack_webhook)}}" class="uk-input" placeholder="Leave empty if you do not wish to receive slack notifications">
178+
<div class="uk-grid">
179+
<div class="uk-width-1-3">
180+
<label class="uk-form-label">Slack Notification (optional)</label>
181+
<div class="uk-text-meta">Add a slack web hook url to recieve slack notifications. Phone numbers should include country code and are digits only. Leave empty if you do not wish to receive slack notifications</div>
182+
</div>
183+
<div class="uk-width-2-3">
184+
<input type="text" id="slack" name="notification_slack_webhook" value="{{old('notification_slack_webhook', $task->notification_slack_webhook)}}" class="uk-input" placeholder="e.g. https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX">
153185
@if($errors->has('notification_slack_webhook'))
154186
<p class="uk-text-danger">{{$errors->first('notification_slack_webhook')}}</p>
155187
@endif
156188
</div>
157189
</div>
158-
<div class="uk-margin">
159-
<div class="uk-form-label"></div>
160-
<div class="uk-form-controls uk-form-controls-text">
190+
<hr class="uk-divider-icon">
191+
<div class="uk-grid">
192+
<div class="uk-width-1-3">
193+
<div class="uk-form-controls">Miscellaneous Options</div>
194+
<div class="uk-text-meta">Decide whether multiple instances of same task should overlap each other or not.</div>
195+
<div class="uk-text-meta">Decide whether the task should be executed while the app is in maintenance mode.</div>
196+
</div>
197+
<div class="uk-width-2-3 uk-form-controls-text">
161198
<label>
162199
<input type="hidden" name="dont_overlap" id="dont_overlap" value="0" {{old('dont_overlap', $task->dont_overlap) ? '' : 'checked'}}>
163200
<input type="checkbox" name="dont_overlap" id="dont_overlap" value="1" {{old('dont_overlap', $task->dont_overlap) ? 'checked' : ''}}>

src/Console/Commands/ListSchedule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public function handle()
5151
if (count($this->schedule->events()) > 0) {
5252
$events = collect($this->schedule->events())->map(function ($event) {
5353
return [
54-
'description' => $event->description,
54+
'description' => $event->description ?: 'N/A',
5555
'command' => ltrim(strtok(str_after($event->command, "'artisan'"), ' ')),
5656
'schedule' => $event->expression,
5757
'upcoming' => $this->upcoming($event),
58-
'timezone' => $event->timezone,
58+
'timezone' => $event->timezone ?: config('app.timezone'),
5959
'overlaps' => $event->withoutOverlapping ? 'No' : 'Yes',
6060
'maintenance' => $event->evenInMaintenanceMode ? 'Yes' : 'No',
6161
];

src/Console/Kernel.php

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,13 @@
22

33
namespace Studio\Totem\Console;
44

5-
use Studio\Totem\Events\Tasks\Executed;
6-
use Studio\Totem\Events\Tasks\Executing;
7-
use Studio\Totem\Contracts\TaskInterface;
8-
use Illuminate\Console\Scheduling\Schedule;
9-
use Illuminate\Contracts\Events\Dispatcher;
10-
use Illuminate\Contracts\Foundation\Application;
115
use Illuminate\Foundation\Console\Kernel as AppKernel;
126

137
class Kernel extends AppKernel
148
{
159
/**
16-
* @var TaskInterface
17-
*/
18-
private $tasks;
19-
20-
/**
21-
* Kernel constructor.
22-
* @param Application $app
23-
* @param Dispatcher $events
24-
* @param TaskInterface $tasks
25-
*/
26-
public function __construct(Application $app, Dispatcher $events, TaskInterface $tasks)
27-
{
28-
$this->tasks = $tasks;
29-
30-
parent::__construct($app, $events);
31-
}
32-
33-
/**
34-
* Define the application's command schedule.
10+
* Get a list of all artisan commands.
3511
*
36-
* @param Schedule $schedule
37-
* @return void
38-
*/
39-
protected function schedule(Schedule $schedule)
40-
{
41-
$this->prepareSchedule($schedule);
42-
// $schedule->command('inspire')
43-
// ->hourly()
44-
// ->timezone('America/Chicago');
45-
46-
parent::schedule($schedule);
47-
}
48-
49-
/**
5012
* @return array
5113
*/
5214
public function getCommands()
@@ -55,31 +17,4 @@ public function getCommands()
5517
return $command->getDescription();
5618
});
5719
}
58-
59-
public function prepareSchedule(Schedule $schedule)
60-
{
61-
$tasks = $this->tasks->findAllActive();
62-
63-
$tasks->each(function ($task) use ($schedule) {
64-
$event = $schedule->command($task->command.' '.$task->parameters);
65-
66-
$event->cron($task->getCronExpression())
67-
->name($task->description)
68-
->timezone($task->timezone)
69-
->before(function () use ($task, $event) {
70-
$event->start = microtime(true);
71-
Executing::dispatch($task);
72-
})
73-
->after(function () use ($event, $task) {
74-
Executed::dispatch($task, $event->start);
75-
})
76-
->sendOutputTo(storage_path($task->getMutexName()));
77-
if ($task->dont_overlap) {
78-
$event->withoutOverlapping();
79-
}
80-
if ($task->run_in_maintenance) {
81-
$event->evenInMaintenanceMode();
82-
}
83-
});
84-
}
8520
}

src/Notifications/TaskCompleted.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Notifications\Messages\MailMessage;
99
use Illuminate\Notifications\Messages\NexmoMessage;
1010
use Illuminate\Notifications\Messages\SlackMessage;
11+
use Illuminate\Notifications\Messages\SlackAttachment;
1112

1213
class TaskCompleted extends Notification implements ShouldQueue
1314
{
@@ -59,23 +60,8 @@ public function toMail($notifiable)
5960
return (new MailMessage)
6061
->subject($notifiable->description)
6162
->greeting('Hi,')
62-
->line("We just finished running your task. {$notifiable->description}")
63-
->line($this->output)
64-
->line('Your Truly,')
65-
->line('Laravel Totem');
66-
}
67-
68-
/**
69-
* Get the array representation of the notification.
70-
*
71-
* @param mixed $notifiable
72-
* @return array
73-
*/
74-
public function toArray($notifiable)
75-
{
76-
return [
77-
//
78-
];
63+
->line("{$notifiable->description} just finished running.")
64+
->line($this->output);
7965
}
8066

8167
/**
@@ -99,6 +85,11 @@ public function toNexmo($notifiable)
9985
public function toSlack($notifiable)
10086
{
10187
return (new SlackMessage)
102-
->content($notifiable->description.' just finished running.');
88+
->content(config('app.name'))
89+
->attachment(function (SlackAttachment $attachment) use ($notifiable) {
90+
$attachment
91+
->title('Totem Task')
92+
->content($notifiable->description.' just finished running.');
93+
});
10394
}
10495
}

0 commit comments

Comments
 (0)