Skip to content

Commit 596452d

Browse files
add support for run in background (#263)
* add support for run in background Co-authored-by: Jay Fletcher <[email protected]>
1 parent 2230103 commit 596452d

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Support\Facades\Schema;
5+
use Studio\Totem\Database\TotemMigration;
6+
7+
class AlterTasksTableAddRunInBackgroundSupport extends TotemMigration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::connection(TOTEM_DATABASE_CONNECTION)
17+
->table(TOTEM_TABLE_PREFIX.'tasks', function (Blueprint $table) {
18+
$table->boolean('run_in_background')->default(false);
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::connection(TOTEM_DATABASE_CONNECTION)
30+
->table(TOTEM_TABLE_PREFIX.'tasks', function (Blueprint $table) {
31+
$table->dropColumn('run_in_background');
32+
});
33+
}
34+
}

resources/views/tasks/form.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
<li class="uk-text-meta">Decide whether multiple instances of same task should overlap each other or not.</li>
191191
<li class="uk-text-meta">Decide whether the task should be executed while the app is in maintenance mode.</li>
192192
<li class="uk-text-meta">Decide whether the task should be executed on a single server.</li>
193+
<li class="uk-text-meta">Decide whether the task should be executed in the background.</li>
193194
</ul>
194195
</div>
195196
<div class="uk-width-1-1@s uk-width-2-3@m uk-form-controls-text">
@@ -213,6 +214,13 @@
213214
Run on a single server
214215
</label>
215216
</div>
217+
<div class="uk-margin">
218+
<label class="uk-margin">
219+
<input type="hidden" name="run_in_background" id="run_in_background" value="0" {{old('run_in_background', $task->run_in_background) ? '' : 'checked'}}>
220+
<input type="checkbox" name="run_in_background" id="run_in_background" value="1" {{old('run_in_background', $task->run_in_background) ? 'checked' : ''}}>
221+
Run in the background
222+
</label>
223+
</div>
216224
</div>
217225
</div>
218226
<hr class="uk-divider-icon">

resources/views/tasks/view.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<span class="uk-float-left">Runs on a single server</span>
7777
</li>
7878
@endif
79+
@if($task->run_in_background)
80+
<li>
81+
<span class="uk-float-left">Runs in the background</span>
82+
</li>
83+
@endif
7984
</ul>
8085
@stop
8186
@section('main-panel-footer')

src/Console/Commands/ListSchedule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ public function handle()
6060
'overlaps' => $event->withoutOverlapping ? 'No' : 'Yes',
6161
'maintenance' => $event->evenInMaintenanceMode ? 'Yes' : 'No',
6262
'one_server' => $event->onOneServer ? 'Yes' : 'No',
63+
'in_background' => $event->runInBackground ? 'Yes' : 'No',
6364
];
6465
});
6566

6667
$this->table(
67-
['Description', 'Command', 'Schedule', 'Upcoming', 'Timezone', 'Overlaps?', 'In Maintenance?', 'One Server?'],
68+
['Description', 'Command', 'Schedule', 'Upcoming', 'Timezone', 'Overlaps?', 'In Maintenance?', 'One Server?', 'In Background?'],
6869
$events
6970
);
7071
} else {

src/Providers/ConsoleServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function schedule(Schedule $schedule)
5353
if ($task->run_on_one_server && in_array(config('cache.default'), ['memcached', 'redis'])) {
5454
$event->onOneServer();
5555
}
56+
if ($task->run_in_background) {
57+
$event->runInBackground();
58+
}
5659
});
5760
}
5861
}

src/Task.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Task extends TotemModel
3636
'auto_cleanup_type',
3737
'auto_cleanup_num',
3838
'run_on_one_server',
39+
'run_in_background',
3940
];
4041

4142
/**

0 commit comments

Comments
 (0)