Laravel Queue not work - php

I used laravel 5 and Queue. try this
$job = (new InstallTheme())->onQueue('install_theme')->delay(20);
dispatch($job);
not work
$job = (new InstallTheme())->delay(20);
dispatch($job);
work
Why the first option does not work?
upd
laravel work only if fuild "queue" in table 'jobs' = default
how to fix this?
i think setting queue.php ?
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],

As I recall
$job = (new InstallTheme())->onQueue('install_theme')->delay(20);
dispatch($job);
puts the job into the install_theme queue while your other code puts it into the default queue. Please try to run the queue worker with this parameters.
php artisan queue:work --queue=install_theme
This should specifically process the job from this queue.

Related

Laravel horizon queued jobs fails with MaxAttemptsExceededException

I dispatch jobs to do some work on my horizon queue. It appears the same jobs are always failing with 60s runtime, which to me looks like a timeout issue:
I dispatch around 10 jobs via a cron schedule, and these 4 are always failing.
This is my config/horizon.php (just the interesting parts):
<?php
use Illuminate\Support\Str;
return [
'waits' => [
'redis:default' => 60,
],
'memory_limit' => 512,
'defaults' => [
'my-app-queue' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 1,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'memory' => 512,
'tries' => 3,
'nice' => 0,
'timeout' => 300,
],
],
'environments' => [
'production' => [
'my-app-queue' => [
'maxProcesses' => 10,
],
],
'local' => [
'my-app-queue' => [
'maxProcesses' => 10,
],
],
],
];
As you can see, I have set a timeout of 300 seconds, but the job always failing at 60 second mark.
I start the horizon queue processor in my docker container with this entrypoint command: php /path/to/artisan horizon
To debug the issue, I instantiated the job class manually to see where it is failing like this:
$test = new DownloadBlockedIPFeed(8);
$test->handle();
exit('Done');
This does seem to be taking longer than 60 seconds, but it does complete.
So my question is - how do you properly set the timeout for laravel horizon?
I am using laravel 8.x and latest version of the horizon package.
It may also be the balance strategy. I've found that If I set the 'balance' option to 'auto', it gives the MaxAttemptsExceededException errors. changing it to 'simple' or 'false' seems to be the solution.
Not sure if this is a bug, but I don't think this is expected behavior either. I've seen jobs that where executed (logging in the handle method of the job) but killed off in the middle for retry.
Check the value for --timeout= in the spawned horizon:supervisor process. If this is 60 seconds, adjust the timeout value in config/horizon.php.
Also check retry_after in config/queue.php.

Botman conversation cache time not working

BotMan Version: 2.6
PHP Version: 7.3.23
Laravel Version : 7.16.1
Cache Driver: LaravelCache
i'm using botman for telegram bot.
everything is ok with botman just the conversation cache time is not working.
this is my botman Configuration code :
use BotMan\BotMan\Cache\LaravelCache;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\BotManFactory;
$config = [
// Your driver-specific configuration
"botman" => [
'conversation_cache_time' => 720 ,
'user_cache_time' => 720,
],
"telegram" => [
"token" => env('TELEGRAM_TOKEN'),
]
];
// Load the driver(s) you want to use
DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
// Create an instance
$botman = BotManFactory::create($config, new LaravelCache());
// and other hears , fallback and conversations functions ...
every thing about the bot and conversations is fine , but the problem is about the conversation cash time
base on the conversation document we have to use drive cache to use conversations and the driver i'm using is laravelCache but i set conversation_cache_time to 720 minute but it just takes the default 30 minute.
what should i do?
thanks in advance.
From these lines in their github:
https://github.com/botman/botman/blob/79310f6e6464436aaa2d0522267b2ca00a07fda5/tests/BotManConversationTest.php#L79-L83
https://github.com/botman/botman/blob/4ec6e3f30d620cbcb73a0cf8e1dbf6b34e47f75d/src/Traits/HandlesConversations.php#L47
https://github.com/botman/botman/blob/203e7f5ef68473dd4d71ca7ee31275eae9a92745/src/BotMan.php#L238-L239
It must be like these:
$config = [
'user_cache_time' => 720,
'config' => [
'conversation_cache_time' => 720 ,
],
// Your driver-specific configuration
"telegram" => [
"token" => env('TELEGRAM_TOKEN'),
]
];
and it works.

