TYPO3 Scheduler

download TYPO3 Scheduler

If you can't read please download the document

  • date post

    10-Jul-2015
  • Category

    Internet

  • view

    895
  • download

    6

Embed Size (px)

description

TYPO3 Scheduler - presentations from typo3camp.pl

Transcript of TYPO3 Scheduler

  • SCHEDULER & CLI

    Krystian Szymukowiczk.szymukowicz@sourcebroker.net

  • PRESENTATION ROADMAP

    WHAT IS SCHEDULER?SCHEDULER FOR USERS

    SCHEDULER FOR DEVELOPERS

    WHAT IS CLI?CLI FOR USERS

    CLI FOR DEVELOPER

    INTERESTING EXTENSIONS

    Krystian Szymukowiczk.szymukowicz@sourcebroker.net

    https://github.com/t33k/schedulerX

  • SCHEDULERmodule to set up and monitor recurring things

  • WHY DO WE NEED SCHEDULER? system extensions and user extensions do not have to

    repeat the code TYPO3 installation is better movable between hostings gives overview of what scheduler jobs are there in system gives overview of what jobs are currently active/running

  • SCHEDULERUSER/INTEGRATOR PERSPECTIVE

  • NOT INSTALLED BY DEFAULT

  • SETTING SCHEDULER MAIN CRONJOB

    When logged to ssh console as www-data user: crontab -e */15 * * * * php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler When logged to ssh console as root then probably better is to: su www-data -ccrontab -e */15 * * * * php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler

    Go to /etc/cron.d/ and create file */15 * * * * www-data php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler

    EDIT USERS CRONTABS.

    EDIT SYSTEM WIDE CRONTABS.

  • Fake cron to run just php script by calling Apache (no CLI) Different PHP version for CLI (works from BE not form CLI) php_memory limit low for CLI (works from BE not form CLI) No way to see errors from CLI on shared hostings.

    Different problems on limited ssh and shared hostings:

    SETTING SCHEDULER MAIN CRONJOB

  • Be ready to fight for Scheduler cron!

    SETTING SCHEDULER MAIN CRONJOB

    "typo3 cli_dispatch.phpsh [hoster name]"Google for:

    Do not hesitate to ask hoster admin!

  • SUCCESS

  • CRON FREQUENCY

    10:00 10:15 10:30 10:45

    /etc/cron.d/*/15 * * * * www-data php /var/www/workspace-typo3/projects/acme/typo3/cli_dispatch.phpsh scheduler

    11:00

    10:0030 45 11:00

    21-11-14 10:10

    21-11-14 10:15

    10 20 405 25 35 50 5515

    Task with id=2 will be late by 10 minutes

  • SCHEDULERDEVELOPER PERSPECTIVE

  • SIMPLE EXT WITH SCHEDULER TASK !typo3conf/ext /Scheduler1 /Classes/Task/SimpleReportTask.php /ext_conf.php /ext_localconf.php

    https://github.com/t33k/scheduler1

  • SIMPLE EXT WITH SCHEDULER TASK Register new extension:

  • SIMPLE EXT WITH SCHEDULER TASK Register new scheduler task:

  • SIMPLE EXT WITH SCHEDULER TASK Class with task:

  • SIMPLE EXT WITH SCHEDULER TASK II https://github.com/t33k/scheduler2

    getAdditonalInformation()getProgress()

    implements \TYPO3\CMS\Scheduler\ProgressProviderInterface()

  • SIMPLE EXT WITH SCHEDULER TASK III

    Standard scheduler task info

    System flash messages

    debug(ArrayUtility::convertObjectToArray($this));

    Flash messages and debug:

    GeneralUtility::devLog(..

  • SIMPLE EXT WITH SCHEDULER TASK III

  • SIMPLE EXT WITH SCHEDULER TASK IV https://github.com/t33k/scheduler4Additional field

  • SIMPLE EXT WITH SCHEDULER TASK IV

    !class SampleTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface{ ! public function getAdditionalFields (array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {} ! public function validateAdditionalFields (array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {} ! public function saveAdditionalFields (array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {}}

    Classes/Task/SampleTaskAdditionalFieldProvider.php

    https://github.com/t33k/scheduler4

  • SIMPLE EXT WITH SCHEDULER TASK V https://github.com/t33k/scheduler5

    Create new tasks automatically in FE and BE

  • SIMPLE EXT WITH SCHEDULER TASK VII Autmaticaly disable task

  • THINGS TO REMEMBERObject is serialized once on creation of scheduler task so all future changes to methods or properties can lead to errors. The solution then is to delete the scheduler task and create new one.

  • CLIUSER PERSPECTIVE

  • CLI !One of SAPI the PHP interact with different env - here with shell. Others SAPI examples: CGI, fpm , apache2handler

    No execution time limit by default. No headers are send. No path is changed while running by default

    Command Line Interface

    CLI points:

  • CLI Command Line Interfacephp typo3/cli_dispatch.phpsh

  • lowlevel_admin setBElock

  • lowlevel_cleaner [option] -r

  • lowlevel_refindex

  • extbase

  • CLIDEVELOPER PERSPECTIVE

  • EXTBASE COMMAND CENTER

    $ php cli_dispatch.phpsh extbase scheduler6:sample:second --name=adam --number=12 --enabled

    This will call:> extension scheduler6> class SampleCommandController > method secondCommand typo3conf/ext/scheduler6/Classes/Command/SampleCommandController.php

    secondCommand($name, $number, $enabled = true)

    $ php cli_dispatch.phpsh extbase --argumentName=value

    Backport from TYPO3 FLOW

  • /** * Class SampleCommandController * @package V\Scheduler6\Command */ class SampleCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController { ! /** * Get Faq title for given uid * * This text goes into description of CLI * so you see when you will do php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:newsTitle. * Second line of description. * Third line of description. * * @param integer $faqUid Faq uid * @return void */ public function faqTitleCommand($faqUid) { $faqUid = intval($faqUid); if ($faqUid) { $faqRepository = $this->getFaqRepository(); $faq = $faqRepository->findByUid($faqUid); if(NULL !== $faq){ $this->outputLine($faq->getQuestion()); } } }

    typo3conf/ext/scheduler6/Classes/Command/SampleCommandController.php

  • php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:faqTitleAll texts are taken from class comment / arguments !!!

  • EXTBASE COMMAND CENTER

    /** * Class SampleCommandController * @package V\Scheduler6\Command */ class SampleCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController { ! /** * Get Faq title for given uid * * This text goes into description of CLI * so you see when you will do php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:newsTitle. * Second line of description. * Third line of description. * * @param integer $faqUid Faq uid * @return void */ public function faqTitleCommand($faqUid) { $faqUid = intval($faqUid); if ($faqUid) { $faqRepository = $this->getFaqRepository(); $faq = $faqRepository->findByUid($faqUid); if(NULL !== $faq){ $this->outputLine($faq->getQuestion()); } } }

    typo3conf/ext/scheduler6/Classes/Command/SampleCommandController.php

  • EXTBASE COMMAND CENTER

  • SCHEDULER/CLIINTERESTING EXTENSIONS

  • CLEARTYPO3CACHE$ php cli_dispatch.phpsh cleartypo3cache all$ php cli_dispatch.phpsh cleartypo3cache pages

    Create BE user "_cli_cleartypo3cache" with TS settingsoptions.clearCache.all=1 options.clearCache.pages=1 options.clearCache.system=1

    $ php cli_dispatch.phpsh cleartypo3cache system

    https://github.com/t33k/cleartypo3cache

  • CLEARTYPO3CACHE https://github.com/t33k/cleartypo3cache

  • T3DEPLOYphp typo3/cli_dispatch.phpsh t3deploy database updateStructure --verbose --execute

    https://github.com/AOEmedia/t3deploy

    php typo3/cli_dispatch.phpsh t3deploy database updateStructure --remove --verbose --execute

    Update only (more safe)

    Remove also

  • THANK YOU!

    Krystian Szymukowiczk.szymukowicz@sourcebroker.net