Skip to content

Commit adb1bec

Browse files
committed
Fix readme
1 parent d9aea53 commit adb1bec

File tree

2 files changed

+44
-37
lines changed

2 files changed

+44
-37
lines changed

README.md

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
![Laravel Console Mutex](doc/img/example-new.gif)
2-
31
# Laravel Console Mutex
42

53
[<img src="https://user-images.githubusercontent.com/1286821/43083932-4915853a-8ea0-11e8-8983-db9e0f04e772.png" alt="Become a Patron" width="160" />](https://patreon.com/dmitryivanov)
@@ -13,7 +11,7 @@
1311
[![Total Downloads](https://poser.pugx.org/illuminated/console-mutex/downloads)](https://packagist.org/packages/illuminated/console-mutex)
1412
[![License](https://poser.pugx.org/illuminated/console-mutex/license)](https://packagist.org/packages/illuminated/console-mutex)
1513

16-
Mutex for Laravel console commands.
14+
Mutex for Laravel Console Commands.
1715

1816
| Laravel | Console Mutex |
1917
| ------- | :----------------------------------------------------------------------: |
@@ -28,14 +26,16 @@ Mutex for Laravel console commands.
2826
| 5.2.* | [5.2.*](https://github.com/dmitry-ivanov/laravel-console-mutex/tree/5.2) |
2927
| 5.1.* | [5.1.*](https://github.com/dmitry-ivanov/laravel-console-mutex/tree/5.1) |
3028

29+
![Laravel Console Mutex](doc/img/example-new.gif)
30+
3131
## Table of contents
3232

3333
- [Usage](#usage)
3434
- [Strategies](#strategies)
3535
- [Advanced](#advanced)
3636
- [Set custom timeout](#set-custom-timeout)
37-
- [Handle several commands](#handle-several-commands)
38-
- [Custom mutex file storage](#custom-mutex-file-storage)
37+
- [Handle multiple commands](#handle-multiple-commands)
38+
- [Set custom storage folder](#set-custom-storage-folder)
3939
- [Troubleshooting](#troubleshooting)
4040
- [Trait included, but nothing happens?](#trait-included-but-nothing-happens)
4141
- [Several traits conflict?](#several-traits-conflict)
@@ -45,7 +45,7 @@ Mutex for Laravel console commands.
4545

4646
1. Install the package via Composer:
4747

48-
```shell
48+
```shell script
4949
composer require illuminated/console-mutex
5050
```
5151

@@ -64,17 +64,17 @@ Mutex for Laravel console commands.
6464

6565
## Strategies
6666

67-
Overlapping can be prevented by various strategies:
67+
The mutex can prevent overlapping by using various strategies:
6868

6969
- `file` (default)
7070
- `mysql`
7171
- `redis`
7272
- `memcached`
7373

74-
Default `file` strategy is fine for small applications, which are deployed on a single server.
75-
If your application is more complex and deployed on several nodes, then you probably would like to use another mutex strategy.
74+
The default `file` strategy is acceptable for small applications, which are deployed on a single server.
75+
If your application is more complex and deployed on several nodes, you should consider using another mutex strategy.
7676

77-
You can change the mutex strategy by specifying `$mutexStrategy` field:
77+
You can change strategy by using the `$mutexStrategy` field:
7878

7979
```php
8080
class ExampleCommand extends Command
@@ -87,7 +87,7 @@ class ExampleCommand extends Command
8787
}
8888
```
8989

90-
Or by using `setMutexStrategy` method:
90+
Or by using the `setMutexStrategy()` method:
9191
9292
```php
9393
class ExampleCommand extends Command
@@ -109,23 +109,24 @@ class ExampleCommand extends Command
109109

110110
### Set custom timeout
111111

112-
By default, the mutex is checking for a running command, and if it finds such, it just exits. However, you can manually
113-
set the timeout for a mutex, so it can wait for another command to finish its execution, instead of just quitting immediately.
112+
By default, if mutex sees that the command is already running, it will immediately quit.
113+
You can change that behavior by setting a timeout in which mutex can wait for another running command to finish its execution.
114114

115-
You can change the mutex timeout by specifying `$mutexTimeout` field:
115+
You can set the timeout by specifying the `$mutexTimeout` field:
116116

117117
```php
118118
class ExampleCommand extends Command
119119
{
120120
use WithoutOverlapping;
121121

122-
protected $mutexTimeout = 3000; // milliseconds
122+
// Timeout in milliseconds
123+
protected $mutexTimeout = 3000;
123124

124125
// ...
125126
}
126127
```
127128

128-
Or by using `setMutexTimeout` method:
129+
Or by using the `setMutexTimeout()` method:
129130

130131
```php
131132
class ExampleCommand extends Command
@@ -136,25 +137,26 @@ class ExampleCommand extends Command
136137
{
137138
parent::__construct();
138139

139-
$this->setMutexTimeout(3000); // milliseconds
140+
// Timeout in milliseconds
141+
$this->setMutexTimeout(3000);
140142
}
141143

142144
// ...
143145
}
144146
```
145147

146-
There are three possible options for `$mutexTimeout` field:
148+
Here's how the `$mutexTimeout` field is treated:
147149

148-
- `0` - check without waiting (default);
149-
- `{milliseconds}` - check, and wait for a maximum of milliseconds specified;
150-
- `null` - wait, till running command finish its execution;
150+
- `0` - no waiting (default);
151+
- `{int}` - wait for the given number of milliseconds;
152+
- `null` - wait for the running command to finish its execution;
151153

152-
### Handle several commands
154+
### Handle multiple commands
153155

154-
Sometimes it is useful to set common mutex for several commands. You can easily achieve this by setting them the same mutex name.
155-
By default, mutex name is generated based on a command's name and arguments.
156+
Sometimes it might be useful to have a shared mutex for multiple commands.
157+
You can easily achieve that by setting the same mutex name for all of those commands.
156158

157-
To change this, override `getMutexName` method in your command:
159+
You should use the `getMutexName()` method for that:
158160

159161
```php
160162
class ExampleCommand extends Command
@@ -163,18 +165,18 @@ class ExampleCommand extends Command
163165

164166
public function getMutexName()
165167
{
166-
return "icmutex-for-command1-and-command2";
168+
return 'shared-for-command1-and-command2';
167169
}
168170

169171
// ...
170172
}
171173
```
172174

173-
### Custom mutex file storage
175+
### Set custom storage folder
174176

175-
If you're using `file` strategy, mutex files will be stored in the `storage/app` folder, by default.
177+
If you're using the `file` strategy, mutex files would be stored in the `storage/app` folder.
176178

177-
You can change the storage folder by overriding `getMutexFileStorage` method in your command:
179+
You can change that by overriding the `getMutexFileStorage()` method:
178180

179181
```php
180182
class ExampleCommand extends Command
@@ -194,21 +196,23 @@ class ExampleCommand extends Command
194196

195197
### Trait included, but nothing happens?
196198

197-
Note, that `WithoutOverlapping` trait is overriding `initialize` method:
199+
`WithoutOverlapping` trait overrides the `initialize()` method:
198200

199201
```php
200202
trait WithoutOverlapping
201203
{
202204
protected function initialize(InputInterface $input, OutputInterface $output)
203205
{
204206
$this->initializeMutex();
207+
208+
parent::initialize($input, $output);
205209
}
206210

207211
// ...
208212
}
209213
```
210214

211-
If your command is overriding `initialize` method too, then you should call `initializeMutex` method by yourself:
215+
If your command overrides the `initialize()` method too, you have to call the `initializeMutex()` method by yourself:
212216

213217
```php
214218
class ExampleCommand extends Command
@@ -217,8 +221,10 @@ class ExampleCommand extends Command
217221

218222
protected function initialize(InputInterface $input, OutputInterface $output)
219223
{
224+
// You have to call it first
220225
$this->initializeMutex();
221226

227+
// Then goes your custom code
222228
$this->foo = $this->argument('foo');
223229
$this->bar = $this->argument('bar');
224230
$this->baz = $this->argument('baz');
@@ -230,9 +236,9 @@ class ExampleCommand extends Command
230236

231237
### Several traits conflict?
232238

233-
If you're using another `illuminated/console-%` package, then you can find yourself getting into the "traits conflict".
239+
If you're using another `illuminated/console-%` package, you'll get the "traits conflict" error.
234240

235-
For example, if you're trying to build [loggable command](https://github.com/dmitry-ivanov/laravel-console-logger), which is protected against overlapping:
241+
For example, if you're building a [loggable command](https://github.com/dmitry-ivanov/laravel-console-logger), which doesn't allow overlapping:
236242

237243
```php
238244
class ExampleCommand extends Command
@@ -244,10 +250,10 @@ class ExampleCommand extends Command
244250
}
245251
```
246252

247-
You'll get the fatal error - the traits conflict, because of both of these traits are overriding `initialize` method:
253+
You'll get the traits conflict, because both of those traits are overriding the `initialize()` method:
248254
> If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.
249255
250-
Override `initialize` method by yourself, and initialize traits in required order:
256+
To fix that - override the `initialize()` method and resolve the conflict:
251257

252258
```php
253259
class ExampleCommand extends Command
@@ -257,6 +263,7 @@ class ExampleCommand extends Command
257263

258264
protected function initialize(InputInterface $input, OutputInterface $output)
259265
{
266+
// Initialize conflicting traits
260267
$this->initializeMutex();
261268
$this->initializeLogging();
262269
}
@@ -267,6 +274,6 @@ class ExampleCommand extends Command
267274

268275
## License
269276

270-
The MIT License. Please see [License File](LICENSE.md) for more information.
277+
Laravel Console Mutex is open-sourced software licensed under the [MIT license](LICENSE.md).
271278

272279
[<img src="https://user-images.githubusercontent.com/1286821/43086829-ff7c006e-8ea6-11e8-8b03-ecf97ca95b2e.png" alt="Support on Patreon" width="125" />](https://patreon.com/dmitryivanov)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "illuminated/console-mutex",
3-
"description": "Mutex for Laravel console commands.",
3+
"description": "Mutex for Laravel Console Commands.",
44
"keywords": ["laravel", "console", "command", "mutex", "locker", "overlapping"],
55
"license": "MIT",
66
"support": {

0 commit comments

Comments
 (0)