定制 mwstake/mediawiki-component-runjobstrigger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mwstake/mediawiki-component-runjobstrigger

最新稳定版本:3.0.0

Composer 安装命令:

composer require mwstake/mediawiki-component-runjobstrigger

包简介

Provides background tasks infrastructure based on MediaWikis `maintenance/runJobs.php`

README 文档

README

RunJobsTrigger for MediaWiki

Provides an infrastructure to execute background tasks based on MediaWiki's maintenance/runJobs.php.

This code is meant to be used within the MediaWiki framework. Do not attempt to use it outside of MediaWiki.

Prerequisites

MediaWiki's maintenance/runJobs.php script must be run periodically by a serverside process (e.g. in a cronjob on Linux or Scheduled Task on Windows).

The frequency of that job determines the minimum frequency at which handlers can be invoked. It is recommended to invoke maintenance/runJobs.php every 15 minutes at a minimum.

Compatibility

  • 3.0.x -> MediaWiki 1.43
  • 2.0.x -> MediaWiki 1.39
  • 2.0.x -> MediaWiki 1.35

Use in a MediaWiki extension

Require this component in the composer.json of your extension:

{
	"require": {
		"mwstake/mediawiki-component-runjobstrigger": "~3"
	}
}

Since 2.0 explicit initialization is required. This can be achived by

  • either adding "callback": "mwsInitComponents" to your extension.json/skin.json
  • or calling mwsInitComponents(); within you extensions/skins custom callback method

See also mwstake/mediawiki-componentloader.

Implement a handler

Create a class that implements MWStake\MediaWiki\Component\RunJobsTrigger\IHandler. For convenience, you may want to implement a subclass of the abstract base class MWStake\MediaWiki\Component\RunJobsTrigger\Handler

In the getInterval method you can return any object that implements MWStake\MediaWiki\Component\RunJobsTrigger\Interval. There are a few predefined intevals available:

  • MWStake\MediaWiki\Component\RunJobsTrigger\Interval\OnceADay
  • MWStake\MediaWiki\Component\RunJobsTrigger\Interval\OnceAWeek
  • MWStake\MediaWiki\Component\RunJobsTrigger\Interval\OnceEveryHour
  • MWStake\MediaWiki\Component\RunJobsTrigger\Interval\TwiceADay

Register a handler

There are two ways to register a handler:

  1. Using the mwsgRunJobsTriggerHandlerRegistry GlobalVars configuraton
  2. Using the hook MWStakeRunJobsTriggerRegisterHandlers

In both cases, an ObjectFactory specification must be provided.

Example 1: GlobalVars

$GLOBALS['mwsgRunJobsTriggerHandlerRegistry']['my-own-handler'] = [
    'class' => '\\MediaWiki\Extension\\MyExt\\MyHandler',
    'services' => [ 'MainConfig' ]
];

Example 2: Hookhandler

$GLOBALS['wgHooks']['MWStakeRunJobsTriggerRegisterHandlers'][] = function( &$handlers ) {
    $handlers["my-own-handler"] = [
        'class' => '\\MediaWiki\Extension\\MyExt\\MyHandler',
        'services' => [ 'MainConfig' ]
    ];
    return true;
};

Configuration

  • mwsgRunJobsTriggerRunnerWorkingDir: Where to store data during execution. Defaults to the operating system's temp dir.
  • mwsgRunJobsTriggerOptions: Timing options for particular handlers.
  • mwsgRunJobsTriggerHandlerRegistry: Add your own trigger handlers.

Configuration examples

Using MediaWiki’s temporary directory to store data during execution

Suppose an administrator wants to ensure that they can ensure any temporary files are created in MediaWiki’s temporary directory rather than somewhere else. They could do this by adding the following to their LocalSettings.php:

$GLOBALS['mwsgRunJobsTriggerRunnerWorkingDir'] = $wgTmpDirectory;

Changing the timing options

A wiki administrator could add the following to their LocalSettings.php to have OnceAWeek tasks run on Friday instead of Sunday (by default):

$GLOBALS['mwsgRunJobsTriggerOptions']['*']['once-a-week-day'] = 'friday';

Debugging

A debug log can be enabled by adding

$GLOBALS['wgDebugLogGroups']['runjobs-trigger-runner'] = "/tmp/runjobs-trigger-runner.log";

to your LocalSettings.php file

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2021-04-07