mercredi 17 juillet 2019

Schedule command are not run on server

I add a cron job in my project But the cron job is not working properly on ubuntu server. I search for the solution but cannot find.

Here is the code of Console/Kernel.php. Where I set my shedule commands. And also tell that i am not use any time like (daily()) then after how much time that command run?

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
   /**
       * The Artisan commands provided by your application.
   *
   * @var array
   */
   protected $commands = [
     //
   ];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    // $schedule->command('inspire')
    //          ->hourly();
    $schedule->call('App\Http\Controllers\Api\ScheduledNotificationController@moodCapacityReached')->everyMinute();
    $schedule->call('App\Http\Controllers\Api\ScheduledNotificationController@upcomingWeekEvent');
    $schedule->call('App\Http\Controllers\Api\ScheduledNotificationController@upcomingDayEvent');
    $schedule->call('App\Http\Controllers\Api\ScheduledNotificationController@upcomingHourEvent');
    $schedule->call('App\Http\Controllers\Api\CompanyCheckinController@beforedaycheckin')->daily();
    $schedule->call('App\Http\Controllers\Api\MoodOfTheDayController@beforeDayMoods')->daily();
}

/**
 * Register the commands for the application.
 *
 * @return void
 */
protected function commands()
{
    $this->load(__DIR__.'/Commands');

    require base_path('routes/console.php');
}

}

And Here is the Controller code that run after the command call:

CompanyCheckinController.php file:

public function beforedaycheckin()
{
    $companycheckin = CompanyCheckin::where('created_at', '<=', Carbon::now()->subDays(1)->toDateTimeString())->get();
    CompanyCheckin::where('created_at', '<=', Carbon::now()->subDays(1)->toDateTimeString())->delete();
    // return response()->json(['Checkin' => $companycheckin], 200);

}

I Run this command one server to run schedule command as a root user.

sudo crontab -e

But the method is not call and companyCheckin can not deleted after 24 hour. I do not find any solution. Please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire