Laravel: 5.6.28
Horizon: v1.3.1
OS: MacOS High Sierra 10.13.5
APP_ENV: local
Mail driver: Mailhog
<?php
return [
'use' => 'default',
'prefix' => env(
'HORIZON_PREFIX',
str_slug(
env('APP_NAME', 'Laravel'),
'-'
).'-horizon:'
),
'waits' => [
'redis:default' => 10,
],
'trim' => [
'recent' => 60,
'failed' => 10080,
],
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default', 'media_queue'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
'local' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default', 'media_queue'],
'balance' => 'simple',
'processes' => 3,
'tries' => 3,
],
],
],
'slack' => [
'webhook_url' => env('HORIZON_SLACK_WEBHOOK_URL'),
'channel' => env('HORIZON_SLACK_CHANNEL'),
],
];
<?php
namespace App\Providers;
use Illuminate\Http\Request;
use Laravel\Horizon\Horizon;
use Illuminate\Support\ServiceProvider;
class HorizonServiceProvider extends ServiceProvider
{
public function boot()
{
Horizon::routeMailNotificationsTo(config('mail.support'));
Horizon::routeSlackNotificationsTo(
config('horizon.slack.webhook_url'),
config('horizon.slack.channel')
);
Horizon::auth(function (Request $request) {
return auth('admin')->check();
});
}
}
[email protected]
HORIZON_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
HORIZON_SLACK_CHANNEL=#general //also tried without hash tag
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class TestJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
while (true) {} //or sleep(5 * 60)
}
}
Tried to launch job by test route:
Route::get('test', function () {
\App\Jobs\TestJob::dispatch();
});
and from the tinker
Expected behavior: after 10 seconds of job processing notification should be send to _Mail_ and _Slack_ chennels
Actual behavior: Nothing happens
Maybe I misunderstood something about jobs long wait time notifications?
Heya! Thanks for sending this in. I had to search for this myself for a bit but it turns out we both misunderstood how this works. First of all, this has nothing to do with individual running jobs. Horizon makes a determination of how long it will take to process all of the jobs on the queue and when it sees that the queue will take a long time it will alert you so you can take action (scale, assign more queues/capacity, etc).
So the above example actually can't reproduce this. You'd have to overload your queue with jobs so it would take Horizon a long time to process them and then you'd be able to get a notification.
Hope this explanation helps!
Got it, thanks for the detailed explanation!
HORIZON_SLACK_CHANNEL=#general //also tried without hash tag --> change to HORIZON_SLACK_CHANNEL="#general"
Most helpful comment
Heya! Thanks for sending this in. I had to search for this myself for a bit but it turns out we both misunderstood how this works. First of all, this has nothing to do with individual running jobs. Horizon makes a determination of how long it will take to process all of the jobs on the queue and when it sees that the queue will take a long time it will alert you so you can take action (scale, assign more queues/capacity, etc).
So the above example actually can't reproduce this. You'd have to overload your queue with jobs so it would take Horizon a long time to process them and then you'd be able to get a notification.
Hope this explanation helps!