I'm using Laravel 5.4 and PHP 7.0.
I have a lot of failed jobs in the table that I want to re-queue. I have written a script to go through a list of IDs that I pulled from the database and I want a foreach to re-queue each one. Pretty simple stuff.
My issue is that when I run
foreach($jobsToRetry as $failedJob) {
Artisan::call('queue:retry '.$failedJob);
}
I receive the following error:
Command "queue:retry 1" is not defined.
Did you mean one of these?
queue:failed
queue:failed-table
queue:flush
queue:forget
queue:listen
queue:restart
queue:retry
queue:table
queue:work
It needs to be using the command "queue:retry" and have the parameter separate but I just can't figure out how to get that to work.
Give the parameter in the arguments
Artisan::call('queue:retry', ['id' => $failedJob]);
You should try this:
Artisan::call('queue:retry', ['--yourparameter' => $failedJob]);
Related
in my Symfony 5.1 project I am trying to declare my own task which I would like to use when deploying. I created it like this:
task('update_database', function () {
if($_ENV['DATABASE_URL'])
{
cd('{{release_path}}');
writeln('<info>Updating database</info>');
run('{{bin/php}} {{bin/console}} d:d:c --if-not-exists');
run('{{bin/php}} {{bin/console}} doctrine:schema:update --force');
}
})->desc('Make database updates');
The "cd" and the "writeln" work. But every time I try to run a command it always fails
I tried with just the command php bin/console instead of using {{bin/php}} {{bin/console}}.
I even tried a silly php bin/console cache:clear command to see, but same error.
Yet I am in the right directory.. I followed this tutorial https://www.codepicky.com/php-automatic-deploy/
And I do the exact same thing though
UPDATE :
I connected to my server, I went to the last release of my project, and when I tried commands, absolutely nothing was happening. No mistake, but they didn't do anything. Even if I try the command to create an entity, it is "ignored".
The -vvv flag didn't give anything either
Here is what I have in the console:
I've did some changes in my config/app to use multiple databases selected by front-end,
now I have to tell in \Request()->header('database') which database I want access.
It's work perfectly, the problem is: when I try to do any artisan commands my logic dies, because isn't informed the database.
So I need to inform the database in artisan commands, like that:
php artisan migrate --database=sandiego_school
php artisan migrate:rollback --database=newyork_school
How can I observer all commands to get the argument?
In this case I guess you should create your own commands that overrides the commands you want to call, then in the handle method of the command you could specify the connexion you want to work on:
\DB::setDefaultConnection($connexion);
or also you can simply add header to request:
request()->headers->set('database', $dbname)
I'd like to create a php script which connects to a mysql server, makes changes on a database and runs a php artisan command.
The first part I have figured out (mysql connection) but is it possible to just put (for example):
php artisan snipeit:ldap-sync --location_id=1
into my script and it will run the command, or am I missing something here?
I'd appreciate it if you could send me into the right direction wtih this. Thank you.
You can use Artisan::call().
Artisan:call('snipeit:ldap-sync', [
'--location_id' => 1
]);
It can also take a second parameter to specify an array of command parameters.
For more information, see Programmatically Executing Commands.
You can call artisan command from code like this:
Artisan::call('cache:clear');
The Situation
I'm using Laravel Queues to process large numbers of media files, an individual job is expected to take minutes (lets just say up to an hour).
I am using Supervisor to run my queue, and I am running 20 processes at a time. My supervisor config file looks like this:
[program:duplitron-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/duplitron/artisan queue:listen database --timeout=0 --memory=500 --tries=1
autostart=true
autorestart=true
user=duplitron
numprocs=20
redirect_stderr=true
stdout_logfile=/var/www/duplitron/storage/logs/duplitron-worker.log
In my duplitron-worker.log I noticed Failed: Illuminate\Queue\CallQueuedHandler#call occurs occasionally and I would like to better understand what exactly is failing. Nothing appears in my laravel.log file (which is where exceptions would normally appear).
The Question
Is there a handy way for me to learn more about what is causing my job to fail?
In the newer Laravel versions there's an exception column in the failed_jobs table that has all the info you need. Thanks cdarken and Toskan for pointing this out!
==== OLD METHOD BELOW
Here's what I always do, but first - make sure you have a failed-jobs table! It's well documented, look it up :)
Run the php artisan queue:failed command to list all the failed jobs, and pick the one you're after. Write the ID down.
Then, make sure to stop your queue with supervisorctl stop all duplitron-worker:
Lastly, make sure your .env setting for APP_DEBUG = true.
Then run php artisan queue:retry {step_job_1_id}
Now manually runphp artisan queue:listen --timeout=XXX
If the error is structural (and most are), you should get the failure with debug stack in your log file.
Good luck with debugging :-)
as #cdarken pointed out, the exception can be found in your database table failed_jobs column name exception. Thanks #cdarken I wish his answer would be an answer and not a comment.
Run these command to create a table failed_jobs in db
php artisan queue:failed-table
php artisan migrate
Run queue worker php artisan queue:work --tries=2
Check the exception reason in your database table failed_jobs you've just created.
If you're using database than goto failed_jobs table and look for the exception there.
Worked for me,
in vendor/laravel/framework/src/Illuminate/Notifications/SendQueuedNotifications.php
Just remove "use Illuminate\Queue\SerializesModels;" Line 6
& modify Line 11 to "use Queueable;"
I have a queue I set up in Laravel 5 to delete companies and associated records. Each time this happens, a lot of work happens on the back-end, so queues are my best option.
I set up my config/queue.php file along with my .env file so that the database driver will be used. I am using the Queue::pushOn method to push jobs onto a queue called company_deletions. Ex.
Queue::pushOn('company_deletions', new CompanyDelete($id));
Where CompanyDelete is a command created with php artisan command:make CompanyDelete --queued
I have tried to get my queue to process using the following commands:
php artisan queue:work
php artisan queue:work company_deletions
php artisan queue:listen
php artisan queue:listen company_deletions
php artisan queue:work database
php artisan queue:listen database
Sometimes when looking at the output of the above commands, I get the following error:
[InvalidArgumentException]
No connector for []
Even when I don't get an error I cannot get it to actually process the jobs for some reason. When I look in my jobs table, I can see the job on the queue, however the attempts column shows 0, reserved shows 0 and reserved_at is null. Am I missing some steps? I have looked over the documentation several times and cannot for the life of me figure out what is wrong. I don't see anything in the laravel error logs either. What would prevent these jobs from being processed once they are in the jobs database? Any help is appreciated.
i run into a smiliar issue because i dont add the jobs in the default queue..
$job = (new EmailJob(
$this->a,
$this->b,
$this->c,
$this->d,
$e
))->onQueue('emails');
then i have to listen to the specific queue:
php artisan queue:listen --queue=emails
in your case it would be
php artisan queue:listen --queue=company_deletions