I have this code on my controller.
// Queue job, Send notification
ExportCsvJob::dispatch(json_encode($exportdata))
->onConnection('database')
->onQueue('default');
.env file
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
config/queue.php
return [
'default' => env('QUEUE_DRIVER', 'sync'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
],
],
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
but when running php artisan queue:work --timeout=3600 never do anything,
I have this two records in jobs table
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
| id | queue | payload | attempts | reserved_at | available_at | created_at |
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
| 168 | shipment_export | {"displayName":"App\\Jobs\\ExportCsvJob","job":"Illuminate\\Queue\\CallQueuedHandler#call","maxTries | 0 | NULL | 1549262600 | 1549262600 |
| 169 | default | {"displayName":"App\\Jobs\\ExportCsvJob","job":"Illuminate\\Queue\\CallQueuedHandler#call","maxTries | 0 | NULL | 1549262834 | 1549262834 |
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
but when I changed QUEUE_DRIVER=sync to QUEUE_DRIVER=database It worked
Can give me explanation and possibly solution about my problem?
Related
I tried to implement Horizon, from the terminal when I run commands like php artisan horizon:status or php artisan horizon:list I get positive feedbacks, everything seems to work just fine, but when I try to go to the /horizon view, no matter how many jobs I tried to run, in the dashboard I get this.
If I open the console from the browser I get Failed to load resource: the server responded with a status of 500 (Internal Server Error) on all the API calls like api/masters, api/stats or api/workload.
Searching online I found a lot of people saying to fix the .env file or the configuration files like queue.php or horizon.php, but after following their instructions my problem persists
.env:
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
APP_ENV=local
APP_DEBUG=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql
# Redis
REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
queue.php:
<php?
return [
'default' => env('QUEUE_CONNECTION', 'redis'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 0,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'your-queue-name'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
],
],
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];
horizon.php:
<?php
use Illuminate\Support\Str;
return [
'domain' => env('HORIZON_DOMAIN'),
'path' => env('HORIZON_PATH', 'horizon'),
'use' => 'default',
'prefix' => env(
'HORIZON_PREFIX',
Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
),
'middleware' => ['web'],
'waits' => [
'redis:default' => 60,
],
'trim' => [
'recent' => 60,
'pending' => 60,
'completed' => 60,
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
],
'metrics' => [
'trim_snapshots' => [
'job' => 24,
'queue' => 24,
],
],
'fast_termination' => false,
'memory_limit' => 64,
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'maxProcesses' => 1,
'maxTime' => 0,
'maxJobs' => 0,
'memory' => 128,
'tries' => 1,
'timeout' => 60,
'nice' => 0,
],
],
'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
],
'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
];
I am trying to use laravel broadcast with pusher but my socket is showing null.
my env file
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
PUSHER_APP_ID=12345
PUSHER_APP_KEY=ABCDEFG
PUSHER_APP_SECRET=HKLMNOP
PUSHER_APP_CLUSTER=mt1
PUSHER_APP_HOST=127.0.0.1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
in your broadcasting.php did you set 'options' => [ 'cluster' => '', 'encrypted' => true ], your broadcasting.php should look like below
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'null'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap2',
'encrypted' => true
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
I'm using Laravel 6.0.4. I was asked to logout users from all devices whenever they log in from a new location. Supposedly, Laravel makes this very easy with this:
https://laracasts.com/series/whats-new-in-laravel-5-6/episodes/7
public function logoutOtherDevices($password, $attribute = 'password'){ ... }
I can see that the code changes the password hash in the database, but the user is still logged in. So it must be that somewhere in the code I am failing to check that the hash has changed. I'm not an expert, perhaps this is an issue related to guards? Our system has four guards. Could it be that some of the guards are not being authenticated correctly? That the guard is not using the hash from the database but some other system?
So, how do I figure out why Laravel isn't logging people out from other devices? I will share config data if you want, just ask me which data to post
Auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'staff' => [
'driver' => 'session',
'provider' => 'staff'
],
'partner' => [
'driver' => 'session',
'provider' => 'partner'
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'partner' => [
'driver' => 'eloquent',
'model' => \App\Models\Partner::class,
],
'staff' => [
'driver' => 'eloquent',
'model' => \App\Models\Staff::class
],
'users' => [
'driver' => 'database',
'table' => 'users',
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
'partner' => [
'provider' => 'partner',
'table' => 'password_resets',
'expire' => 60,
],
'staff' => [
'provider' => 'staff',
'table' => 'password_resets',
'expire' => 60,
]
],
session.php
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => env('SESSION_CONNECTION', null),
'table' => 'sessions',
'store' => env('SESSION_STORE', null),
'lottery' => [2, 100],
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
),
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true,
'same_site' => null,
What does the 'queue' => 'default' setting do at config/queue.php?
It seems like it does not affect anything.
In config/queue.php my queue configuration is ga-fetcher-queue.
This is my config:
return [
'default' => 'redis',
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'ga-fetcher-queue',
'retry_after' => 360,
],
],
'failed' => []
];
My redis config at config/database.php is this:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
]
I used redis for task queue in laravel, i want to use connection name per queue to handle config varibales conflict in queue in below code :
php artisan queue:work connection-name --deamon --queue=high,medium,low --sleep=3 --tries=3
But i dont know what is the connection name in below code to use:
'default' => env('QUEUE_DRIVER', 'redis'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
],
You have several connections configured.
Each connection is an element in the connections array and you just need to pass the relevant key as the name.
e.g.
php artisan queue:work sqs --daemon --queue=high --sleep=3 --tries=3