ronon

ronon

Member Since 2 Years Ago

Experience Points
25,450
Total
Experience

4,550 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
194
Lessons
Completed
Best Reply Awards
3
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 6
25,450 XP
Jan
09
1 week ago
Activity icon

Awarded Best Reply on Mocking A File In A Storage For A PHPUnit Test?

You could also use

$file = UploadedFile::fake()->create('image.jpg')
        ->storeAs('app/images', newfilename.jpg)');

With this you could also create any kind of formats like pdf etc.

Activity icon

Replied to Mocking A File In A Storage For A PHPUnit Test?

You could also use

$file = UploadedFile::fake()->create('image.jpg')
        ->storeAs('app/images', newfilename.jpg)');

With this you could also create any kind of formats like pdf etc.

Nov
29
1 month ago
Activity icon

Replied to Long Running Queues Fails And Executes Successfully At The Same Time

Seems not to be a memory issue. I modified the function that throws the exception to log whats happening:

protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $job, $maxTries)
    {
        $maxTries = ! is_null($job->maxTries()) ? $job->maxTries() : $maxTries;

        $timeoutAt = $job->timeoutAt();

        Log::debug('timeout at: ' . ($timeoutAt ?? 'not set') . ' - timeout ' . $job->timeout() .
                    ' - max tries: ' . $maxTries . ' - attempts: ' . $job->attempts());

        if ($timeoutAt && Carbon::now()->getTimestamp() <= $timeoutAt) {
            return;
        }

        if (! $timeoutAt && ($maxTries === 0 || $job->attempts() <= $maxTries)) {
            return;
        }

        Log::error('Throw exception... timeout at: ' . ($timeoutAt ?? 'not set') . ' - timeout ' . $job->timeout() .
            ' - max tries: ' . $maxTries . ' - attempts: ' . $job->attempts());

        $this->failJob($job, $e = new MaxAttemptsExceededException(
            $job->resolveName().' has been attempted too many times or run too long. The job may have previously timed out.'
        ));

        throw $e;
    }

This is in the log:

[2019-11-29 00:31:27] production.DEBUG: timeout at: not set - timeout 0 - max tries: 1 - attempts: 1
[2019-11-29 00:31:28] production.DEBUG: timeout at: not set - timeout 0 - max tries: 1 - attempts: 2
[2019-11-29 00:31:28] production.ERROR: Throw exception... timeout at: not set - timeout 0 - max tries: 1 - attempts: 2

It seems that the attempts is increased without any reason. Have to dig further to see why the attempts are increased :/

Nov
27
1 month ago
Activity icon

Replied to Long Running Queues Fails And Executes Successfully At The Same Time

@talinon Yes all workers have been restarted after the change.

Will take a look at sar. Maybe it's really an memory issue.

Diskspace is monitored and is configured to not fill the disk only to a certain limit

Nov
21
1 month ago
Activity icon

Replied to Long Running Queues Fails And Executes Successfully At The Same Time

@talinon sorry for the late response. I tried different Settings without success.

eg. I trief tondet the timeout to 86400 seconds, and the first 2 jobs failed exactly after 6 minutes and 1 seconds. The others seemed to run longer. It confuses me more and more...

Nov
15
2 months ago
Activity icon

Replied to Deleteing Data From Multiple Tables Depending Relationship In Laravel Vuejs Api

I would go for the same solution as @goldtaste .

But if you just want to remove particular ones and change the parent you could go with the static::deleting event. You could then update the specific childs and remove the other ones, before the parent gets deleted

Nov
05
2 months ago
Activity icon

Replied to Long Running Queues Fails And Executes Successfully At The Same Time

retry_after in config/queue.php is set to 90 on each connection. We're using beanstalkd by the way.

As far as I remember is had it to set to 1, since zero wasn't a valid value. (Not sure about this to be honest).

I guess we would have to set it to about 24hours then. Since we cannot tell how long an encoding job is running. The longest I saw was about 12 hours :/

Nov
04
2 months ago
Activity icon

