sfTaskLoggerPlugin
1.0.0stable
for sf 1.2 MIT
The sfTaskLoggerPlugin allows you to run custom tasks and store the results. Results are stored in the database in a specific table and/or in a log file. Each task
has its own log file, which is stored in a specific directory depending on its namespace and name. (/log/task/:TASK_NAMESPACE/:TASK_NAME). It allows you to have a clean log history of all the CRON executed by your symfony project.
Developers
| Name |
Status |
Email |
Vernet Loïc |
lead |
rf.oohay <<ta>> lioc_frq
|
License
Plugin by Vernet Loïc aka COil. (qrf_coil[at]yahoo[dot]fr)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfTaskLoggerPlugin
The sfTaskLoggerPlugin allow you to run tasks and store the results. Results
are stored in the database in a specific table and also in a log file. Each task
has its own log file, witch is stored in a specific directory depending on its
namespace and name. (/log/tasks/:TASK_NAMESPACE/:TASK_NAME).
The database record stores the following informations:
- An error code
- Start and end time
- A success flag
- The log file path
- Extra comments (for admin)
The plugin is Doctrine and
Propel friendly, it you are using Doctrine, the
/lib/config/doctrine/schema.yml will be used whereas using Propel
the /lib/config/schema.yml will be used.
Installation
Configuration
The plugin comes with a base task class witch is named sfBaseTaskLoggerTask
Therefore your tasks must extend this one. Because there is no autoloading at
the task level. Therefore, one must include the base class manually:
require_once(dirname(__FILE__). '/sfBaseTaskLoggerTask.class.php');
Of course you will have to change this path depending on where is located your
task. For example if it is located in the /lib/task folder of your project,
the include directive should look like this:
require_once(dirname(__FILE__). '/../../plugins/sfTaskLoggerPlugin/lib/task/sfBaseTaskLoggerTask.class.php');
Usage
1 - Create a new class that extends the plugin base class:
class sfTaskLoggerSampleTask extends sfBaseTaskLoggerTask
2 - Implement the configure() method as you would do with a standart task:
/**
* Main task configuration.
*/
protected function configure()
{
$this->addOptions(array(
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'Environment used', 'prod'),
));
$this->namespace = 'sf_task_logger';
$this->name = 'sample';
$this->briefDescription = 'This is a sample task !';
$this->detailedDescription = <<<EOF
The task [sf_task_logger:sample|INFO] doesn't do that much.
It logs itself in the database and in the file system:
[./symfony sf_task_logger:sample --env=prod|INFO]
EOF;
}
Now there are 2 specific methods to implement:
This method can be usefull if you have advanced controls to do on task parameters or
arguments. Just return true if you don't have to use it.
This is the main method of your task process. $this->task is the database
object that will be saved. As you can see the setOk() and setNOk methods
allow to set the flag of the record automatically depending on the success or
failure of the task.
If you want more control on the task process you can also re-implement the execute()
method of the base class witch is responsible for calling all others sub functions:
/**
* Global process of the task.
*
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$this->setParameters($arguments, $options);
$this->checkParameters($arguments, $options);
$this->initDatabaseManager();
$this->initLogger();
$this->logStart();
$this->doProcess();
$this->logEnd();
}
Notes
The plugin is bundled with a sample task: /lib/task/sfTaskLoggerSampleTask.class
witch can be run with the following command:
> ./symfony sf_task_logger:sample
TODO
- Log arguments and parameters of task ? Will be done on the next release
depending on feedback.
- Include admin generator module ?
Support
Please report bugs on the symfony TRAC, i could also answer if you ask on the
symfony mailing list or IRC.
Changelog
- 1.0.0
- Initial version for symfony 1.2
See you. COil :)
This plugin is sponsored by SQL Technologies
