-
Hi all, First time posting here so if I am at the wrong place, please let me know :-) Currently, when running [2021-10-06 09:38:35][JtANf66QJ5qibMl9zDRwZdpXbblE0asO] Processing: App\Jobs\MyJob
[2021-10-06 09:38:35][JtANf66QJ5qibMl9zDRwZdpXbblE0asO] Processed: App\Jobs\MyJob What I would wantI want to change the output and move it to JSON output. JSON output because our logging system (DataDog) can then index it better and we can query DataDog in a way we want. What I've tried
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Queue\Console\WorkCommand;
class MyWorkCommand extends WorkCommand
{
} I register the command in [2021-10-06T09:47:58.728967+00:00] local.ERROR: Unresolvable dependency resolving [Parameter #3 [ <required> callable $isDownForMaintenance ]] in class Illuminate\Queue\Worker {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Unresolvable dependency resolving [Parameter #3 [ <required> callable $isDownForMaintenance ]] in class Illuminate\\Queue\\Worker at /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:1053)"} [] This is being caused by the constructor of the /**
* Create a new queue work command.
*
* @param \Illuminate\Queue\Worker $worker
* @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
public function __construct(Worker $worker, Cache $cache)
{
parent::__construct();
$this->cache = $cache;
$this->worker = $worker;
}
In $this->app->singleton('command.queue.work', function ($app) {
return new WorkOutputJsonCommand($app['queue.worker'], $app['cache.store']);
}); My use Illuminate\Contracts\Queue\Job;
use Illuminate\Queue\Console\WorkCommand;
use Illuminate\Support\Carbon;
class WorkOutputJsonCommand extends WorkCommand
{
public function writeStatus(Job $job, $status, $type)
{
$this->output->writeln(sprintf(
"<{$type}>[%s][%s] hello testing %s</{$type}> %s",
Carbon::now()->format('Y-m-d H:i:s'),
$job->getJobId(),
str_pad("{$status}:", 11), $job->resolveName()
));
}
} This however doesn't work as well unfortunately. dump(self::class . '::' . __FUNCTION__); When I run "App\Providers\AppServiceProvider::boot"
"Illuminate\Foundation\Providers\ArtisanServiceProvider::registerQueueWorkCommand" This tells me that my AppServiceProvider is being loaded before the ArtisanServiceProvider. However, in How can I achieve what I want? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Using laravel 8.18.1, by the way. |
Beta Was this translation helpful? Give feedback.
-
For future reference: I was able to solve this via this way:
class JobAggregateServiceProvider extends AggregateServiceProvider implements DeferrableProvider
{
/**
* The provider class names.
*
* @var string[]
*/
protected $providers = [
BackgroundWorkerServiceProvider::class
];
}
class BackgroundWorkerServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->singleton('command.queue.work', function ($app) {
return new WorkOutputJsonCommand($app['queue.worker'], $app['cache.store'], $app['log']);
});
}
public function provides(): array
{
return ['command.queue.work'];
}
} Via this way, you are able to override the queue worker. |
Beta Was this translation helpful? Give feedback.
For future reference:
I was able to solve this via this way:
AggregateServiceProvider
:BackgroundWorkerServiceProvider
class: