Prevent a scheduled import from overlapping itself
A catalog import normally finishes in two minutes, but today it takes twenty. A schedule that starts it every five minutes can create several concurrent imports unless overlap is explicitly controlled.
Lock the scheduled task
use Illuminate\Support\Facades\Schedule;
Schedule::command('catalog:import')
->everyFiveMinutes()
->withoutOverlapping(30);
This illustrative command name must exist in your application. The argument is the lock expiry in minutes. Set it with an understanding of the longest legitimate run and failure recovery. If the lock expires while an import is still running, a later invocation may overlap after all.
A scheduler lock has a scope
The mechanism relies on the configured cache. Multiple servers need a shared supported cache and, where appropriate, a single-server scheduling rule. Separate cache stores do not coordinate with each other simply because the scheduled command has the same name.
The import should also tolerate retries and duplicate input. An overlap lock limits simultaneous execution; it does not erase partial writes from a previous failure or guarantee a provider event is applied once.
Test a deliberately slow run and confirm another scheduled invocation is skipped as intended. Record start, finish, failure, and duration so a permanently skipped task is visible. If you clear a stale scheduler lock, first verify that no legitimate process still owns the work. Clearing it indiscriminately can recreate the overlap you were trying to prevent.