在 Golang 中进行「任务调度」,像用 Laravel 一样丝滑

Laravel 中的「任务调度」

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            DB::table('recent_users')->delete();
        )}->daily();

        $schedule->command('emails:send name')->daily();
    }
}

Goravel 中的「任务调度」

type Kernel struct {
}

func (kernel Kernel) Schedule() []*support.Event {
    return []*support.Event{
        facades.Schedule.Call(func() {
            facades.DB.Where("1 = 1").Delete(&models.User{})
        }).Daily(),

        facades.Schedule.Command("emails:send name").Daily(),
    }
}

func (kernel Kernel) Commands() []console.Command {
    return []console.Command{
        &commands.SendEmails{},
    }
}

实现了 Laravel 中大部分的实用方法,持续更新中, 欢迎 star 与 issues。

关于 Goravel

Goravel 是一个功能完备、具有良好扩展能力的 Web 应用程序框架。 作为一个起始脚手架帮助 Golang 开发者快速构建自己的应用。

项目地址:github.com/goravel/goravel

文档地址:www.goravel.dev

0DkNTwOZmj.png!large

本作品采用《CC 协议》,转载必须注明作者和本文链接
唯有所执,方有所成。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!