Hot answers tagged

37 votes
Accepted

Generating pending image transforms stuck in process

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, ...
user avatar
  • 66.5k
10 votes
Accepted

Triggering the start of a task from a CRON job

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 (!...
user avatar
  • 4,361
8 votes
Accepted

Long 'Deleting stale template caches'

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 ...
user avatar
  • 66.5k
7 votes
Accepted

How to add a subTask to an already running Task?

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-...
user avatar
7 votes

How can I mitigate caching performance issues with Craft?

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. ...
user avatar
  • 281
7 votes

How can I troubleshoot why my queue of tasks in stuck in Craft 3?

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 ...
user avatar
6 votes

Resolving “Stuck” Background Tasks

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.
user avatar
  • 7,248
6 votes
Accepted

Resolving “Stuck” Background Tasks

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 ...
user avatar
  • 66.5k
6 votes

Trigger Task Status Icon

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"...
user avatar
5 votes

Documentation on creating tasks

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 ...
user avatar
  • 66.5k
4 votes

Triggering the start of a task from a CRON job

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/...
user avatar
4 votes

Debugging a Failed Custom Task in Craft CMS

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');
user avatar
4 votes

Debugging a Failed Custom Task in Craft CMS

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 ...
user avatar
4 votes

Tasks on Uninstall Plugin

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 ...
user avatar
  • 66.5k
4 votes

Delete Stale Template Caches tasks much larger in Production than Staging

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” ...
user avatar
  • 7,248
4 votes
Accepted

Is it possible to determine if a script is running within a task?

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....
user avatar
  • 3,400
4 votes
Accepted

Queue Exec Time

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::...
user avatar
  • 6,326
3 votes
Accepted

Memory usage in sub tasks vs. regular tasks

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 ...
user avatar
  • 66.5k
3 votes

Problems with tasks and max execution time

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.
user avatar
  • 66.5k
3 votes

Triggering the start of a task from a CRON job

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 ...
user avatar
  • 2,301
3 votes
Accepted

How to get a Task's description inside runStep()?

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 ...
user avatar
3 votes
Accepted

How to notify the user from a Task

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 ...
user avatar
  • 3,833
3 votes

GeneratePendingTransforms stuck every time

I think to solve your issue we're going to need a bit more of information. A couple of things you can try: set a higher max execution time. I think normally the max execution time is 120 sec. and ...
user avatar
  • 858
3 votes
Accepted

Craft task send mails at specific date

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....
user avatar
  • 66.5k
3 votes

How can I troubleshoot why my queue of tasks in stuck in Craft 3?

There is now a handy plugin available for managing your tasks queue: https://github.com/lukeyouell/craft-queue-manager
user avatar
  • 769
3 votes
Accepted

How to manually run pending tasks in Craft CMS 3

Craft 3 default action to run the queue is public function actionRun(): Response { // Prep the response $response = Craft::$app->getResponse(); $response->content = '1'; // ...
user avatar
2 votes
Accepted

My tasks don't seem to be running as a background process

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 ...
user avatar
  • 8,326
2 votes

Creating Task cause Site/CP to hang

I recently dealt with a similar issue. Keep your tasks small and quick by using subtasks or by creating multiple instances of your main task. In your example, make each entry creation its own tasks or ...
user avatar
2 votes

How to re-generate titles for all entries in a section?

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 ...
user avatar
2 votes
Accepted

How can I access or set a Task's properties inside a class or method?

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 { ...
user avatar
  • 3,833

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