I would like two jobs not to overlap, i.e. only one job can be executed at a time. Is there anything to do this?
If not, as far as I can see, I think to establish some kind of “flag” set to 1 when Queue::EVENT_BEFORE_EXEC and to 0 when Queue::EVENT_AFTER_EXEC.
Also, how can I set a real listener? a cron just works once each minute, but my jobs can be handled in seconds.
Mutex allows to get an idea if something is “locked”. This something could be a job of a certain type. How to handle it depends on your case. You can mark the job as done and put it into queue again or make the worker to actually wait till the lock is released.
If you are executing jobs using queue/run from a command line (cron for instance), you can use:
/usr/bin/flock -n /tmp/anyfile.lockfile php yii your-queue/run
flock will not let to start a new run if a another is being executed.