首页 > 解决方案 > Task scheduling in laravel forge

问题描述

I've hosted my app in Digital Ocean with Laravel Forge and have created a artisan command to run through schedule [Nightly].

The artisan command runs smoothly via terminal but returns No such file or directory while running it through Scheduled Jobsmanually from Laravel Forge.

The command for the job is:

php /home/forge/sitename.com/artisan Instagram:fetch

The artisan command php /home/forge/sitename.com/artisan Inspire i.e php artisan inspire returns the correct output.

While the above mentioned custom artisan returns No such file or directory

app\Console\Commands\FetchInstagram.php's handel method:

    public function handle()
{
    $instagram = new Instagram('api-key');
    $posts = $instagram->media(); //gets 20 latest insta posts of a user
    // dd($posts);
    $fromDBs = Insta::orderBy('id', 'desc')->take(20)->get(); //get last 20 rows from table
    foreach( $posts as $post)
    {
        Insta::firstOrCreate([
            'thumb_link' => $post->images->thumbnail->url  ,
            'standard_link' => $post->images->standard_resolution->url  ,
            'caption' => $post->caption->text
        ]);
    }
}

Code from Kernel.php:

protected $commands = [
    'App\Console\Commands\FetchInstagram'
];

protected function schedule(Schedule $schedule)
{
    $schedule->command('Instagram:fetch')
    ->daily();
}

标签: phplaravellaravel-5laravel-5.7

解决方案


推荐阅读