terp's avatar
Level 1

Eloquent returns no rows, sometimes, when using scheduler

Hi

I have defined mulitple tasks, like:

$schedule->command('my:command')->cron("*/5 * * * *")->appendOutputTo(storage_path('logs/mycommand.log'))->runInBackground()->withoutOverlapping(10);

And this works fine, most of the time, but sometimes a simple eloquent search returns 0 rows, eventhough, there are rows, and there always is.

$servers = servers::where(['active'=>1])->get();

I cant seem to fine any explanation for this behaviour, and my only theory is that these jobs run at the same time, and creates some kind of conflict, but there are no updates to this table, only selects, but if i add a random sleep() to my code in the commands, it seems to work better.

Ideas?

Thanks in advance :)

info: Running Laravel 9.11, in Docker

0 likes
5 replies
Snapey's avatar

maybe another command running at the same time and messing with the active column?

terp's avatar
Level 1

@Snapey yea that would be the easy fix :) but there is no update to that column

Snapey's avatar

@terp I'm not trying to give you an easy fix. I'm trying to get you to consider OUTSIDE this particular command and THINK about the environment it is running in, and other things that might be happening in parallel.

With not much evidence to go on "sometimes a simple eloquent search returns 0 rows" its all I can suggest

terp's avatar
Level 1

@Snapey I know, but if i had more info i would have provided it. Is eloquent requests cached in any way?

Please or to participate in this conversation.