mtwebit Posted November 9, 2017 Share Posted November 9, 2017 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. Monitoring task progress (and log messages if debug mode is active) Task data and log 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 16 Link to comment Share on other sites More sharing options...
bernhard Posted November 9, 2017 Share Posted November 9, 2017 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: 4 Link to comment Share on other sites More sharing options...
mtwebit Posted November 10, 2017 Author Share Posted November 10, 2017 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. 1 Link to comment Share on other sites More sharing options...
alxndre Posted November 10, 2017 Share Posted November 10, 2017 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. Link to comment Share on other sites More sharing options...
nicolant Posted October 23, 2018 Share Posted October 23, 2018 (edited) Thank you @mtwebit for that module! But I have a trouble with processwire setup with two site folders: "site" and "site-users". Tasker module is installed in site-users/modules folder. How to force processwire to load that modules instead of site/modules? Because runByCron.sh can't find Tasker module: require "index.php"; if (!wire('modules')->isInstalled('Tasker')) { echo 'Tasker module is missing.'; exit; } Nikolay. SOLVED: By addition of $_SERVER['HTTP_HOST']=$siteDomain; before index.php Edited October 23, 2018 by nicolant Link to comment Share on other sites More sharing options...
flydev Posted January 6, 2019 Share Posted January 6, 2019 (edited) I tested this module sometime ago before the release of DataSet and I had to fix the hardcoded admin url. I will sent you the new pull-request this afternoon concerning the following fix/change, feel free to merge it or not. install / uninstall written: fields and template created on installation / removed on uninstall fix: corrected admin page link in module and js file process module link moved under setup (can be moved later by the user without messing the admin url) about, tips markup improvements @mtwebit do you have an idea from where I could start to begin to port this module under Windows as the PCNTL extension isn't supported by this last OS ? I have already in mind implementing pthread to consume a Messaging Queueing System or something like that. And for people who wonder how it works with DataSet, there are a small screencast (shortened) importing a CSV DataSet : Edited May 6, 2024 by flydev removed gif preview, I ran out of attachment space 4 Link to comment Share on other sites More sharing options...
tpr Posted January 6, 2019 Share Posted January 6, 2019 @nicolant could you try !$this->wire('modules')->isInstalled... instead? Link to comment Share on other sites More sharing options...
mtwebit Posted January 9, 2019 Author Share Posted January 9, 2019 On 1/6/2019 at 9:59 AM, flydev said: @mtwebit do you have an idea from where I could start to begin to port this module under Windows as the PCNTL extension isn't supported by this last OS ? I have already in mind implementing pthread to consume a Messaging Queueing System or something like that. Thanks for the screencast, @flydev. I really appreciate it. Regarding the pcntl on Windows... Unfortunately, I don't have experience in this field. Windows has no signals (as far as I know) so I'd use a virtualization tool to overcome this limitation. You can try an API/kernel virtualization (e.g. Linux subsys for Windows) or use Docker. Also thanks for the pull req. I'll check your suggestions. Link to comment Share on other sites More sharing options...
flydev Posted January 9, 2019 Share Posted January 9, 2019 16 minutes ago, mtwebit said: You can try an API/kernel virtualization (e.g. Linux subsys for Windows) or use Docker. Ok that's an idea, I will take a look. About the PR, I didn't had the time the other day, will try to re sent it today. Thanks again for this great module. Link to comment Share on other sites More sharing options...
mtwebit Posted December 30, 2019 Author Share Posted December 30, 2019 I've uploaded a new version (0.9.5) to GitHub. It tries to handle DB connection loss errors and it has a basic profiler to optimize your import routines. See the wiki for more details. Note: TaskerAdmin needs some fixes in its JS-based task executor. Don't use this feature atm. (Cron is always the preferred task execution method.) 6 Link to comment Share on other sites More sharing options...
adrian Posted January 18, 2021 Share Posted January 18, 2021 On 12/30/2019 at 3:52 AM, mtwebit said: Note: TaskerAdmin needs some fixes in its JS-based task executor. Don't use this feature atm. (Cron is always the preferred task execution method.) I was just playing around with the module and this feature - I am correct in assuming it's still broken? I wasn't sure if I was doing something wrong. I started fixing things, but no real luck yet - it just keeps reporting a failure. And when I tried to emulate the PDF module's approach of redirecting to the tasker admin page, it seems like it never actually executes. Anyway, I'll go try the cron approach and see if that works. Link to comment Share on other sites More sharing options...
adrian Posted January 19, 2021 Share Posted January 19, 2021 @mtwebit - I think the bootstrap line in the runByCron.php file should be: require_once(__DIR__ . '/../../../index.php'); It didn't work for me the way you had it. Unfortunately I am also having issues with wanting to create and execute a task via my AdminActions module - because the method that is being called belong to the action's class and not the ProcessAdminActions parent class, things aren't working. I think I'll end up building a custom approach to doing what I need but just wanted to let you know of a possible issue that others might also have. Link to comment Share on other sites More sharing options...
mtwebit Posted January 27, 2021 Author Share Posted January 27, 2021 On 1/19/2021 at 12:57 AM, adrian said: I was just playing around with the module and this feature - I am correct in assuming it's still broken? I wasn't sure if I was doing something wrong. I started fixing things, but no real luck yet - it just keeps reporting a failure. And when I tried to emulate the PDF module's approach of redirecting to the tasker admin page, it seems like it never actually executes. Anyway, I'll go try the cron approach and see if that works. I forgot to mention it here, but it was fixed in November, last year. I completely rewrote this part of the code. There's no redirect anymore. The module will display an embedded progress bar if you run a task via the Web browser: Link to comment Share on other sites More sharing options...
mtwebit Posted January 27, 2021 Author Share Posted January 27, 2021 On 1/19/2021 at 2:03 AM, adrian said: @mtwebit - I think the bootstrap line in the runByCron.php file should be: require_once(__DIR__ . '/../../../index.php'); It didn't work for me the way you had it. Unfortunately I am also having issues with wanting to create and execute a task via my AdminActions module - because the method that is being called belong to the action's class and not the ProcessAdminActions parent class, things aren't working. I think I'll end up building a custom approach to doing what I need but just wanted to let you know of a possible issue that others might also have. I guess you forgot to set the working directory in your crontab. You should invoke Tasker using cron this way: */2 * * * * docker exec --user nginx phpweb bash -c "cd /var/www/html/site/modules/Tasker && LD_PRELOAD=/usr/lib/preloadable_libiconv.so /usr/bin/php runByCron.php" You can skip the docker and LD_PRELOAD parts but you need to set the working directory (cd ......./Tasker). I don't really understand the other problem, sorry. Do you have trouble with the createTask() method called from your own module? 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now