Skip to content

Remonhasan/cron-purge

Repository files navigation

CronJob Schedule : Automating Old Data Cleanup with Laravel

A project that automates the process of cleaning up old data from your Laravel application's database. Keep your database clean and efficient with scheduled tasks.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/Remonhasan/cron-purge
  2. Navigate to the project directory:

    cd your-project
  3. Install dependencies using Composer:

    composer install
  4. Copy the .env.example file to .env and configure your environment:

    cp .env.example .env
  5. Generate an application key:

    php artisan key:generate
  6. Run database migrations:

    php artisan migrate
  7. Schedule the data cleanup task:

    Open your App/Console/Kernel.php file and add the following code to the schedule method:

    $schedule->command('clear:old-data')->everyMinute();

    This schedules the data cleanup to run every minute.

Usage

To use this project, you need to define the specifics of your use case. Typically, you may need to customize the data cleanup logic based on your application's needs.

  1. Define the data cleanup logic:

    Open App/Console/Commands/ClearOldData.php and modify the logic for cleaning up old data in your database. You can customize the table name, criteria for deletion, and timing.

  2. Run the scheduler:

    To manually run the scheduler, you can execute the following command:

    php artisan schedule:run
  3. View cleanup results:

    After running the scheduler, you can check your database to ensure that old data has been successfully cleaned up.

Configuration

You can configure this project by editing the .env file. Customize the database connection settings and any other project-specific configuration.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

License

The Laravel framework is open-sourced software licensed under the MIT license.