Replied to Long Running Queues Fails And Executes Successfully At The Same Time

@talinon I'm using this library https://github.com/PHP-FFMpeg/PHP-FFMpeg to encode videos.

I checked the max_exectuion_time and it's set to 30 seconds. Since the job is failing much later then 30 seconds, I assume that the max_execution_time time in the php.ini doesn't has an impact.

I also checked the timespan between start and failure. Here are some startdates and failure dates:

| Id       | Starttime of Worker   | Starttime of enc process    |  Faildate |
| -------- |:---------------------:|:---------------------:| ---------------------:|
| 1  | [2019-11-04 21:08:29] | [2019-11-04 21:26:41] | [2019-11-04 22:08:19] |
| 2  | [2019-11-04 20:08:02] | [2019-11-04 21:09:35] | [2019-11-04 21:22:17] |
| 3  | [2019-11-04 06:40:29] | [2019-11-04 07:08:10] | [2019-11-04 09:00:06] |
| 4  | [2019-11-04 06:19:29] | [2019-11-04 06:36:44] | [2019-11-04 06:40:19] |

All entries are from the same server. The delay between Start of Worker and Start of Encoding Process is because, the file needs to be transfered to the encoding server first.

As you can see the faildates are very random. One time 2 hours, the next time 20minutes.

The VideoProcessor class handles everything from downloading the file from a storage server, start the encoding process, notify the database about the current state, if finished, etc.

Can a huge memory cosumption also forces laravel to throw the exception?

Activity icon

Replied to Check Time Is Between Two Times Or Not - Laravel

if(now() < $end && now() > $start){
    'time between'
}
Nov
03
2 months ago
Activity icon

Started a new Conversation Long Running Queues Fails And Executes Successfully At The Same Time

We're have to encode many files per day from different formats to mp4. For this we use FFmpeg, laravel, queues and the supervisor.

Everything works as expected, the only point is that the Job executes the failed method although the process is still running!??

Supervisor config:

[program:encoding-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/laravel/artisan queue:work --queue=encoding --sleep=10 --tries=1 --timeout=0
autostart=true
autorestart=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/laravel/storage/logs/encoding-worker.log

ProcessVideo.php

<?php

namespace App\Jobs;

use Exception;
use App\Video\VideoProcesser;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Exceptions\FileNotFoundException;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldQueue;

class ProcessVideo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $video;

    public $timeout = 0;


    /**
     * Delete the job if its models no longer exist.
     *
     * @var bool
     */
    public $deleteWhenMissingModels = false;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($video)
    {
        $this->video = $video;
    }

    /**
     * Execute the job.
     *
     * @param VideoProcesser $processer
     * @throws FileNotFoundException
     * @throws \App\Exceptions\EncodingTransferFailedException
     */
    public function handle(VideoProcesser $processer)
    {

        $processer->process($this->video);

    }

    /**
     * The job failed
     *
     * @param Exception $exception
     */
    public function failed(Exception $exception)
    {
        \Log::channel('encoding')->error('Encoding job failed ' . $exception->getMessage() . ' - '. $this->video->getFilename());

    }
}

The encoding.log often contains this message:

production.ERROR: Encoding job failed App\Jobs\ProcessVideo has been attempted too many times or run too long. The job may have previously timed out

but now it get's weird. Even though the failed method gets called, the process finishes successfully and reaches the last point of the code. I'm sure that it reaches the code since the database is updated with the correct parameters. The next weird part, the error only occurs sometimes and not on every encoding job.

What can cause this issue? The $timeout = 0 should disable the timeout, correct? And the --tries=1 should only execute the job once.

We're using Laravel 5.8 with php7.3 and latest mariadb version.

Oct
14
3 months ago
Activity icon

Replied to Unable To Update Encrypted Table.

The data in $request is correct?

Activity icon

Replied to MySql To Eloquent

