julesgraus/housekeeper

该包最新版本(1.0.0)没有可用的许可信息。

清理旧文件的工具

1.0.0 2023-03-06 02:18 UTC

This package is auto-updated.

Last update: 2024-09-06 05:45:01 UTC


README

清理旧文件。

安装

您可以通过composer安装该包

composer require julesgraus/housekeeper

请确保您的根composer.json中包含对仓库的引用。如果您想自动触发housekeeper,请确保您已在服务器上设置定时任务

使用方法

请确保您的可清理类将实现此包中的CanDoHouseKeeping接口

class MyClass implements \JulesGraus\Housekeeper\Contracts\CanDoHouseKeeping {
    //Your regular methods and properties here.
    
    public static function doHousekeeping(OutputStyle $output) {
        //Put your houskeeping code here.
    }
}

您可以使用$output变量将清理反馈写入控制台。您可以通过将实现传递给housekeeper的register方法将实现注册到服务提供者中

\JulesGraus\Housekeeper\Housekeeper::register([
    MyClass::class
]);

默认情况下,housekeeper每天凌晨02:00将触发所有已注册类的doHousekeeping方法。

在特定时间运行housekeeper

如果您想在不同时间运行,可以使用housekeeper的schedule命令,如下所示

\JulesGraus\Housekeeper\Housekeeper::schedule(function(\Illuminate\Console\Scheduling\Event $command) {
    $command->twiceDaily(1, 13); //Run the task daily at 1:00 & 13:00
});

手动运行housekeeper

您可以在项目根目录中运行php artisan housekeeper:run来手动运行housekeeper。这在测试时很有用。

测试

在包的根目录中运行此命令以运行测试。

composer test