tobento/app-job 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tobento/app-job

最新稳定版本:2.0.1

Composer 安装命令:

composer require tobento/app-job

包简介

The app job lets you monitor queued or ran jobs from a web interface.

README 文档

README

The app job lets you monitor queued or ran jobs from a web interface.

Table of Contents

Getting Started

Add the latest version of the app job project running this command.

composer require tobento/app-job

Requirements

  • PHP 8.4 or greater

Documentation

App

Check out the App Skeleton if you are using the skeleton.

You may also check out the App to learn more about the app in general.

Job Boot

The job boot does the following:

  • installs and loads job config
  • implements jobs interface
  • boots features configured in job config
use Tobento\App\AppFactory;
use Tobento\App\Job\JobRepositoryInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Job\Boot\Job::class);
$app->booting();

// Implemented interfaces:
$jobRepository = $app->get(JobRepositoryInterface::class);

// Run the app
$app->run();

You may install the App Backend and boot the job in the backend app.

Job Config

The configuration for the job is located in the app/config/job.php file at the default App Skeleton config location where you can configure features and more.

Features

Jobs Feature

The jobs feature provides a jobs page where users can see any jobs queued or ran. In addition, you may requeue failed or completed jobs again.

Config

In the config file you can configure this feature:

'features' => [
    new Feature\Jobs(
        // A menu name to show the jobs link or null if none.
        menu: 'main',
        menuLabel: 'Jobs',
        // A menu parent name (e.g. 'system') or null if none.
        menuParent: null,
        
        // you may disable the ACL while testing for instance,
        // otherwise only users with the right permissions can access the page.
        withAcl: false,
    ),
],

ACL Permissions

  • jobs User can access jobs
  • jobs.requeue User can requeue jobs.

If using the App Backend, you can assign the permissions in the roles or users page.

Monitor Jobs Feature

The monitor jobs feature records jobs using the job repository.

Config

In the config file you can configure this feature:

'features' => [
    Feature\MonitorJobs::class,
],

Console

Purge Jobs Command

Use the following command to purge monitored jobs:

Purging jobs older than 24 hours

php ap jobs:purge

Available Options

Option Description
--hours=24 The number of hours to retain jobs data.
--queued=true If defined it purges only jobs which are queued (true) or not (false).
--status=failed Purges only the jobs with the defined status.
--appId[] Purges only the jobs which belongs to the defined app IDs.

If you would like to automate this process, consider installing the App Schedule bundle and using a command task:

use Tobento\Service\Schedule\Task;
use Butschster\CronExpression\Generator;

$schedule->task(
    new Task\CommandTask(
        command: 'jobs:purge',
    )
    // schedule task:
    ->cron(Generator::create()->daily())
);

Or you may install the App Task bundle and use the Command Task Registry to register this command.

Learn More

Monitor Jobs From Another App

When using different Apps, you may monitor jobs from all apps. Make sure that you configure the same job repository connection in the config file.

For instance, you may use the App Backend and configure it like:

'features' => [
    Feature\Jobs::class,
    Feature\MonitorJobs::class,
],

'interfaces' => [
    JobRepositoryInterface::class =>
    static function(DatabasesInterface $databases, JobEntityFactory $entityFactory): JobRepositoryInterface {
        return new JobStorageRepository(
            storage: $databases->default('shared:storage')->storage()->new(),
            table: 'jobs',
            entityFactory: $entityFactory,
        );
    },
],

Next, if you have created another app:

'features' => [
    // only monitor jobs:
    Feature\MonitorJobs::class,
],

'interfaces' => [
    JobRepositoryInterface::class =>
    static function(DatabasesInterface $databases, JobEntityFactory $entityFactory): JobRepositoryInterface {
        return new JobStorageRepository(
            storage: $databases->default('shared:storage')->storage()->new(),
            table: 'jobs',
            entityFactory: $entityFactory,
        );
    },
],

Finally, in the database config file, in both apps, configure the shared:storage database:

'defaults' => [
    'pdo' => 'mysql',
    'storage' => 'file',
    'shared:storage' => 'shared:file',
],

'databases' => [
    'shared:file' => [
        'factory' => \Tobento\Service\Database\Storage\StorageDatabaseFactory::class,
        'config' => [
            'storage' => \Tobento\Service\Storage\JsonFileStorage::class,
            'dir' => directory('app:parent').'storage/database/file/',
        ],
    ],
],

Credits

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-27