Download the PHP package thunderwolf/sf-task-logger-plugin without Composer

On this page you can find all versions of the php package thunderwolf/sf-task-logger-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sf-task-logger-plugin

sfTaskLoggerPlugin

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/tasks/:TASK_NAMESPACE/:TASK_NAME). It allows you to have a clean log history of all the CRON executed by your symfony project.

The database record stores the following informations:

The plugin base task has several useful options:

Note The plugin is both 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. (I am sorry but I didn't test the Propel version with the last 1.4 package, so feel free to report me issues if you use it with Propel. Neither the admin generator module is available.)

Installation

Or for Propel:

    $ symfony propel:build-all-load

Note At this point you should have

  • A new table called tl_tasks in your database
  • A new set of model classes in lib/model/sfTaskLoggerPlugin or lib/model/doctrine/sfTaskLoggerPlugin

Configuration

The plugin comes with a base task class which is named sfBaseTaskLoggerTask Therefore your tasks must extend this one. Because there is no auto-loading at the task level, one must include it manually:

[php]
require_once(dirname(__FILE__). '/sfBaseTaskLoggerTask.class.php');

Note 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, use the following code.

Generally you will want to extend all your tasks with a custom project task so all of them will benefit from its generic methods, arguments or options (thus, it must stay abstract). It would looks like this:

[php]
/**
 * This the base task for all tasks of myProject.
 *
 * @author COil
 * @since  01/09/2010
 */

require_once(dirname(__FILE__). '/../../plugins/sfTaskLoggerPlugin/lib/task/sfBaseTaskLoggerTask.class.php');

abstract class mySuperBaseTask extends sfBaseTaskLoggerTask
{
  /**
   * This function is callable by all the project tasks.
   */
  public function superFunction()
  {
  }
}

Your final task should extends this custom task and look like this:

[php]
/**
 * This a custom task
 *
 * @author Vernet Loïc aka COil <qrf_coil]at[yahoo[dot]fr>
 * @since  1.0.0 - 7 aug 2009
 */
class sfMyTask extends mySuperBaseTask
{
  // check the following section for functions to implement
}

Moreover the plugin comes with a default YAML configuration file, this file allows you to tell if you want to log into the database, a file or both:

Usage

In your task (like sfMyTask above):

Now there are 2 specific methods to implement:

Note This method can be useful if you have advanced controls to do on task parameters or arguments. Raise an InvalidArgumentException if there is at least an invalid parameter. Don't forget to call at first the parent function so generic parameters can be checked at the base task level. (or at your project base task level)

Note 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 status flag automatically depending on the success or failure of the task. We also set a status code that will give more details than success or not about how ended the process.

If you want to resume a batch process from a given id, you can use the last_id_processed field for this purpose.

Finally, if you want more control on the task process you can also re-implement the execute() method of the base class which is responsible for calling all others sub functions:

[php]
/**
 * Global process of the task.
 *
 * @see sfTask
 */
protected function execute($arguments = array(), $options = array())
{
  $this->createContext();

  $this->config = $this->checkAndGetConfig($options['config']);

  $this->checkConfig();

  $this->setParameters($arguments, $options);

  $this->initDatabaseManager();

  $this->checkParameters($arguments, $options);

  $this->initLogger();

  $this->logStart();

  $this->doProcess($arguments, $options);

  $this->logEnd();
}

Admin generator module

The plugin comes with a handy admin generator module (Doctrine, symfony >= 1.2) in order to manage the main tl_task table.

Add the module tl_task to the enabled module list of the settings.yml file of your application.

    enabled_modules:  [default, tl_task]

After having generated all the model files of the plugin, edit the /lib/model/doctrine/sfTaskLoggerPlugin/tlTaskTable.class.php class and make it extend the class PlugintlTaskTableExtended:

[php]
/**
 * tlTaskTable
 *
 * This class has been auto-generated by the Doctrine ORM Framework
 */
class tlTaskTable extends PlugintlTaskTableExtended
{
    /**
     * Returns an instance of this class.
     *
     * @return object tlTaskTable
     */
    public static function getInstance()
    {
        return Doctrine_Core::getTable('tlTask');
    }
}

Then call the module, you_backend.php/tl_task ! That's it ! ;)

Note The plugin comes with a route tl_task for this admin generator module.

Notes

Note The plugin is bundled with a sample task: /lib/task/sfTaskLoggerSampleTask.class.php which can be run with the following command (replace "frontend" with a valid application name of your project and "dev" with a valid environment):

> ./symfony task-logger:sample --application="frontend" --env="dev"

And also with a task: /lib/task/sfTaskLoggerPurgeRunningTask.class.php to purge tasks who ended with a fatal error and which stayed with the running flag to "ON":

> ./symfony task-logger:purge --task="myProject:myTask" --application=backend --env="dev"

Console output

You may want to have your console output disabled when running cron tasks, for example because of some server related configuration - in this case, add the --quiet option to your cli command line:

 ./symfony task-logger:sample --application=frontend --env="prod" --quiet

TODO

Support

Send me an email or report bugs on the symfony TRAC, I could also answer if you ask on the symfony mailing list.

Changelog

(check the changelog tab)


See you. COil :)


This plugin is sponsored by SQL Technologies

SQL Technologies


All versions of sf-task-logger-plugin with dependencies

PHP Build Version
Package Version
Requires composer/installers Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package thunderwolf/sf-task-logger-plugin contains the following files

Loading the files please wait ....