Skip to content

[lock] Add documentation about serializing lock #14366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/lock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@ method can be safely called repeatedly, even if the lock is already acquired.
across several requests. To disable the automatic release behavior, set the
third argument of the ``createLock()`` method to ``false``.

Serializing Locks
------------------

The ``Key`` contains the state of the ``Lock`` and can be serialized. This
allows the user to begin a long job in a process by acquiring the lock, and
to continue the job in an other process within the same lock.::

use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\Lock;

$key = new Key('article.'.$article->getId());
$lock = new Lock($key, $this->store, 300, false);
$lock->acquire(true);

$this->bus->dispatch(new RefreshTaxonomy($article, $key));

.. note::

Don't forget to disable the autoRelease to avoid releasing the lock when
the destructor will be called.

All stores are not compatible with serialization and cross-process locking:
For instance the kernel will automatically releases Semaphores acquires by the
:ref:`SemaphoreStore <lock-store-semaphore>` store.
Wen a lock is acquired with such store, and hte application try to serialize
the key, and exception will be thrown

.. _lock-blocking-locks:

Blocking Locks
Expand Down