laravel 自动任务

A:
namespace App\Console;

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 = [
		// 已上线7天的需求邮件推送评分链接
		\App\Console\Commands\MailPushLink::class,
		// 已上线14天的需求邮件推送评分链接
		\App\Console\Commands\MailPushLink2::class,
        // 每月1号跑上个月的个人需求得分
        \App\Console\Commands\autoMonthDemandScore::class,
	];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
		// 已上线7天的需求邮件推送评分链接
		$schedule->command('MailPushLink')->dailyAt('08:00');
		// 已上线14天的需求邮件推送评分链接
		$schedule->command('MailPushLink2')->dailyAt('09:00');
        // 每月1号跑上个月的个人需求得分
        $schedule->command('autoMonthDemandScore')->monthlyOn('08:00');
	}

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

B:
namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Log;
use App\Services\Demand\DemandService;

class MailPushLink extends Command {

	// 命令名称
	protected $name = 'MailPushLink';
	// 命令描述,没什么用
	protected $description = '已上线7天的需求邮件推送评分链接';

	public function __construct() {
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function handle() {
		$this->MailPushLink();
	}

	public function MailPushLink() {
		$info = DemandService::MailPushLink(date('Y-m-d 23:59:59', strtotime('-3 day')), 0);
		log::info($info);
	}

}

思路:
	1,/app/Console/Commands 目录下创建文件,写入上面 B 代码
	2,/app/Console/Kernel.php 文件修改,参考上面 A 代码
	3,linux 上运行:php 项目路径/artisan MailPushLink
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值