Skip to content

Commit b05a0e5

Browse files
committed
Removes unused command / updates README.md
1 parent 452d643 commit b05a0e5

File tree

2 files changed

+63
-78
lines changed

2 files changed

+63
-78
lines changed

README.md

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
![Laravel One-Time Operations](https://user-images.githubusercontent.com/65356688/224431782-550a6147-144d-408e-a412-4bd2b425dc15.jpg)
12
# Laravel One-Time Operations
23

34
Run an operation once after each deployment - just like you do it with migrations!
45

56
This package is for you if...
67

78
- you often create jobs to use just one single time **after a deployment**
8-
- you sometimes forgot to execute that one specific job and stuff got crazy
9-
- your code gets cluttered with Jobs, that are no longer in use anymore
9+
- you sometimes **forgot to execute** that one specific job and stuff got crazy
10+
- your code gets **cluttered with jobs**, that are not being used anymore
1011
- you seed or process data in a migration file (which is a big no-no!)
1112

1213
And the best thing: They work as easy as **Laravel migrations**!
@@ -39,7 +40,7 @@ php artisan operations:make <operation_name> // create operation file
3940
php artisan operations:process // process operation files
4041
php artisan operations:process --sync // force syncronously execution
4142
php artisan operations:process --async // force asyncronously execution
42-
php artisan operations:process --test // don't flag operations as "processed"
43+
php artisan operations:process --test // dont flag operations as processed
4344
php artisan operations:process <operation_name> // re-run one specific operation
4445
```
4546

@@ -53,20 +54,29 @@ php artisan operations:show disposed // show disposed operations
5354
php artisan operations:show pending processed disposed // use multiple filters
5455
```
5556

56-
### Delete operation files
57+
## Tutorials
58+
59+
### Deployment-Process
60+
61+
The *One-Time Operations* work exactly like [Laravel Migrations](https://laravel.com/docs/9.x/migrations).
62+
Just process the operations *after your code was deployed and the migrations were migrated*.
63+
You can make it part of your deployment script like this:
64+
5765
```shell
58-
php artisan operations:dispose // delete all operation files (only on local environment)
66+
...
67+
- php artisan migrate
68+
- php artisan operations:process
69+
...
5970
```
6071

61-
## Tutorials
72+
### Edit config
6273

63-
### Edit config (optional)
74+
By default, the following elements will be created in your project:
6475

65-
By default, the next steps will create the following:
6676
- the table `operations` in your database
67-
- the directory `operations` in your project directory
77+
- the directory `operations` in your project root directory
6878

69-
If you want to use a different settings for _table_ or _directory_ publish the config file:
79+
If you want to use a different settings just publish and edit the config file:
7080

7181
```shell
7282
php artisan vendor:publish --provider="TimoKoerber\LaravelOneTimeOperations\OneTimeOperationsServiceProvider"
@@ -87,18 +97,21 @@ Make changes as you like.
8797

8898
### Create One-Time Operation files
8999

90-
To create a new operations file execute the following command:
100+
![Laravel One-Time Operations - Create One-Time Operation files](https://user-images.githubusercontent.com/65356688/224433928-721b1261-b7ad-40c6-a512-d0f5b5fa0cbf.png)
101+
102+
![Laravel One-Time Operations - Create One-Time Operation files](https://user-images.githubusercontent.com/65356688/224433323-96b23e84-e22e-4333-8749-ae61cc866cd1.png)
103+
104+
To create a new operation file execute the following command:
91105

92106
```shell
93-
php artisan operations:make SeedAclData
107+
php artisan operations:make AwesomeOperation
94108
```
95109

96-
This will create a file like `operations/XXXX_XX_XX_XXXXXX_seed_acl_data.php` with the following content.
97-
(If you ever used Laravel migrations you should be familiar with the convention)
110+
This will create a file like `operations/XXXX_XX_XX_XXXXXX_awesome_operation.php` with the following content.
98111

99112
```php
100113
<?php
101-
// operations/XXXX_XX_XX_XXXXXX_seed_acl_data.php
114+
// operations/XXXX_XX_XX_XXXXXX_awesome_operation.php
102115

103116
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperation;
104117

@@ -124,54 +137,62 @@ Provide your code in the `process()` method, for example:
124137

125138

126139
```php
127-
// operations/XXXX_XX_XX_XXXXXX_seed_acl_data.php
140+
// operations/XXXX_XX_XX_XXXXXX_awesome_operation.php
128141

129142
public function process(): void
130143
{
131-
(new AclDataSeeder())->run(); // fill acl tables with required data
144+
User::where('active', 1)->update(['status' => 'awesome']) // make active users awesome
132145
}
133146
```
134147

135-
By default, the operation is being processed ***asyncronously*** by dispatching the job `OneTimeOperationProcessJob`.
148+
By default, the operation is being processed ***asyncronously*** (based on your configuration) by dispatching the job `OneTimeOperationProcessJob`.
136149

137150
You can also execute the code syncronously by setting the `$async` flag to `false`.
138151
_(this is only recommended for small operations, since the processing of these operations will be part of the deployment process)_
139152

140153
### Processing the operations
141154

155+
![Laravel One-Time Operations - Processing the operations](https://user-images.githubusercontent.com/65356688/224434129-43082402-6077-4043-8e97-c44786e60a59.png)
156+
142157
Use the following call to process all new operation files.
143158

144159
```shell
145160
php artisan operations:process
146161
```
147162

148-
Your code will be executed and you will find all the processed operations in the `operations` table:
163+
Your code will be executed, and you will find all the processed operations in the `operations` table:
149164

150-
| id | name | dispatched | processed_at |
151-
|-----|--------------------------------|------------|---------------------|
152-
| 1 | XXXX_XX_XX_XXXXXX_seed_acl_data| async | 2015-10-21 07:28:00 |
165+
| id | name | dispatched | processed_at |
166+
|-----|-------------------------------------|------------|---------------------|
167+
| 1 | XXXX_XX_XX_XXXXXX_awesome_operation | async | 2015-10-21 07:28:00 |
153168

154-
After that this specific operation will not be processed anymore.
169+
After that, this operation will not be processed anymore.
155170

156-
#### Force syncronously/asyncronously execution
171+
### Dispatching Jobs syncronously or asyncronously
157172

158-
By providing the `--sync` or `--async` option, the `$async` flag in all the files will be ignored and the operation will be executed based on the given flag.
173+
By default, all operations are being exectued with the `OneTimeOperationProcessJob` based on your `queue.default` configuration.
174+
By providing the `--sync` or `--async` option, the `$async` attribute in all the files will be ignored and the operation will be executed based on the given flag.
159175

160176
```shell
161-
php artisan operations:process --sync
162-
php artisan operations:process --async
177+
php artisan operations:process --async // force OneTimeOperationProcessJob::dispatch()
178+
php artisan operations:process --sync // force OneTimeOperationProcessJob::dispatchSync()
163179
```
164180

165-
#### Re-run an operation manually
181+
**Hint!** If `operation:process` is part of your deployment process, it is **not recommended** to process the operations syncronously,
182+
since an error in your operation could make your whole deployment fail.
166183

167-
If something went wrong, you can process an operation manually by providing the **name** of the operation.
168-
This will process the operation again, even if it was processed before.
184+
### Re-run an operation manually
185+
186+
![Laravel One-Time Operations - Re-run an operation manually](https://user-images.githubusercontent.com/65356688/224440344-3d095730-12c3-4a2c-b4c3-42a8b6d60767.png)
187+
188+
If something went wrong, you can process an operation manually by providing the **name of the operation** as parameter in `operations:process`.
189+
This will process the operation again, even if it was processed before (confirmation is required).
169190

170191
```shell
171-
php artisan operations:process XXXX_XX_XX_XXXXXX_seed_acl_data
192+
php artisan operations:process XXXX_XX_XX_XXXXXX_awesome_operation
172193
```
173194

174-
#### Testing the operation
195+
### Testing the operation
175196

176197
You might want to test your code a couple of times before flagging the operation as "processed". Provide the `--test` flag to run the command again and again.
177198

@@ -181,6 +202,8 @@ php artisan operations:process --test
181202

182203
### Showing all operations
183204

205+
![Laravel One-Time Operations - Showing all operations](https://user-images.githubusercontent.com/65356688/224432952-49009531-8946-4d19-8cee-70ca12605038.png)
206+
184207
So you don't have to check the database or the directory for the existing operations,
185208
you can show a list with `operations:show`.
186209
Filter the list with the available filters `pending`, `processed` and `disposed`.
@@ -194,6 +217,14 @@ php artisan operations:show pending // show only pending operations
194217
php artisan operations:show pending disposed // show only pending and disposed operations
195218
```
196219

220+
### Deleting operations
221+
222+
The whole idea of this package is, that you can dispose the operations once they were executed, so your project won't be cluttered with files and code, you won't be using anymore.
223+
224+
So you just need to **delete the files from your repository**
225+
226+
The deleted operations will be shown as ``DISPOSED`` when you call `operations:show`, so you still have a history on all the processed operations.
227+
197228
## Testing
198229

199230
```

src/Commands/OneTimeOperationDisposeCommand.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)