fullscreeninteractive/silverstripe-queuedjob-progressfield 问题修复 & 功能扩展

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

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

fullscreeninteractive/silverstripe-queuedjob-progressfield

Composer 安装命令:

composer require fullscreeninteractive/silverstripe-queuedjob-progressfield

包简介

Displays a user friendly form field for the progress of a QueuedJob

README 文档

README

A progress bar and screen for monitoring a SilverStripe Scheduled Job.

Build Status Version License

demo

Installation

composer require fullscreeninteractive/silverstripe-queuedjob-progressfield

Usage

The QueuedJobProgressField can be included in any Form

use FullscreenInteractive\QueuedJobProgressField\QueuedJobProgressField;

$fields = [
    // ...
    QueuedJobProgressField::create('ScheduledJob', '', $this->ScheduledJobID)
];

This module also provides a Controller subclass which displays the state of the job if needed. Setup a route to point to the QueuedJobProgressController

SilverStripe\Control\Director:
  rules:
    'upload//$Action/$ID': 'FullscreenInteractive\QueuedJobProgressField\QueuedJobProgressController'

Then you can redirect users to site.com/upload/progress/<jobSignature>/<jobId> to see the live progress of the job.

demo-web

User Experience Tips

Overriding Redirection Location

Redirecting users to site.com/upload/progress/<jobSignature>/<jobId> displays a running status of the job. If the job successes, a Continue button for users is activated. By default the continue button will redirect the user back, this behaviour can be overriden by using a ContinueLink query param on the original link.

site.com/upload/progress/<jobSignature>/<jobId>?ContinueLink=/thanks/

Likewise, you can set a different link for the button if the job fails, stalls or some other error occurs.

site.com/upload/progress/<jobSignature>/<jobId>?FailureLink=/error/

Long Running Single Progress Jobs

Due to the design of queued jobs, the progress indicator (currentStep) is only modified in the database at the end of a process call. Sometimes with long running single process jobs we need to display progress more verbosely. QueuedJobProgressService is designed as a drop-in replacement for QueuedJobService. The service allows your job to update the job descriptor more frequently.

Example Job

use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use FullscreenInteractive\QueuedJobProgressField\QueuedJobProgressService;
use SilverStripe\Core\Injector\Injector;

class MyAwesomeJob extends AbstractQueuedJob
{
    protected $descriptor;

    /**
     * By default the job descriptor is only ever updated when process() is
     * finished, so for long running single tasks the user see's no process.
     *
     * This method manually updates the count values on the QueuedJobDescriptor
     */
    public function updateJobDescriptor()
    {
        if (!$this->descriptor && $this->jobDescriptorId) {
            $this->descriptor = QueuedJobDescriptor::get()->byId($this->jobDescriptorId);
        }

        // rate limit the updater to only 1 query every sec, our front end only
        // updates every 1s as well.
        if ($this->descriptor && (!$this->lastUpdatedDescriptor || $this->lastUpdatedDescriptor < (strtotime('-1 SECOND')))) {
            Injector::inst()->get(QueuedJobProgressService::class)
                ->copyJobToDescriptor($this, $this->descriptor);

            $this->lastUpdatedDescriptor = time();
        }
    }

    public function process()
    {
        $tasks = [
            // ..
        ];

        foreach ($tasks as $task) {
            $this->currentStep++;

            // sends feedback to the database in the middle of process() allowing
            // long single processes to continue.
            $this->updateJobDescriptor();
        }

        $this->isComplete = true;
    }
}

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-07-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固