Skip to content

Commit 19218bf

Browse files
committed
updated guide
1 parent ba5312f commit 19218bf

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Handle scheduled one time or recurring tasks associated with Eloquent models.
77

88
> imagine a job portal where if an application gets rejected the app needs to notify the applicant via automated email after 3 days of that event, during that period the admin may change his mind and prevent the auto mail sending or modify the mail content
99
10-
For any scheduled task we can directly use Laravel's queue but what if that task needs to be modified is some way before it gets executed?
10+
For any scheduled task we can directly use Laravel's [queue](https://laravel.com/docs/8.x/queues) but what if that task needs to be modified is some way before it gets executed?
1111

1212
This package stores all the tasks that needs to run on a future date & time / recurringly and perform a task only before few moments when it is scheduled to run so that we get the chance to modify the task before it gets executed.
1313

14-
It uses Laravel's task scheduling to figure out & handle the tasks that needs to be run for the current day at the specified time for that task, and sends the task payload to a receiver class of your app (configurable). So how to perform the task is totally up to you.
14+
It uses Laravel's task [scheduling](https://laravel.com/docs/8.x/scheduling) to figure out & handle the tasks that needs to be run for the current day at the specified time for that task, and sends the task payload to a [receiver class](https://github.com/devsrv/laravel-scheduled-model-action#step---3--receiver-class-gets-task-payload--passes-the-task-to-classes-based-on-task-action-for-this-example-sending-email) of your app ([configurable](https://github.com/devsrv/laravel-scheduled-model-action#step---3--receiver-class-gets-task-payload--passes-the-task-to-classes-based-on-task-action-for-this-example-sending-email)). So how to perform the task is totally up to you.
1515

1616

1717
### Installation
@@ -48,21 +48,22 @@ return [
4848
```php
4949
$schedule->command('scheduledaction:poll --tasks=10')->hourly(); // poll pending tasks (10 tasks every hour & sends payload to your receiver, customize as per your app)
5050

51-
$schedule->command('scheduledaction:reset')->dailyAt('12:01'); // resets previously finished recurring tasks' status that needs to run today, skip this if your app donot need recurring task handling
51+
$schedule->command('scheduledaction:reset')->dailyAt('12:01'); // resets previously finished recurring tasks' status that needs to run today, skip this if your app doesn't need recurring task handling
5252
```
5353

54-
### 💡 NOTE :
55-
- this package creates two tables `model_actions` and `model_action_recurring`
56-
- every task has 4 satatus `PENDING` `FINISHED` `CANCELLED` `DISPATCHED`
57-
- `PENDING` tasks gets run at specified date & time, remember to mark the task as `FINISHED` or `CANCELLED` based on how it was handled.
58-
- most likely you'll use queue to run a task at a specified time so after dispatching to a queued job you might want to set the status as `DISPATCHED`
54+
### 💡 Note :
55+
- This package creates two tables `model_actions` and `model_action_recurring`
56+
- Every task has 4 satatus `PENDING` `FINISHED` `CANCELLED` `DISPATCHED`
57+
- The `scheduledaction:poll` artisan command polls `PENDING` tasks for the present day and passes the tasks payload to your receiver class.
58+
- Set how often you want the poll to happen of how many tasks needs to be passed to your receiver (the above [example](#%EF%B8%8F-add-scheduled-task-to-appconsolekernelphp) shows 10 per hour)
59+
- `PENDING` tasks gets run at specified date & time, remember to mark the task as `FINISHED` or `CANCELLED` based on how it was handled [check example](#step---4--email-sending-task-payload-gets-received-via-previous-receiver-class-and-mail-is-sent).
60+
- The `scheduledaction:reset` command updates only `FINISHED` recurring tasks to `PENDING` if it needs to run today i.e. resets the recurring tasks which is basically just a query so we can run it once a day
61+
- Most likely you'll use queue to run a task at a specified time so after dispatching to a queued job you might want to set the status as `DISPATCHED`
5962

60-
>there are many fluent methods to interact with the tables, check below:-
63+
## There are many fluent methods to interact with the tables
6164

6265

63-
### Use
64-
65-
#### Get
66+
### Get
6667

6768
```php
6869
use Devsrv\ScheduledAction\Models\ModelAction;
@@ -111,7 +112,7 @@ ModelAction::where('properties->type', 'success')->get();
111112
\Devsrv\ScheduledAction\Facades\Action::needsToRunToday(10, 'desc');
112113
```
113114

114-
#### Create
115+
### Create
115116

116117
```php
117118
$action = $model->scheduledActions()->create([
@@ -145,7 +146,7 @@ ModelAction::actWith('EMAIL')->forModel(Candidate::find(10))->actDate($carbon)->
145146
ModelAction::actTime($carbon)->createSchedule();
146147
```
147148

148-
#### Update
149+
### Update
149150
```php
150151

151152
$action->setPending()->save();
@@ -165,7 +166,7 @@ $action->syncWithoutDetachingRunsOnEvery([Days::SUNDAY, ..]); // doesnt remove
165166
$action->setNonRecurring()->setActOn($carbon)->save();
166167
```
167168

168-
### Example
169+
## Example
169170

170171
###### Step - 1 : some event happend and a task is created to execute on future day & time
171172
```php
@@ -185,7 +186,7 @@ ModelAction::actWith('MAIL')
185186
public function modifyScheduledTask() {
186187
$this->validate();
187188

188-
$this->schedule
189+
$this->task
189190
->setActDate(Carbon::createFromFormat('m/d/Y', $this->act_date))
190191
->setActTime(Carbon::createFromFormat('H:i:s', $this->act_time))
191192
->mergeExtraProperties([
@@ -198,7 +199,7 @@ public function modifyScheduledTask() {
198199
}
199200

200201
public function cancelSchedule() {
201-
$this->schedule->setCancelled()->save();
202+
$this->task->setCancelled()->save();
202203
$this->info('schedule cancelled');
203204
}
204205
```
@@ -264,7 +265,6 @@ class MailTaskHandler
264265
}
265266
```
266267

267-
268268
## Changelog
269269

270270
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

0 commit comments

Comments
 (0)