-
Carsten Rose authoredCarsten Rose authored
System.rst 8.64 KiB
System
AutoCron
The AutoCron service fires periodically jobs like open a webpage (typically a QFQ page which does some database actions) or send mail.
- AutoCron will be triggered via system cron. Minimal time distance therefore is 1 minute. If this is not sufficient, any process who starts .../typo3conf/ext/qfq/Classes/External/autocron.php via /usr/bin/php frequently might be used.
- Custom start time and frequency.
- Per job:
- If a job still runs and receives the next trigger, the running job will be completed first.
- If more than one trigger arrives during a run, only one trigger will be processed.
- If the system misses a run, it will be played as soon as the system is online again.
- If multiple runs are missed, only one run is fired as soon as the system is online again.
- Running and processed jobs can easily be monitored via lastRun, lastStatus, nextRun, inProgress.
Setup
- Setup a system cron entry, typically as the webserver user ('www-data' on debian).
- Necessary privileges:
- Read for .../typo3conf/ext/qfq/*
- Write, if a logfile should be written (specified per cron job) in the custom specified directory.
Cron task (user cron tab):
* * * * * /usr/bin/php /var/www/html/typo3conf/ext/qfq/Classes/External/autocron.php
AutoCron Jobs of type 'website' needs the php.ini setting:
allow_url_fopen = On
Remember: if a cron job fails for whatever reason, the cron daemon will send a mail to the userid who started the cron job. E.g. www-data. Setup a email forward of such account to a frequently read email account.
Create / edit AutoCron jobs
Create a T3 page with a QFQ record (similar to the formeditor). Such page should be access restricted and is only needed to edit AutoCron jobs:
dbIndex={{indexQfq:Y}}
form={{form:S}}
10 {
# Table header.
sql = SELECT CONCAT('p:{{pageSlug:T}}?form=cron') AS _pagen, 'id', 'Next run','Frequency','Comment'
, 'Last run','In progress', 'Status', 'Auto generated'
head = <table class='table table-hover qfq-table-50'>
tail = </table>
rbeg = <thead><tr>
rend = </tr></thead>
fbeg = <th>
fend = </th>
10 {
# All Cron Jobs
sql = SELECT CONCAT('<tr class="'
, IF(c.lastStatus LIKE 'Error%','danger','')
, IF(c.inProgress!=0 AND DATE_ADD(c.inProgress, INTERVAL 10 MINUTE)<NOW(),' warning','')
, IF(c.status='enable','',' text-muted'),'" '
, IF(c.inProgress!=0 AND DATE_ADD(c.inProgress, INTERVAL 10 MINUTE)<NOW(),'title="inProgress > 10mins"'
, IF(c.lastStatus LIKE 'Error%','title="Status: Error"',''))
, '>')
, '<td>', CONCAT('p:{{pageSlug:T}}?form=cron&r=', c.id) AS _pagee, '</td><td>'
, c.id, '</td><td>'
, IF( c.nextrun=0,"", DATE_FORMAT(c.nextrun, "%d.%m.%y %H:%i:%s")), '</td><td>'
, c.frequency, '</td><td>'
, c.comment, '</td><td>'
, IF(c.lastrun=0,"", DATE_FORMAT(c.lastrun,"%d.%m.%y %H:%i:%s")), '</td><td>'
, IF(c.inProgress=0,"", DATE_FORMAT(c.inProgress,"%d.%m.%y %H:%i:%s")), '</td><td>'
, LEFT(c.laststatus,40) AS '_+pre', '</td><td>'
, c.autoGenerated
, CONCAT('U:form=cron&r=', c.id) AS _paged, '</td></tr>'
FROM Cron AS c
ORDER BY c.id
}
}
Or you can use the following code in a separate QFQ record for the twig version of autoCron:
file=_autoCronTwig