Select codigo, referenciacliente, nombre, nombrecliente, diasaviso 
from articulos 
where (articulos.cod_cliente = '$codigo' and articulos.descatalogado = 0)
or (articulos.cod_cliente = '$codigo' and articulos.descatalogado = 1 and 
articulos.codigo 
in (select movimientos.cod_articulo from movimientos
          where movimientos.fecha_alta >= '$fromDate' and movimientos.fecha_alta <= '$toDate')
) 
order by articulos.nombre asc

I assume you have a model called Articulo and Movimientos

Articulo::select('codigo, referenciacliente, nombre, nombrecliente, diasaviso')
    ->where(function($q) use ($codigo){
        $q->where('cod_cliente', '=', $codigo)
            ->where(descatalogado, 0);
})
->orWhere(function($q) use ($codigo, $from, $to){
    $q->where('cod_cliente', $codigo)
        ->where('descatalogado', 1)
        ->whereIn('codigo', function() use ($from, $to){
            Movimientos::select('cod_articulo')->whereBetween('fetch_alta', $from, $to)->get()->pluck('cod_articulo');
    });
})->orderBy('nombre', 'ASC');

Not tested, but you should get the idea

Sep
12
4 months ago
Activity icon

Started a new Conversation Job Marked As Failed Is Still Been Processed

I have often transfer files between servers. Therefore I have a job which should handle the transfer process in the background. The transfer also works but the job is often marked as failed and inserted in the failed_jobs table although it's still processed till the end.

The Job:

class TransferFiles implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $data;

    public $timeout = 0;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(TransferProcessor $processor)
    {
        $processor->process($this->data);
    }

    /**
     * The job failed
     *
     * @param Exception $exception
     */
    public function failed(Exception $exception)
    {
       \Log::channel('transfer')->error('failed '. $exception->getMessage());
     
    }
}

I dispatch it as follow:

TransferFiles::dispatch($data)->onQueue('transfer');

the supervisor config:

[program:transfer-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/laravel/artisan queue:work --queue=transfer --sleep=10 --tries=1 --timeout=0
autostart=true
autorestart=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/laravel/storage/logs/transfer-worker.log

I set the timeout=0 in the command and the job itself.

The exception message

Illuminate\Queue\MaxAttemptsExceededException: App\Jobs\TransferFiles has been attempted too many times or run too long. The job may have previously timed out. in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:405
Stack trace:
#0 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(321): Illuminate\Queue\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts('beanstalkd', Object(Illuminate\Queue\Jobs\BeanstalkdJob), 1)
#1 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\Queue\Worker->process('beanstalkd', Object(Illuminate\Queue\Jobs\BeanstalkdJob), Object(Illuminate\Queue\WorkerOptions))
#2 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\BeanstalkdJob), 'beanstalkd', Object(Illuminate\Queue\WorkerOptions))
#3 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('beanstalkd', 'transfer', Object(Illuminate\Queue\WorkerOptions))
#4 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('beanstalkd', 'transfer')
#5 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#6 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#7 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#8 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#9 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#10 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#11 /var/www/html/laravel/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#12 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#13 /var/www/html/laravel/vendor/symfony/console/Application.php(921): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/laravel/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/laravel/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/html/laravel/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 {main}

So does anyone has any idea why it's marked as failed although it's still running?

Aug
22
4 months ago
Activity icon

Replied to VueJS Concatenating The Variables Rather Than Addition

In addition to @tykus reply, I strongly suggest to use "0" as default parameter then an empty string

Aug
19
4 months ago
Activity icon

Replied to Does Supervisor Needs A Restart If The Config Changes?

I meant the laravel config and the variables set in the .env file and not the supervisor config file.

Activity icon

Started a new Conversation Does Supervisor Needs A Restart If The Config Changes?

I know that I have to restart the supervisor if I update my code. But what if I just need to change a value in the config that is needed in the Job code base?

Do I have to restart the supervisor as well, or will it be enough if I run

php artisan config:cache

?

Activity icon

Replied to Sorting And Live Search Using Ajax

Is the XHR header set at all?

You use

if ($request->ajax()) 

try disabling it.