2

I am trying to debug a failed task in craft. However I'm not really sure what I'm looking for. I've dug though the log files and found traces of the task but no real errors to speak of. I have set:

'runTasksAutomatically' => false,

in my general.php file so that when I create my task:

craft()->tasks->createTask('WassermanNews_SocialTask');
craft()->end();

it will become a pending task rather than run automatically. That part seems to work as I end up with a pending task in my control panel.

enter image description here

So I think I've got the process up to this point. From here I'd simply like to kick off that pending process which I am attempting to do by though cURL.

curl -H "X-Requested-With: XMLHttpRequest" myurl.dev:32769/actions/tasks/runPendingTasks

I know that this is firing because the tasks moves from a pending state to a failed state:

enter image description here

However as I previously mentioned I have no idea why the task is failing and the logs do not seem to be my friend today.

Any ideas on what I could be doing wrong/where I could look for errors?

Below is my task which should be firing (it fires 1 subTask):

<?php
namespace Craft;

class WassermanNews_SocialTask extends BaseTask
{
  $TWITTER = 1;
  $INSTAGRAM = 2;
  $VINE = 3;

  public function getDescription()
  {
    return 'Social Grab';
  }

  public function getTotalSteps()
  {
    return 3;
  }

  public function runStep($step)
  { 
    WassermanNewsPlugin::log("Social Grab stepz izz happening",LogLevel::Info);

    switch($step){
        case TWITTER:
            return $this->runSubTask('WassermanNews_TwitterTask');
        case INSTAGRAM;
            return $this->runSubTask('WassermanNews_InstagramTask');
        case VINE:
            return $this->runSubTask('WassermanNews_VineTask');
    }
  }
}

All the sub tasks look more or less identical to this:

<?php
namespace Craft;

class WassermanNews_TwitterTask extends BaseTask
{
  public function getDescription()
  {
    return 'Twitter Task';
  }

  public function getTotalSteps()
  {
    return 1;
  }

  public function runStep($step)
  {
    return "twitter step";
  }
}

Any help figuring this out would be much appreciated!

UPDATE:

  1. I just attempted to run the an example and it failed as well. Do certain settings affect how tasks are run?

  2. Installed PixelAndTonic's Power Nap and it failed as well! I did however find a log for this example saying:

    Encountered an error running task 95 (PowerNap): Could not find the task component type.

This makes me wonder what the type of the task has to be! I took a look in TasksService.php and saw that the error is derived from not having a type so what type do tasks need to have?

enter image description here

  • I'm playing with Tasks too, currently. How are you running the Power Nap task? It's working fine for me. Also, not sure what the "type" error is referring to, but to my knowledge I'm not setting a type in my task, nor is one set in Power Nap. – Chase Giunta Dec 23 '15 at 18:48
  • I just added it to my plugins folder and then once I Installed it, I navigated to myurl.dev/actions/powerNap/start to trigger the task – 9er Dec 23 '15 at 18:50
  • If you enable devMode and check craft/storage/runtime/logs are you not getting any task related error message? – Brad Bell Dec 23 '15 at 20:10
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. WassermanNews_TwitterTask.

There's not really any thorough documentation on Tasks, so I can't verify this is the problem, but this is what worked for me.

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');
  • The naming convention trips me up all the time, this reminded me. – Brad Aug 31 '16 at 15:29
0
public function runStep($step)

the $step starts from 0 btw

And be sure to return true in all tasks, if everything works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.