2017 © Pedro Peláez
 

library wba-task

UI for time-consuming tasks of the Ride framework

image

ride/wba-task

UI for time-consuming tasks of the Ride framework

  • Wednesday, August 24, 2016
  • by ride-user
  • Repository
  • 10 Watchers
  • 0 Stars
  • 91 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

Ride: Tasks web application

This module adds a UI to run different time-consuming tasks., (*1)

Task

The Task interface is what you need to implement for each task you want to offer., (*2)

You can inherit from AbstractTask to omit the obvious functions., (*3)

Define Your Task

To make the application know your task, add a dependency definition for it in your dependencies.json:, (*4)

{
    "dependencies": [
        {
            "interfaces": "ride\\web\\base\\task\\Task",
            "class": "my\\TestTask",
            "id": "test"
        }
    ]
}

Code Sample

Check the following code sample to get you on your way:, (*5)

```php <?php, (*6)

namespace my;, (*7)

use ride\library\i18n\translator\Translator; use ride\library\form\FormBuilder; use ride\library\system\file\browser\FileBrowser;, (*8)

use ride\web\base\task\AbstractTask;, (*9)

class TestTask extends AbstractTask {, (*10)

/**
 * Name of this task, should be the same as your dependency id
 * @var string
 */
const NAME = 'test';

/**
 * Constructs a new test task
 * @param \ride\library\system\file\browser\FileBrowser $fileBrowser Let's 
 * use the file browser to retrieve the job result
 */
public function __construct(FileBrowser $fileBrowser) {
    $this->fileBrowser = $fileBrowser;
}

/**
 * Hook to prepare the form to ask for extra arguments
 * @param \ride\library\form\FormBuilder $form
 * @param \ride\library\i18n\translator\Translator $translator
 * @return null
 */
public function prepareForm(FormBuilder $form, Translator $translator) {
    // if you need extra information for your task, you can use this hook
    // to prepare a form which asks for these arguments
    $form->addRow('test', 'string', array(
        'validators' => array('required' => array()),
    ));
}

/**
 * Gets the queue job of this task
 * @param array $data Extra arguments from the form
 * @return \ride\library\queue\job\QueueJob Job to invoke
 */
public function getQueueJob(array $data) {
    // your extra arguments, as defined in prepareForm, will be passed on to 
    // this method

    // you should return a QueueJob which holds the logic of your task
    return new TestQueueJob();
}

/**
 * Gets the result of this task
 * @param string $queueJobId Id of the invoked queue job
 * @return mixed
 */
public function getResult($jobId) {
    // extract the result 
    $application = $this->fileBrowser->getApplicationDirectory();

    return $application->getChild('data/test-' . $jobId . '.txt');
}

}, (*11)

The Versions