t-kanstantsin / yii2-action-lock-behavior
Allow run only one action instance at once
Installs: 387
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Type:yii2-extension
Requires
- php: >=7.1
- ext-mbstring: ^7.1
- psr/log: ^1.0
- yiisoft/yii2: ^2.0.10
This package is not auto-updated.
Last update: 2024-11-10 05:56:44 UTC
README
Yii widget
Basic
Behavior allow deny multiple runs of same console application action (e.g. long time executing task initiated with cron) using yii\mutex\*
package.
Lock source should be chosen carefully noting following:
-
yii\mutex\FileMutex
simple but can be used only with one docker container instance because its not possible determine if process still running or ended in another container. Requires only writable directory -
yii\mutex\DbMutex
requires db connection. May be used only with single database instance.
Example
Using mutex from global config:
public function behaviors(): array { return [ 'pid' => ActionLockBehavior::class, ]; }
Define mutex on-the-fly:
public function behaviors(): array { return [ 'pid' => [ 'class' => ActionLockBehavior::class, 'mutex' => [ 'class' => FileMutex::class, 'mutexPath' => \Yii::getAlias('@runtime/pid'), ], ], ]; }