Hot answers tagged

37

More of a "How do I debug stuck tasks" answer, but it should help you. Open up your craft_tasks table. You'll see one task in with a 'status' of 'running' and if you refresh the table several times, the 'currentStep' value for that task is no longer incrementing. That's your stuck task. Set that task's status to 'pending', and reload any page in the ...


10

Everything you need to manage tasks is in the TasksService, so you should be able to just use that in your controller action to kick off any pending tasks, using something along the lines of: if (!craft()->tasks->isTaskRunning()) { $task = craft()->tasks->getNextPendingTask(); if ($task) { craft()->tasks->...


8

The {% cache %}, by default will cache it's contents on a per URL and per locale basis. A lot of times when we see the behavior you're seeing, that's not the desired behavior and you should be using the {% cache globally %} parameter, where Craft stores the cached segment only on a per locale basis and drastically reduces the number of rows in the database ...


7

Sub-tasks can only be initiated by the parent task, and they will only visually look like a sub-task if they are actually sub-tasks. It’s also not possible to change the settings of an already-running task, at least without manually checking for new settings in your task. So, your parent task’s getStep() function would need to do its own checking to see if ...


7

First off: Craft stores cached content in the templatecaches table. Craft stores criteria mapping to the cached versions in templatecachecriteria. 1. Make sure Craft isn't caching too much. Originally, we were using {% cache using key craft.request.path if not craft.config.devMode %} We discovered it's critical to use the globally keyword: {% cache ...


7

I typically just truncate (delete all of the rows) the queue table if something goes wrong with a task. Then I delete all of the files in storage/logs/ and I try to reproduce the problem. If it still happens, then I look in queue.log and web.log to see what the issue is. Usually searching on [error] finds what I'm looking for pretty easily. Occasionally I ...


6

If you want an even more user friendly way of doing it, install the Task Manager plugin by Bob Olde Hampsink, and you can do it from the Craft control panel.


6

The easiest way is to use a GUI MySQL client to connect to the Craft database and edit the table directly. Popular ones include Navicat and Sequel Pro, but there is a good list here of options for both OSX and Windows. Once you connect to the database, you can edit the data in the craft_tasks table and change the value of status from running to pending to ...


5

I use this to force the task icon to show up immediately: Craft.cp.setRunningTaskInfo({ "id": "task ID", "level": "0", "description": "description", "status": "running", "progress": 0 }); Craft.cp.trackTaskProgress();


5

I'm not aware of any articles or best practice documents. There is a sample/simple PowerNap plugin that shows the basics of creating and running a task as well as the TaskService class reference documentation which you've already found.


4

I've encountered this problem before, and it seemed to be solved by replacing return $this->runSubTask('WassermanNews_TwitterTask'); with return $this->runSubTask('WassermanNews_Twitter');


4

I came across this Could not find the task component type. error upon trying to add a secondary task to my plugin. Following the naming scheme that P&T have in the PowerNap plugin, try making sure you have one task named after the plugin itself WassermanNewsTask, and then follow the subtasks, or any other additional tasks, with the underscore naming, eg....


4

I can't think of an existing way to do this (other than something ugly like have a separate plugin whose sole job is to clean up the data from the first). I think this would make the case for things like onBeforePluginUninstall, onPluginUninstall, onBeforePluginInstall, onPluginInstall, onBeforePluginDeactivate, etc. events to be added so that you could ...


4

With the recent release of 2.3.2632, I've had success with curling the runPendingTask action as an ajax request. 0 2 * * * curl -H "X-Requested-With: XMLHttpRequest" http://example.com/actions/myPlugin/someController/runSomeTask 9 2 * * * curl -H "X-Requested-With: XMLHttpRequest" http://example.com/actions/tasks/runPendingTasks So queue up the tasks, then ...


4

First, this is perfectly normal. :) Have a look at Brandons explanation here on how the cache tag works. If the element was added or modified, it queues up a new “Delete Stale Template Caches” task, which cycles through the templatecachecriteria table to see if there are any cached element queries which (if not cached) would have started showing ...


4

TasksService->getRunningTask() will tell you if a task is currently running. However, it doesn't tell you whether a particular chunk of code is being executed by that Task or by some other function. The most straightforward solution I can think of would be to write yourself a little helper method to check whether the call stack includes a Task class: ...


4

Before you push the job to the queue you can specify the ttr (time to reserve) in order to prevent the job being cancelled after 300 seconds (the default). Craft::$app->queue->ttr(3600); Craft::$app->queue->push($myJob); Alternatively, you can make your Job class implement RetryableJobInterface and then give it its own getTtr() method. See the ...


3

Ok, you are probably nearly there - all you need to do is call that controller action from the outside world. Here is a small example: <?php namespace Craft; class MyPlugin_SomeController extends BaseController { // this lets anyone run the controller actions we specify protected $allowAnonymous = = array('actionRunSomeTask'); // this is the ...


3

The description you define in getDescription() is just the default description in the event that no description was specified when craft()->tasks->createTask() was called. The actual description for the task is saved on the TaskModel, which you can get via $this->model from your Task class: $description = $this->model->description;


3

The simple way to do this would be to log a message to your Plugin's custom log using ExamplePlugin::log( 'TaskName has completed' ); This would require the user to visit the log and refresh to see if the task had completed - not ideal! However, if you wanted something that updated as the task was being run you could possibly redirect them to a Plugin ...


3

Might I suggest that a Craft task might not be the best way to pull off what you're trying to achieve. By default, they will be triggered by the next control panel request, no matter when that occurs. Sure you could build in some timing logic in your plugin, or set the runTasksAutomatically config setting to false and have a cron job hit the task at your ...


3

There is now a handy plugin available for managing your tasks queue: https://github.com/lukeyouell/craft-queue-manager


2

You are right about the Tasks running in the background. If the Task is just sending a few mails, it might be done before your site is loaded, thus creating this impression. Check: Change the Batch Size of the Mailer plugin to 1 and the waiting time to 120 seconds. Change the $user_criteria to fetch 2 users. Run your controller It should now take about 2 ...


2

Tasks are just another PHP request and they are subject to the same web server and php.ini limitations as a "normal" request. Sounds like you just need to up your max_execution_time.


2

Have you defined the settings and their type in your Task file? I've had success using the array of things passed to the task to set the total steps like so: class RerouteTask extends BaseTask { protected function defineSettings() { // Files passed from controller return array( 'files' => AttributeType::Mixed, ); } ...


2

I think this is difficult to answer properly because it depends almost entirely on what the tasks and subtasks are actually doing. For example, the main task could do something that ate 400MB of memory and triggered 400 sub-tasks that did nothing but return null not using any memory. Alternatively, the main task could do nothing but trigger subtasks (using ...


2

After trying many different things I noticed that the background tasks que was backed up: The queue was not moving. After a little research I came across the support ticket on craft on how to Resolve "Stuck" Background Tasks. After completing the couple steps of updating the stuck task status and restarting the queue, they all cleared out. After this, my ...


2

Currently not... after all, the task has to be triggered by something (either a cron job or a PHP request to kick it off). We've discussed the possibility of adding quasi-cron support natively in the future. It wouldn't be 100% accurate, though, since it would still require a PHP request to trigger it. At most you'd be able to say something like "Start ...


2

My understanding is that dynamic titles only get updated whenever an entry is saved — so without using a plugin you would have to re-save them each manually. If you wanted to automate this process in a plugin, you would use something like this. public function updateMySectionTitles() { $criteria = craft()->elements->getCriteria(ElementType::Entry);...


2

There is a support article about stuck tasks. In your case I would take a look at your logs, especially the phplog. You find them at: yourdomain.com/cp-path/utils/logs https://craftcms.com/support/stuck-tasks


Only top voted, non community-wiki answers of a minimum length are eligible