-
command + forge schedule(스케줄)Laravel 2022. 4. 11. 22:21반응형SMALL
# What?
- 서버에서 일정 시간마다 어떤 작업을 예약하고 싶다면 사용
# How?
1. 스케줄 생성
php artisan make:command RefundFailLetter
2. 실행할 내용 작성
@ RefundFailLetter
protected $signature = 'refund:fail-letter'; protected $description = '발송실패건 환불'; public function __construct() { parent::__construct(); } public function handle() { $letters = Letter::where("finished", 1)->where("refunded", 0)->where("count_fail", ">", 0)->cursor(); foreach($letters as $letter){ $price = $letter->price * $letter->count_fail; $letter->update([ "refunded" => 1, ]); $letter->user->update([ "point" => $letter->user->point + $price ]); } }
@ Kernel.php
protected $commands = [ FormatCars::class, ];
3. Forge 설정
- 서버 선택 > Scheduler > Command 입력 > Frequency는 원하는 주기로 설정하고 재시작하기
php8.0 /home/forge/자기사이트명/artisan 명령어
ex. php8.0 /home/forge/admin.lettrers.com/artisan check:letter-log
* 5분마다 실행하게 하고싶을땐?
Custom check -> */5 * * * *
LIST'Laravel' 카테고리의 다른 글
라라벨 Excel(엑셀) 한글 헤더 사용하는법 (0) 2022.05.23 Custom Resource Collection 만들기(Resource에 변수 넘기기) (0) 2022.04.26 API 비동기로 파일 다운 구현하는법 (0) 2022.03.29 Carbon 이번주 특정 요일 얻기(월화수목금토일) (0) 2022.03.22 그룹별로 카운팅하고 싶을 때 + 그룹핑 대상에 where처럼 조건 걸고싶을 때 (GroupBy + Having) (0) 2022.01.21