我在 Laravel 中开发了一个应用程序,它应该每隔四小时使用 webhose.io 获取所有国家的新闻。它似乎在一段时间内运行得很好。但是在一段时间后就停止了,然后重新启动。我不知道如何跟踪出错的原因。
Laravel 版本
Laravel Framework 5.5.45
Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-142-generic x86_64)
CRON Job 详细信息
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1
00 22 * * * /opt/dbbackup/db.sh /dev/null 2>&1
Kernel.php
<?php
namespace App\Console;
use DB;
use App;
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 = [
//
'\App\Console\Commands\GetNewsUpdates',
'\App\Console\Commands\AddBirthdayNotifications',
'\App\Console\Commands\DeleteBirthdayNotifications',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command(AddBirthdayNotifications::class, ['--force'])->daily();
$schedule->command('AddBirthdayNotifications:addbdaynotifications')->dailyAt('13:00')->withoutOverlapping();
$schedule->command('DeleteBirthdayNotifications:deletebdaynotifications')->daily()->withoutOverlapping();
//->daily() // midnight
if ( App::environment('live') ) {
$schedule->command('GetNewsUpdates:getnews')->cron('0 */4 * * *')->sendOutputTo('/root/logs/laravel_output.log');
}
$schedule->command('DeleteSendEmails:deleteEmailsSend')->weekly()->withoutOverlapping();
$schedule->command('SendEmails:sendEmailToUser')->hourly()->withoutOverlapping();
$schedule->command('ConnectSendEmails:sendEmailToConnectUser')->hourly()->withoutOverlapping();
// $schedule->command('GetNewsUpdates:getnews')->everyMinute();
// $schedule->command('DeleteBirthdayNotifications:deletebdaynotifications')
// ->daily();
/* $schedule->call(function () {
DB::table('recent_users')->delete();
})->daily();*/
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
Laravel作业的日志 最近的日志(正常工作)
1062 BN 1062 BN 1062 BN 1062 BN 1062 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 IO 1061 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BR 988 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BW 1059 BA 1058 BA 1058 BA 1058 BA 1058 BA 1058 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BO 1057 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BT 1056 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BM 1055 BZ 1053 BZ 1053 BZ 1053 BZ 1053 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BE 987 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BY 1052 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BB 1051 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BD 1050 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 BH 1049 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AZ 1047 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AT 986 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AU 985 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AW 1046 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AM 1045 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AG 1044 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AI 1042 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AO 1041 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AD 1040 AS 1039 AS 1039 AS 1039 AS 1039 AS 1039 AS 1039 AS 1039 AS 1039 AS 1039 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 DZ 1038 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AL 1037 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036 AF 1036
系统日志中的CRON日志
Feb 25 10:05:01 connect424 CRON[6770]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:05:01 connect424 CRON[6771]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 25 10:05:01 connect424 CRON[6774]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:06:01 connect424 CRON[6804]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:06:01 connect424 CRON[6805]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:07:01 connect424 CRON[6836]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:07:01 connect424 CRON[6837]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:08:01 connect424 CRON[6871]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:08:01 connect424 CRON[6870]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:09:01 connect424 CRON[6919]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:09:01 connect424 CRON[6920]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Feb 25 10:09:01 connect424 CRON[6922]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:10:01 connect424 CRON[7013]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:10:01 connect424 CRON[7014]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:11:01 connect424 CRON[7041]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:11:01 connect424 CRON[7043]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:12:01 connect424 CRON[7071]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:12:01 connect424 CRON[7073]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:13:01 connect424 CRON[7123]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:13:01 connect424 CRON[7125]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:14:01 connect424 CRON[7174]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:14:01 connect424 CRON[7175]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:15:01 connect424 CRON[7221]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 25 10:15:01 connect424 CRON[7222]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:15:01 connect424 CRON[7225]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:16:01 connect424 CRON[7269]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:16:01 connect424 CRON[7270]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:17:01 connect424 CRON[7310]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:17:01 connect424 CRON[7311]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 25 10:17:01 connect424 CRON[7309]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:18:01 connect424 CRON[7347]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:18:01 connect424 CRON[7348]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:19:01 connect424 CRON[7396]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:19:02 connect424 CRON[7398]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:20:01 connect424 CRON[7426]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:20:01 connect424 CRON[7427]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:21:01 connect424 CRON[7462]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:21:01 connect424 CRON[7464]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:22:01 connect424 CRON[7500]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:22:01 connect424 CRON[7501]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:23:01 connect424 CRON[7532]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:23:01 connect424 CRON[7534]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:24:01 connect424 CRON[7574]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:24:01 connect424 CRON[7575]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:25:01 connect424 CRON[7613]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 25 10:25:01 connect424 CRON[7614]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:25:01 connect424 CRON[7616]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
Feb 25 10:26:01 connect424 CRON[7649]: (root) CMD (php /var/www/html/connect/artisan schedule:run >> /root/logs/sec.log 2>&1)
Feb 25 10:26:01 connect424 CRON[7650]: (developer) CMD (php /var/www/html/connect/artisan schedule:run >> /dev/null 2>&1)
编辑:
添加了具有时间的withoutoverlapping()
日志
我发现新闻更新任务每4小时运行一次,但被其他任务打断。
if (App::environment('live')) {
$schedule->command('GetNewsUpdates:getnews')->cron('0 */4 * * *')->withoutOverlapping(10)->sendOutputTo('/root/logs/laravel_output.log');
带有时间的日志
2019-02-27 12:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' GetNewsUpdates:getnews > '/root/logs/laravel_output.log' 2>&1
2019-02-27 12:01:01: No scheduled commands are ready to run.
2019-02-27 12:02:01: No scheduled commands are ready to run.
2019-02-27 12:03:01: No scheduled commands are ready to run.
2019-02-27 12:04:01: No scheduled commands are ready to run.
2019-02-27 13:30:01: No scheduled commands are ready to run.
Running scheduled command: '/usr/bin/php7.2' 'artisan' SendEmails:sendEmailToUser > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 13:31:01: No scheduled commands are ready to run.
2019-02-27 13:59:01: No scheduled commands are ready to run.
2019-02-27 14:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' SendEmails:sendEmailToUser > '/dev/null' 2>&1
2019-02-27 14:59:01: No scheduled commands are ready to run.
2019-02-27 15:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' SendEmails:sendEmailToUser > '/dev/null' 2>&1
2019-02-27 15:01:01: No scheduled commands are ready to run.
2019-02-27 15:02:01: No scheduled commands are ready to run.
2019-02-27 15:58:01: No scheduled commands are ready to run.
2019-02-27 15:59:01: No scheduled commands are ready to run.
2019-02-27 16:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' GetNewsUpdates:getnews > '/root/logs/laravel_output.log' 2>&1
2019-02-27 16:58:01: No scheduled commands are ready to run.
2019-02-27 16:59:01: No scheduled commands are ready to run.
2019-02-27 17:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 17:01:01: No scheduled commands are ready to run.
2019-02-27 17:58:01: No scheduled commands are ready to run.
2019-02-27 17:59:01: No scheduled commands are ready to run.
2019-02-27 18:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 18:01:01: No scheduled commands are ready to run.
2019-02-27 18:58:02: No scheduled commands are ready to run.
2019-02-27 18:59:01: No scheduled commands are ready to run.
2019-02-27 19:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 19:01:01: No scheduled commands are ready to run.
2019-02-27 19:09:01: No scheduled commands are ready to run.
2019-02-27 19:10:01: No scheduled commands are ready to run.
2019-02-27 19:59:01: No scheduled commands are ready to run.
2019-02-27 20:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' GetNewsUpdates:getnews > '/root/logs/laravel_output.log' 2>&1
2019-02-27 20:01:01: No scheduled commands are ready to run.
2019-02-27 20:59:01: No scheduled commands are ready to run.
2019-02-27 21:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 21:01:01: No scheduled commands are ready to run.
2019-02-27 21:19:01: No scheduled commands are ready to run.
Running scheduled command: '/usr/bin/php7.2' 'artisan' SendEmails:sendEmailToUser > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 21:20:01: No scheduled commands are ready to run.
2019-02-27 21:59:01: No scheduled commands are ready to run.
2019-02-27 22:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-27 22:01:01: No scheduled commands are ready to run.
2019-02-27 22:59:01: No scheduled commands are ready to run.
2019-02-27 23:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' SendEmails:sendEmailToUser > '/dev/null' 2>&1
2019-02-27 23:01:01: No scheduled commands are ready to run.
2019-02-27 23:59:01: No scheduled commands are ready to run.
2019-02-28 00:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' DeleteBirthdayNotifications:deletebdaynotifications > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.2' 'artisan' GetNewsUpdates:getnews > '/root/logs/laravel_output.log' 2>&1
2019-02-28 01:00:01: Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.2' 'artisan' SendEmails:sendEmailToUser > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.2' 'artisan' ConnectSendEmails:sendEmailToConnectUser > '/dev/null' 2>&1
2019-02-28 01:01:01: No scheduled commands are ready to run.
如果与上面的完整任务相比较,那么未完成的任务正在被完成。
ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZW 1226 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 ZM 1225 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 YE 1223 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VG 1219 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218 VN 1218
APP_ENV
环境变量设置为live
还是production
? - Travis BritzAPP_ENV
变量被设置为live
。 - twister_void