mtwebit

Tasker

Recommended Posts

Tasker is a module to handle and execute long-running jobs in Processwire. It provides a simple API  to create tasks (stored as PW pages), to set and query their state (Active, Waiting, Suspended etc.), and to execute them via Cron, LazyCron or HTTP calls.

Creating a task

$task = wire('modules')->Tasker->createTask($class, $method, $page, 'Task title', $arguments);

where $class and $method specify the function that performs the job, $page is the task's parent page and $arguments provide optional configuration for the task.

Executing a task

You need to activate a task first

wire('modules')->Tasker->activateTask($task);

then Tasker will automatically execute it using one of its schedulers: Unix cron, LazyCron or TaskerAdmin's REST API + JS client.

Getting the job done

Your method that performs the task looks like

public function longTask($page, &$taskData, $params) {
  ...
}

where $taskData is a persistent storage and $params are run-time options for the task.

Monitoring progress, management

The TaskerAdmin module provides a Javascript-based front-end to list tasks, to change their state and to monitor their progress (using a JQuery progressbar and a debug log area). It also allows the on-line execution of tasks using periodic HTTP calls performed by Javascript.

TaskerAdmin.png.e535554a45673edd5dd1049b910585fe.png

 

Monitoring task progress (and log messages if debug mode is active)

TaskMonitor.png.912e5949fab4d8a61f39262e2e682ddd.png

 

Task data and log

TaskData.png.e5bd86b403dad7b2718cf4fdd39ec175.pngTaskLog.png.1795f8a454cba4d9756877e77b5ed820.png

Detailed info (setup, task dependencies, time limits, REST API etc.) and examples can be found on GitHub.

This is my first public PW module. I'm sure it needs improvement :)

 

  • Like 12

Share this post


Link to post
Share on other sites

hi @mtwebit welcome to the forum and thanks for that module! i've created something similar for one of my projects but it's custom and not built into a module so i think there's potential for what you are doing :)

some ideas/questions/feedback:

  • use InputfieldMarkup to structure your custom code and make it look&feel more native. see my new tutorial here: 
  • do you know the wirequeue module?
  • would be great to have an easy way to integrate this into other modules or custom pages. maybe it is already possible - i'll have a look when i have more time :)

This is how my progressbar looks like using InputfieldMarkup:

2017-11-09 16_20_28-Edit Page_.png

  • Like 4

Share this post


Link to post
Share on other sites

Thanks for the feedback. I'll definitely have a look at InputfieldMarkup and wirequeue.

It is possible to integrate the UI elements into other pages. There's a renderTaskList() method to perform this:

    if(wire('modules')->isInstalled("TaskerAdmin")) {
      $out .= '<h3>Tasks</h3>';
      $out .= wire('modules')->get('TaskerAdmin')->renderTaskList($selector);
    }

It can render a task list or a detailed task monitoring div including JS code to show the progressbar or even to execute the task when displaying the page.
It needs improvement, however, as its links point to the TaskerAdmin page atm and the list UI is not really customizable.

Share this post


Link to post
Share on other sites

I'm doing something similar (far from being as awesome as your module) using only some hobbled up pages and templates, and it's getting out of hand. This looks worthwhile to dig around in. I'll try it out and try to give helpful feedback. Thanks for sharing. :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By adrian
              Introducing Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 30+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By Harmen
      Hello all,
      Was wondering if any of you tried to include the Exact PHP client by Picqer in Processwire (URL)? I am trying to at the moment but I am stuck at the Authorization process. Building it inside a module file to execute a certain function every 6 hours to update something on the website. For the authorization process the file has to execute the following piece of code:
      header('Location:'. $urlThatRedirectsMeToTheLoginOfExact); But each time I am trying  to do so, I get the following error: Cannot modify header information - headers already sent by (output started at /processwire/index.php:55). I am out of options so that's why I am trying to find someone who used this library and could get it to work or someone who knows how I can fix it.
      Tips are highly appreciated (if they work ;))
      Cheers, Harmen
    • By BitPoet
      So I stumbled over the request to allow limiting templates to be used only once under every parent page in this thread
      and found that this would actually come in handy (also in a site I've built).
      The code can be found on github and soon also in the module repo.
      After installation, you'll find a new checkbox "Only once per parent" in the family tab when editing a template.

    • By Robin S
      Password Generator
      Adds a password generator to InputfieldPassword.

       
      Usage
      Install the Password Generator module.
      Now any InputfieldPassword has a password generation feature. The settings for the generator are taken automatically from the settings* of the password field.
      *Settings not supported by the generator:
      Complexify: but generated passwords should still satisfy complexify settings in the recommended range. Banned words: but the generated passwords are random strings so actual words are unlikely to occur.  
      https://modules.processwire.com/modules/password-generator/
      https://github.com/Toutouwai/PasswordGenerator