-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Laravel Horizon, test tasks, and jobs, along with minor improve…
…ments
- Loading branch information
1 parent
c3d9283
commit e985f76
Showing
26 changed files
with
1,359 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Run our defined exec if args empty | ||
if [ -z "$1" ]; then | ||
|
||
: ${CONTAINER_MODE:='manual'} | ||
: ${CONTAINER_ROLE:='app'} | ||
: ${APP_ENV:='production'} | ||
artisan="php -d variables_order=EGPCS /var/www/html/artisan" | ||
|
||
if [ "$CONTAINER_MODE" = "automatic" ]; then | ||
echo "Preparing application..." | ||
chown -R nobody:nobody /var/www/html/storage | ||
php artisan storage:link || true | ||
php artisan config:cache || true | ||
php artisan migrate --force || true | ||
fi | ||
|
||
if [ "$CONTAINER_ROLE" = "app" ]; then | ||
|
||
echo "INFO: Running octane..." | ||
exec $artisan octane:start --server=frankenphp --host=0.0.0.0 --port=8000 | ||
|
||
elif [ "$CONTAINER_ROLE" = "worker" ]; then | ||
|
||
echo "INFO: Running the queue..." | ||
exec $artisan queue:work -vv --no-interaction --tries=3 --sleep=5 --timeout=300 --delay=10 | ||
|
||
elif [ "$CONTAINER_ROLE" = "horizon" ]; then | ||
|
||
echo "INFO: Running the horizon..." | ||
exec $artisan horizon | ||
|
||
elif [ "$CONTAINER_ROLE" = "scheduler" ]; then | ||
|
||
while true; do | ||
if [ -d "/var/www/html/vendor" ] ; then | ||
echo "INFO: Running scheduled tasks." | ||
exec $artisan schedule:run --verbose --no-interaction & | ||
else | ||
echo "WARNING: Directory /var/www/html/vendor does not yet exist." | ||
fi | ||
sleep 60s | ||
done | ||
|
||
else | ||
echo "Could not match the container role \"$CONTAINER_ROLE\"" | ||
exit 1 | ||
fi | ||
|
||
else | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\CreateTextFile; | ||
use Illuminate\Console\Command; | ||
|
||
class ProcessTextFile extends Command | ||
{ | ||
protected $signature = 'process:textfile'; | ||
|
||
protected $description = 'Process text file by triggering a job'; | ||
|
||
public function handle() | ||
{ | ||
dispatch(new CreateTextFile()); | ||
$this->info('Text file processing job pushed to the queue.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class TestTask extends Command | ||
{ | ||
protected $signature = 'test:task'; | ||
|
||
protected $description = 'Test task executed every minute'; | ||
|
||
public function handle() | ||
{ | ||
$message = 'Hello, this is a test task running at ' . now(); | ||
Log::info($message); | ||
$this->info('Task executed successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class CreateTextFile implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function handle() | ||
{ | ||
sleep(rand(5, 30)); | ||
|
||
$filePath = 'local/textfile.txt'; | ||
$content = 'Date and Time: ' . now() . "\n"; | ||
|
||
// Append existing content if file exists | ||
if (Storage::exists($filePath)) { | ||
$existingContent = Storage::get($filePath); | ||
$content .= $existingContent; | ||
} | ||
|
||
// Write content to the file | ||
Storage::put($filePath, $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Support\Facades\Gate; | ||
use Laravel\Horizon\Horizon; | ||
use Laravel\Horizon\HorizonApplicationServiceProvider; | ||
|
||
class HorizonServiceProvider extends HorizonApplicationServiceProvider | ||
{ | ||
/** | ||
* Bootstrap any application services. | ||
*/ | ||
public function boot(): void | ||
{ | ||
parent::boot(); | ||
|
||
// Horizon::routeSmsNotificationsTo('15556667777'); | ||
// Horizon::routeMailNotificationsTo('[email protected]'); | ||
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel'); | ||
} | ||
|
||
/** | ||
* Register the Horizon gate. | ||
* | ||
* This gate determines who can access Horizon in non-local environments. | ||
*/ | ||
protected function gate(): void | ||
{ | ||
Gate::define('viewHorizon', function ($user) { | ||
return in_array($user->email, [ | ||
// | ||
]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.