You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-62Lines changed: 49 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,15 @@
3
3
[](https://packagist.org/packages/devsrv/laravel-inplace)
> 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
11
11
12
12
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 in some way before it gets executed?
13
13
14
-
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.
14
+
This package stores all the tasks that needs to run on a future date & time and executes each only on the day when it is scheduled to run so that we get the chance to modify the task before it gets executed.
15
15
16
16
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.
#### ✔️ Add Scheduled Task to `app/Console/Kernel.php`
49
49
```php
50
50
$schedule->command('scheduledaction:poll --tasks=10')->hourly(); // poll pending tasks (10 tasks every hour & sends payload to your receiver, customize as per your app)
51
-
52
-
$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
53
51
```
54
52
55
53
#### ✔️ Use the `HasScheduledAction` trait in your models
@@ -65,12 +63,11 @@ class Candidate extends Model
65
63
```
66
64
67
65
### 💡 Note :
68
-
- This package creates two tables`model_actions` and `model_action_recurring`
66
+
- This package creates one table`model_actions`
69
67
- Every task has 4 satatus `PENDING``FINISHED``CANCELLED``DISPATCHED`
70
68
- The `scheduledaction:poll` artisan command polls `PENDING` tasks for the present day and passes the tasks payload to your receiver class.
71
-
- 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)
69
+
- Set how often you want the poll to happen and 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)
72
70
-`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).
73
-
- 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
74
71
- 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`
75
72
76
73
## There are many fluent methods to interact with the tables
$action->setActAt($carbon)->save(); // date and time will be extracted
173
166
$action->setActDate($carbon)->save(); // only date will be used
174
167
$action->setActTime($carbon)->save(); // only time will be used
175
-
176
-
$action->markAsRecurringRunsOnEvery([Days::SUNDAY, ..]); // stores only the given days removeing any existing day that was previously set as recurring day
177
-
$action->syncWithoutDetachingRunsOnEvery([Days::SUNDAY, ..]); // doesnt remove anything yet adds any new days given
0 commit comments