Laravel Guzzle Request gets wrong DB Connection

I am trying to make a request from one Laravel project to another. The issue that I am getting is that the second Laravel is using the first Laravel Database Connection. So it is complaining that a table does not exist.
Here is the code that I am using.
$data = ['test' => 'foobar'];
$client = new \GuzzleHttp\Client();
$url = getenv('API_BASE') . 'stock-list';
$res = $client->request('POST', $url, [
'headers' => [
'X-Public' => getenv('API_PUBLIC'),
'X-Hash' => ApiService::Encrypt(getenv('API_PRIVATE'), json_encode($data)),
],
'json' => $data,
'http_errors' => false,
]);
echo "<pre>" . print_r($res->getBody()->getContents(), true) . "</pre>";
Has anyone ever come across something like this?
The way to fix this as I am running both Laravel projects on the same server, is to change the environment variable names in the .env file.
DB_DATABASE=XXXX
becomes
XXX_DB_DATABASE=XXXX
This needs to be done on one of the Laravel setups then it all works properly.
You can change the default db connection runtime like this:
So let's say you have
1 security db with credentials that is the default db design time.
1 or more databases containing data for 1 or more users.
You log in using the security db and based on the user change the default db to the data db.
config(['database.connections.data' => array(
'driver' => 'sqlsrv',
'host' => $connection['Database_Server'],
'database' => $connection['Database_Name'],
'username' => $connection['Database_User'],
'password' => $connection['Database_Password']
)]);
DB::setDefaultConnection('data');
If you don't need such flexibility you can define the connection per model:
class A extends Model {
protected $connection = 'security';
protected $table = 'A';
}

customising Job and job table in Laravel queue/ rename jobs table

When I try php artisan queue:table
It gave me the following error
[InvalidArgumentException]
A CreateJobsTable migration already exists.
It is because I have already the migration named CreateJobsTable for other purpose. I cannot rename this table and migration . Is there any way to rename the migration to CreateJobsQueueTable or some thing relevant?
can we rename the jobs table that artisan creates with 'queue:table'?
Yes. Edit this file config\queue.php:
<?php
return [
....
'connections' => [
....
'database' => [
'driver' => 'database',
'table' => 'jobs', <------ Edit this to something else
'queue' => 'default',
'retry_after' => 90,
],
....
],
....
];
Change the table name to other value, and it should pick up by the TableCommand. Check out Illuminate\Queue\Console\TableCommand on how it uses this value. It's pretty much straightforward :)

Laravel Mail::queue not async

I have a problem with laravel 5.1 queues.
I have beanstalkd already set up in my Homestead vm so all i did was to change the queue driver from the default one to beanstalkd in config/queue.php. I've tried the code below and neither one seem to be queued. They all fired synchronously, as soon as i run the code. I didn't even fire the artisan queue:listen command. What am i doing wrong?
Route::get('/', function () {
// return view('welcome');
Queue::push(function($job)
{
Log::info("Dadas");
$job->delete();
});
$input = [
'name' => 'Mario Bašić',
'email' => 'email#me.com',
'comment' => 'Testing queues',
'subject' => 'Email subject'
];
Mail::queue('emails.test', $input, function($message) use ($input)
{
$message->to($input['email'], $input['name']);
$message->subject($input['subject']);
Log::info('sending');
});
});
Make sure you change the driver in the .env file:
QUEUE_DRIVER=beanstalkd
Changing the value in the config/queue.php to:
'default' => env('QUEUE_DRIVER', 'beanstalkd'),
won't work if another value is set for QUEUE_DRIVER in .env.

Categories