Skip to content

Commit

Permalink
Added instructions on how to schedule deleteVisitorByAge command in R…
Browse files Browse the repository at this point in the history
…EADME.md
  • Loading branch information
hanisirfan committed Nov 20, 2022
1 parent 54a83c3 commit 5c8aaf5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,38 @@

`php artisan install PASSWORD USER_NAME EMAIL_ADDRESS`

## Deleting Visitors By Its Age

You can remove visitors that have a certain age (in seconds) after their addition to the system. You can do that by running the artisan `deleteVisitorByAge` command. Run `php artisan help deleteVisitorByAge` for more info.

To schedule `deleteVisitorByAge` command, you need to define it in `app/Console/Kernel.php` file's schedule method. For example:
```
protected function schedule(Schedule $schedule)
{
$schedule->command('deleteVisitorByAge --days=3')
->daily()
->runInBackground();
}
```

This will schedule the deletion of visitors that are 3 days old every day at midnight.

To running the actual Laravel Scheduler, add a single cron entry to your server to run `schedule:run` command every minute.

```
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
```

Refer [this article](https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/) on how to add Cron entries in Linux.

Refer [Laravel documentation](https://laravel.com/docs/9.x/scheduling#scheduling-artisan-commands) for more info in task scheduling.

### Logs

All logs of `deleteVisitorByAge` command are stored in `storage/logs/deleteVisitorByAgeCommand.log` file.

## Copyright

Copyright (c) 2022 Muhammad Hanis Irfan Bin Mohd Zaid a.k.a. Hanis Irfan.
Copyright (c) 2022 Muhammad Hanis Irfan Bin Mohd Zaid.

Licensed under the MIT license.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();

}

/**
Expand Down

0 comments on commit 5c8aaf5

Please sign in to comment.