Closed MisterFoxi closed 8 years ago
Whats the file location exactly? Note the casing!
it’s under project/src/Shell/Task
and its name is QueueGetKeyTask.php
The queue shell detect it as it appears in the list and it’s just a basic ‘empty’ task like you can see. I know it might be something utterly obvious but after few hours looking at it i can;t figure it out.
thanks :)
namespace App\Shell;
use Queue\Shell\Task\QueueTask;
use Cake\ORM\TableRegistry;
use Cake\Controller\Component;
use Cake\Error\Debugger;
use Cake\Log\log;
use Pheal\Pheal;
use Cake\Core\App;
use Cake\Controller\ComponentRegistry;
/**
* A Simple QueueTask example.
*/
class QueueGetKeyTask extends QueueTask {
/**
* @var \Queue\Model\Table\QueuedTasksTable
*/
public $QueuedTasks;
/**
* Timeout for run, after which the Task is reassigned to a new worker.
*
* @var int
*/
public $timeout = 10;
/**
* Number of times a failed instance of this task should be restarted before giving up.
*
* @var int
*/
public $retries = 5;
/**
* Stores any failure messages triggered during run()
*
* @var string
*/
public $failureMessage = 'Unable to collect information.';
/**
* Example add functionality.
* Will create one example job in the queue, which later will be executed using run();
*
* @return void
*/
public function add() {
$this->out('Fetch evekey api data.');
$this->hr();
$this->out('You can find the sourcecode of this task in: ');
$this->out(__FILE__);
$this->out(' ');
/*
* Adding a task of type 'example' with no additionally passed data
*/
// $this->$EveApi = $this->loadComponent('EveGetCharacterSheet');
$data = [
'KeyId' => $this->args[1],
'Vcode' => $this->args[2]
];
if ($this->QueuedTasks->createJob('GetKey', $data)) {
$this->out('OK, job created, now run the worker');
} else {
$this->err('Could not create Job');
}
}
/**
* Example run function.
* This function is executed, when a worker is executing a task.
* The return parameter will determine, if the task will be marked completed, or be requeued.
*
* @param array $data The array passed to QueuedTask->createJob()
* @param int|null $id The id of the QueuedTask
* @return bool Success
*/
public function run($data, $id = null) {
if (!isset($data['Vcode'])) {
$this->err('no Vcode parameter.');
return false;
}
if (!isset($data['KeyId'])) {
$this->err('no KeyId parameter.');
return false;
}
$this->hr();
$this->out('CakePHP GetEveKey task.');
$this->hr();
$this->out(' ->Success, tGetEveKey Job was run.<-');
$this->out($data['KeyId']);
$this->out($data['Vcode']);
return true;
}
}
Le 29 août 2016 à 14:13, Mark Sch. notifications@github.com a écrit :
Whats the file location exactly? Note the casing!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dereuromark/cakephp-queue/issues/104#issuecomment-243106945, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBIvGNjZhBkeExJRFbDFVWy0HLkXaoCks5qkszVgaJpZM4JvXSa.
@MisterFoxi in your custom Task use:
namespace App\Shell\Task;
Instead of:
namespace App\Shell;
Hi, I try to run a custom task and got an exception error: Task class QueueGetkey could not be found.
The file is located under src/shell/task and named appropriately and contains: use Queue\Shell\Task\QueueTask; as stated in the doc.
The namespace is changed too.
I suppose i miss something obvious but so far i can't see what.
Thanks for your support !