Skip to content
Advertisement

Symfony Lock Component does not lock – how to fix?

i upgraded recently to Symfony 3.4.x, refactor LockHandler because of deprecation warning and fall into strange behaviour.

Code in command before refactoring:

JavaScript

And it prevents to run two command at the same time – second just finishes without doing job. That is good.

But after suggested refactoring it allows to run many commands simultaneously. This is FAIL. How to prevent execution? New code:

JavaScript

NB #1: I don’t care about many servers or so, just one instance of application.

NB #2: If process was killed then new command must unlock and run.

Advertisement

Answer

You must use the LockableTrait trait

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement