laravel schedule cron job в виде url
Я сделал приложение на laravel, в нем используется schedule, который вызывает comand с запросом к бд. В crontab -e я добавил такую запись * * * * * php /var/www/poorbirds.com/artisan schedule:run >> /dev/null 2>&1 - Всё работает.
Сейчас я выложил сайт на хостинг infinityfree. В cpanel (Или что-то похожее на cpanel) есть раздел cron jobs. Вот так он выглядит
Я записал в поле script cron/collect_eggs.
а в web.php добавил такую запись
Route::get('/cron/collect_eggs', function() {
Artisan::call('collect:eggs');
});
И сделал так, чтобы этот скрипт вызывался каждые 2 минуты для тестов. Через 2 минуты он вызывается и всё. ТО есть вызывается только один раз. ЧТо может быть не так?
Вот handler из kernel.php и CollectEggs.php
// kernel.php
class Kernel extends ConsoleKernel {
protected $commands = [
Commands\ CollectEggs::class
];
protected
function schedule(Schedule $schedule) {
$schedule - > command('collect:eggs') - > everyMinute();
}
protected
function commands() {
$this - > load(__DIR__.
'/Commands');
require base_path('routes/console.php');
}
}
// CollectEggs.php
class CollectEggs extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'collect:eggs';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Every hour counts the number of eggs in users';
/**
* Create a new command instance.
*
* @return void
*/
public
function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public
function handle() {
// counting eggs and litter for all users
DB::select("
INSERT INTO eggs(id, name, birds_count, price, demand, count, litter, collected, cared, fine, user_id, bird_seller_id)
SELECT CONCAT(u.id, b_s.id), --create UID from user_id and bird_seller_id birds.name, --bird name count, --count of birds from bird_seller_user table birds.egg_price * (1 + IFNULL(price_bonus, 0) / 100), --egg price with certificate birds.demand * (1 + IFNULL(demand_bonus, 0) / 100), --demand with certificate bonus count * birds.fertility * (1 + IFNULL(fertility_bonus, 0) / 100), --get count of eggs from birds_count * fertility with certificate bonus count * birds.litter * (1 + IFNULL(litter_bonus, 0) / 100),
0, --change collected 0, --remove care bonus CASE WHEN grade IS NULL THEN 5--no certificate.Fine is 5 WHEN grade = 0 THEN 3--grade 0 - fake certificate.Fine is 3 WHEN grade = 1 THEN 1--grade 1 - certificate with a typo.Fine is 1 ELSE 0 END,
user_id,
bird_seller_id
FROM users AS u--get all users
LEFT JOIN bird_seller_user AS b_s_u ON(b_s_u.user_id = u.id) --join bird_seller_user table to get sold_bird
JOIN bird_seller AS b_s ON(b_s.id = b_s_u.bird_seller_id) --join bird_seller table(this id sol_bird)
JOIN birds ON(b_s.bird_id = birds.id) --join birds table
LEFT JOIN certificates AS certs ON((SELECT certificate_id FROM sellers WHERE id = b_s.seller_id) = certs.id) --and join certificate table
ON DUPLICATE KEY UPDATE name = birds.name, --update bird name(just in
case) birds_count = b_s_u.count,
price = birds.egg_price * (1 + IFNULL(price_bonus, 0) / 100),
demand = birds.demand,
count = eggs.count +
b_s_u.count * birds.fertility * (1 + IFNULL(fertility_bonus, 0) / 100) * --count eggs with certificate bonus IF((1 - (eggs.litter / 20) / 100) < 0, 0, (1 - (eggs.litter / 20) / 100)) * --litter deduction IF(eggs.cared = 1, (1 + (birds.care / 100 * (1 + IFNULL(care_bonus, 0) / 100))), 1), --care bonus litter = eggs.litter + b_s_u.count * birds.litter * (1 + IFNULL(litter_bonus, 0) / 100),
collected = 0,
cared = 0, --remove care bonus fine = eggs.fine + CASE WHEN certs.grade IS NULL THEN 5--no certificate.Fine is 5 WHEN certs.grade = 0 THEN 3--grade 0 - fake certificate.Fine is 3 WHEN certs.grade = 1 THEN 1--grade 1 - certificate with a typo.Fine is 1 ELSE 0 END ");
Log::info('litter');
}
}