Danon
Danon

Reputation: 39

How to run schedule tasks every minute in Laravel?

How i can run my Schedule task every minute? When i run command php artisan schedule:run, console get "No scheduled commands are ready to run.". How i should set my Tasks properly? For example if I use solo command php artisan command:send_info_email_before_event it works, but i want do it with schedule:run when i develop app.

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
     $schedule->command('command:send_info_email_before_event')
         ->everyMinute();
}

Upvotes: 1

Views: 8480

Answers (2)

filipe
filipe

Reputation: 2047

In windows you can schedule a task.

  1. Open the Windows start menu and type in "Scheduled Tasks". This will open the Task Scheduler. After that click Create Task (I would not suggest using basic task, as it is too basic for cron jobs).
  2. This will open a window that allows you to create a new "Cron Job" in Windows 10.

    Name: This is an easy way for you to remember what that task does. You can enter anything.

    Description: Just a more in-depth description for you to remember what it is.

    User Account: I would suggest using a full privileged account so that your cron jobs can create and modify files if it needs to. But I would also suggest using an account dedicated to Cron jobs so that you can revoke permissions any time you need to!

    Due to the nature of a website, I would definitely check “Run when user is logged in or not” and leave do not store password (This can throw an XML invalid error if you leave this unchecked and a password is required)

    And I would also check "Run with Highest Privileges"

  3. After that, Click "Trigger" and "Add new"

  4. To run a "Cron Job" task that runs more than once a day, Click Daily task. Recure daily, and repeat the task every minute. Be sure to click enabled. After that click Okay and click the tab "Actions" and New…

  5. Set program/Script to the /path/to/php.exe and arguments to /path/to/artisan schedule run. Be sure to use "" if you have spaces in the path. I would suggest using them either way as a rule of thumb.

Remember to not use production email credentials, you can use something like https://mailtrap.io to "trap" all sent emails.

Upvotes: 2

thisiskelvin
thisiskelvin

Reputation: 4202

You should be setting this up via cron job to run every minute. Task scheduling is not intended to be run manually.

In the terminal run:

crontab -e

Then add:

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

Once saved, this will then run the application scheduler every minute (without you needing to run php artisan schedule:run.

See the docs for more information.

Upvotes: 6

Related Questions