php - 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 Jobs
manually 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();
}
解决方案
推荐阅读
- javascript - 需要用回调函数替换正则表达式
- mongodb - 是否可以在 MongoTemplate 中计算不同的文档?
- concurrency - 在 Erlang 中发送/接收消息(并发)
- android - 为什么
/tools/proguard/lib/proguard.jar 版本没有变化? - mysql - mysql 使用 sum 和 product 公式的组合计算
- javascript - 如何忽略 @click 的 bootstrapvue 按钮?
- asp.net-mvc - 我可以在 ASP.NET 应用程序中唯一标识客户端计算机吗
- javascript - 在没有聚合的猫鼬中获取数组长度
- delphi - 在 Delphi 中创建一个 7zip 压缩包
- bash - bash如何正确处理变量中的空格