FINAL suepr merge step : added all modules to this super repos
243
sites/all/modules/contrib/dev/ultimate_cron/CronRule.class.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* This class parses cron rules and determines last execution time using least case integer comparison.
|
||||
*/
|
||||
|
||||
class CronRule {
|
||||
|
||||
public $rule = NULL;
|
||||
public $allow_shorthand = FALSE;
|
||||
private static $ranges = array(
|
||||
'minutes' => array(0, 59),
|
||||
'hours' => array(0, 23),
|
||||
'days' => array(1, 31),
|
||||
'months' => array(1, 12),
|
||||
'weekdays' => array(0, 6),
|
||||
);
|
||||
|
||||
private $parsed_rule = array();
|
||||
public $offset = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct($rule = NULL) {
|
||||
$this->rule = $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand interval from cronrule part
|
||||
*
|
||||
* @param $matches (e.g. 4-43/5+2)
|
||||
* array of matches:
|
||||
* [1] = lower
|
||||
* [2] = upper
|
||||
* [5] = step
|
||||
* [7] = offset
|
||||
*
|
||||
* @return
|
||||
* (string) comma-separated list of values
|
||||
*/
|
||||
function expandInterval($matches) {
|
||||
$result = array();
|
||||
|
||||
$lower = $matches[1];
|
||||
$upper = $matches[2];
|
||||
$step = isset($matches[5]) ? $matches[5] : 1;
|
||||
$offset = isset($matches[7]) ? $matches[7] : 0;
|
||||
|
||||
if ($step <= 0) return '';
|
||||
$step = ($step > 0) ? $step : 1;
|
||||
for ($i = $lower; $i <= $upper; $i+=$step) {
|
||||
$result[] = ($i + $offset) % ($upper + 1);
|
||||
}
|
||||
return implode(',', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand range from cronrule part
|
||||
*
|
||||
* @param $rule
|
||||
* (string) cronrule part, e.g.: 1,2,3,4-43/5
|
||||
* @param $max
|
||||
* (string) boundaries, e.g.: 0-59
|
||||
* @param $digits
|
||||
* (int) number of digits of value (leading zeroes)
|
||||
* @return
|
||||
* (array) array of valid values
|
||||
*/
|
||||
function expandRange($rule, $type) {
|
||||
$max = implode('-', self::$ranges[$type]);
|
||||
$rule = str_replace("*", $max, $rule);
|
||||
$rule = str_replace("@", $this->offset % (self::$ranges[$type][1] + 1), $rule);
|
||||
$this->parsed_rule[$type] = $rule;
|
||||
$rule = preg_replace_callback('!(\d+)-(\d+)((/(\d+))?(\+(\d+))?)?!', array($this, 'expandInterval'), $rule);
|
||||
if (!preg_match('/([^0-9\,])/', $rule)) {
|
||||
$rule = explode(',', $rule);
|
||||
rsort($rule);
|
||||
}
|
||||
else {
|
||||
$rule = array();
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre process rule.
|
||||
*
|
||||
* @param array &$parts
|
||||
*/
|
||||
function preProcessRule(&$parts) {
|
||||
// Allow JAN-DEC
|
||||
$months = array(1 => 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
|
||||
$parts[3] = strtr(strtolower($parts[3]), array_flip($months));
|
||||
|
||||
// Allow SUN-SUN
|
||||
$days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
|
||||
$parts[4] = strtr(strtolower($parts[4]), array_flip($days));
|
||||
$parts[4] = str_replace('7', '0', $parts[4]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process rule
|
||||
*
|
||||
* @param array $intervals
|
||||
*/
|
||||
function postProcessRule(&$intervals) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate regex rules
|
||||
*
|
||||
* @param $rule
|
||||
* (string) cronrule, e.g: 1,2,3,4-43/5 * * * 2,5
|
||||
* @return
|
||||
* (array) date and time regular expression for mathing rule
|
||||
*/
|
||||
function getIntervals($rule = NULL) {
|
||||
$parts = preg_split('/\s+/', isset($rule) ? $rule : $this->rule);
|
||||
if ($this->allow_shorthand) $parts += array('*', '*', '*', '*', '*'); // Allow short rules by appending wildcards?
|
||||
if (count($parts) != 5) return FALSE;
|
||||
$this->preProcessRule($parts);
|
||||
$intervals = array();
|
||||
$intervals['minutes'] = $this->expandRange($parts[0], 'minutes');
|
||||
if (empty($intervals['minutes'])) return FALSE;
|
||||
$intervals['hours'] = $this->expandRange($parts[1], 'hours');
|
||||
if (empty($intervals['hours'])) return FALSE;
|
||||
$intervals['days'] = $this->expandRange($parts[2], 'days');
|
||||
if (empty($intervals['days'])) return FALSE;
|
||||
$intervals['months'] = $this->expandRange($parts[3], 'months');
|
||||
if (empty($intervals['months'])) return FALSE;
|
||||
$intervals['weekdays'] = $this->expandRange($parts[4], 'weekdays');
|
||||
if (empty($intervals['weekdays'])) return FALSE;
|
||||
$intervals['weekdays'] = array_flip($intervals['weekdays']);
|
||||
$this->postProcessRule($intervals);
|
||||
|
||||
return $intervals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert intervals back into crontab rule format
|
||||
*/
|
||||
function rebuildRule($intervals) {
|
||||
$parts = array();
|
||||
foreach ($intervals as $type => $interval) {
|
||||
$parts[] = $this->parsed_rule[$type];
|
||||
}
|
||||
return implode(' ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse rule. Run through parser expanding expression, and recombine into crontab syntax.
|
||||
*/
|
||||
function parseRule() {
|
||||
return $this->rebuildRule($this->getIntervals());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last execution time of rule in unix timestamp format
|
||||
*
|
||||
* @param $time
|
||||
* (int) time to use as relative time (default now)
|
||||
* @return
|
||||
* (int) unix timestamp of last execution time
|
||||
*/
|
||||
function getLastRan($time = NULL) {
|
||||
// Current time round to last minute
|
||||
if (!isset($time)) $time = time();
|
||||
$time = floor($time / 60) * 60;
|
||||
|
||||
// Generate regular expressions from rule
|
||||
$intervals = $this->getIntervals();
|
||||
if ($intervals === FALSE) return FALSE;
|
||||
|
||||
// Get starting points
|
||||
$start_year = date('Y', $time);
|
||||
$end_year = $start_year - 28; // Go back max 28 years (leapyear * weekdays)
|
||||
$start_month = date('n', $time);
|
||||
$start_day = date('j', $time);
|
||||
$start_hour = date('G', $time);
|
||||
$start_minute = (int)date('i', $time);
|
||||
|
||||
// If both weekday and days are restricted, then use either or
|
||||
// otherwise, use and ... when using or, we have to try out all the days in the month
|
||||
// and not just to the ones restricted
|
||||
$check_both = (count($intervals['days']) != 31 && count($intervals['weekdays']) != 7) ? FALSE : TRUE;
|
||||
$days = $check_both ? $intervals['days'] : range(31, 1);
|
||||
|
||||
// Find last date and time this rule was run
|
||||
for ($year = $start_year; $year > $end_year; $year--) {
|
||||
foreach ($intervals['months'] as $month) {
|
||||
if ($month < 1 || $month > 12) continue;
|
||||
if ($year >= $start_year && $month > $start_month) continue;
|
||||
|
||||
foreach ($days as $day) {
|
||||
if ($day < 1 || $day > 31) continue;
|
||||
if ($year >= $start_year && $month >= $start_month && $day > $start_day) continue;
|
||||
if (!checkdate($month, $day, $year)) continue;
|
||||
|
||||
// Check days and weekdays using and/or logic
|
||||
$date_array = getdate(mktime(0, 0, 0, $month, $day, $year));
|
||||
if ($check_both) {
|
||||
if (!isset($intervals['weekdays'][$date_array['wday']])) continue;
|
||||
}
|
||||
else {
|
||||
if (
|
||||
!in_array($day, $intervals['days']) &&
|
||||
!isset($intervals['weekdays'][$date_array['wday']])
|
||||
) continue;
|
||||
}
|
||||
|
||||
if ($day != $start_day || $month != $start_month || $year != $start_year) {
|
||||
$start_hour = 23;
|
||||
$start_minute = 59;
|
||||
}
|
||||
foreach ($intervals['hours'] as $hour) {
|
||||
if ($hour < 0 || $hour > 23) continue;
|
||||
if ($hour > $start_hour) continue;
|
||||
if ($hour < $start_hour) $start_minute = 59;
|
||||
foreach ($intervals['minutes'] as $minute) {
|
||||
if ($minute < 0 || $minute > 59) continue;
|
||||
if ($minute > $start_minute) continue;
|
||||
break 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create unix timestamp from derived date+time
|
||||
$time = mktime($hour, $minute, 0, $month, $day, $year);
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a rule is valid
|
||||
*/
|
||||
function isValid($time = NULL) {
|
||||
return $this->getLastRan($time) === FALSE ? FALSE : TRUE;
|
||||
}
|
||||
}
|
2
sites/all/modules/contrib/dev/ultimate_cron/INSTALL.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Set your crontab to wget cron.php once per minute (* * * * *). If this is not possible, activate the Poormans cron function in the Ultimate Cron settings.
|
||||
|
339
sites/all/modules/contrib/dev/ultimate_cron/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
84
sites/all/modules/contrib/dev/ultimate_cron/README.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
Thanks to Mark James for the icons
|
||||
http://www.famfamfam.com/lab/icons/silk/
|
||||
|
||||
|
||||
Example code:
|
||||
|
||||
|
||||
// Default cron-function, configurable through /admin/build/cron/settings
|
||||
function mymodule_cron() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
|
||||
|
||||
// Define custom cron functions
|
||||
function mymodule_cronapi($op, $job = NULL) {
|
||||
switch($op) {
|
||||
case 'list':
|
||||
return array(
|
||||
'mymodule_cronjob_1' => 'Cron-1 Handler',
|
||||
'mymodule_cronjob_2' => 'Cron-2 Handler',
|
||||
'mymodule_cronjob_3' => 'Cron-3 Handler',
|
||||
);
|
||||
|
||||
case 'rule':
|
||||
switch($job) {
|
||||
case 'mymodule_cronjob_1': return '*/13 * * * *';
|
||||
case 'mymodule_cronjob_2': return '0 0 1 * *';
|
||||
);
|
||||
|
||||
case 'execute':
|
||||
switch($job) {
|
||||
case 'mymodule_cronjob_2':
|
||||
mymodule_somefunction();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Custom cron-function
|
||||
function mymodule_cronjob_1() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
|
||||
// Custom cron-function
|
||||
function mymodule_somefunction() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
|
||||
// Custom cron-function
|
||||
function mymodule_cronjob_3() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
|
||||
// Easy-hook, uses rule: 0 * * * *
|
||||
function mymodule_hourly() {
|
||||
// Do some stuff
|
||||
}
|
||||
|
||||
// Easy-hook, uses rule: 0 0 * * *
|
||||
function mymodule_daily() {
|
||||
// Do some stuff
|
||||
}
|
||||
|
||||
// Easy-hook, uses rule: 0 0 * * 1
|
||||
function mymodule_weekly() {
|
||||
// Do some stuff
|
||||
}
|
||||
|
||||
// Easy-hook, uses rule: 0 0 1 * *
|
||||
function mymodule_monthly() {
|
||||
// Do some stuff
|
||||
}
|
||||
|
||||
// Easy-hook, uses rule: 0 0 1 1 *
|
||||
function mymodule_yearly() {
|
||||
// Do some stuff
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,65 @@
|
||||
.ultimate-cron-admin-status a {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-status span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-status-info,
|
||||
.ultimate-cron-admin-status-error,
|
||||
.ultimate-cron-admin-status-success,
|
||||
.ultimate-cron-admin-status-warning,
|
||||
.ultimate-cron-admin-status-running {
|
||||
background-position: center !important;
|
||||
background-repeat: no-repeat !important;
|
||||
}
|
||||
|
||||
a.ultimate-cron-admin-status-info,
|
||||
a.ultimate-cron-admin-status-info:hover,
|
||||
a.ultimate-cron-admin-status-error,
|
||||
a.ultimate-cron-admin-status-error:hover,
|
||||
a.ultimate-cron-admin-status-success,
|
||||
a.ultimate-cron-admin-status-success:hover,
|
||||
a.ultimate-cron-admin-status-warning,
|
||||
a.ultimate-cron-admin-status-warning:hover,
|
||||
a.ultimate-cron-admin-status-running,
|
||||
a.ultimate-cron-admin-status-running:hover {
|
||||
padding-left: 24px !important;
|
||||
background-position: 5px center !important;
|
||||
background-repeat: no-repeat !important;
|
||||
}
|
||||
|
||||
|
||||
.ultimate-cron-admin-status-info {
|
||||
background-image: url(../icons/message-16-info.png) !important;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-status-error {
|
||||
background-image: url(../icons/message-16-error.png) !important;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-status-success {
|
||||
background-image: url(../icons/message-16-ok.png) !important;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-status-warning {
|
||||
background-image: url(../icons/message-16-warning.png) !important;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-status-running {
|
||||
background-image: url(../icons/hourglass.png) !important;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-start,
|
||||
.ultimate-cron-admin-end,
|
||||
.ultimate-cron-admin-duration,
|
||||
.ultimate-cron-admin-rules {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ultimate-cron-admin-message {
|
||||
white-space: pre-line;
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
Every minute, a cron job is checked whether it should run or not.
|
||||
|
||||
<pre>*/10 * * * *</pre>
|
||||
|
||||
is equivilant of
|
||||
|
||||
<pre>0,10,20,30,40,50 * * * *</pre>
|
||||
|
||||
and runs every hour at the minutes 0,10,20,30,40,50.
|
||||
|
||||
If for some reason (connection congestion, server crash, etc.) that Ultimate Cron cannot launch the job, e.g. 10:30, then normally, the job won't attempted to be launched again until 10:40.
|
||||
|
||||
The <em>catch up</em> compensates for this, allowing the job to be launched anyway until a certain time. The <em>Catch up</em> value is in seconds, so if it is set to 300, the job will launch at 10:31-35 if it did not launch at 10:30
|
||||
|
@@ -0,0 +1 @@
|
||||
Logs for each cron job are stored in database. To prevent the database from accumulating much unnecessary information, Ultimate Cron cleans up old log. How old a log entry should be, before it is removed, is controlled by this setting.
|
@@ -0,0 +1 @@
|
||||
<p>Easy hooks are shortcuts for specific implementations of cron jobs, instead of using hook_cronapi()</p>
|
@@ -0,0 +1 @@
|
||||
This is the regular cron hook for Drupal. See the Drupal documentation for this.
|
@@ -0,0 +1,48 @@
|
||||
<p>The hook_cron_alter(&$hooks) allows you to change the cron hooks defined by hook_cron() and hook_cronapi().</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>Change default rules for the Node modules cron hook and hi-jack system cron:</p>
|
||||
<pre>
|
||||
function hook_cron_alter(&$hooks) {
|
||||
$hooks['node_cron']['settings']['rules'] = array('0 * * * *');
|
||||
$hooks['system_cron']['module'] = 'mymodule';
|
||||
$hooks['system_cron']['callback'] = 'mymodule_new_system_cron';
|
||||
$hooks['system_cron']['file'] = drupal_get_path('module', 'mymodule') . '/mymodule.cron.inc';
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>Example of the Node modules cron hook data:</p>
|
||||
<pre>
|
||||
(
|
||||
[unsafe] =>
|
||||
[description] => Default cron handler
|
||||
[module] => node
|
||||
[configure] =>
|
||||
[settings] => Array
|
||||
(
|
||||
[enabled] => 1
|
||||
[rules] => Array
|
||||
(
|
||||
[0] => * * * * *
|
||||
)
|
||||
|
||||
[catch_up] => 300
|
||||
)
|
||||
|
||||
[function] => node_cron
|
||||
[callback] => node_cron
|
||||
)
|
||||
</pre>
|
||||
|
||||
<h3>Description of data structure</h3>
|
||||
<table border="1">
|
||||
<tr><th>Name</th><th>Description</th></tr>
|
||||
<tr><td>unsafe</td><td>If true, then the cron hook is considered unsafe, meaning that Ultimate Cron will not execute it. This value is set by Ultimate Cron when determining which hooks are unsafe. A hook is considered unsafe, if the function resides in a module with a weight lower than Ultimate Cron.</td></tr>
|
||||
<tr><td>description</td><td>The description of the cron hook, usally defined in hook_cronapi(). The core modules description are added through a hook_cron_alter() in Ultimate Cron.</td></tr>
|
||||
<tr><td>module</td><td>Name of the module in which the cron hook lives</td></tr>
|
||||
<tr><td>configure</td><td>Link to module settings page</td></tr>
|
||||
<tr><td>settings</td><td>Array with settings data, contains enabled, rules and catch_up by default, provided by Ultimate Cron</td></tr>
|
||||
<tr><td>function</td><td>Name of function for the cron hook. Note: This is unsafe to change</td></tr>
|
||||
<tr><td>callback</td><td>Name of callback to use when executing cron. This is set to the cron hooks function by default</td></tr>
|
||||
<tr><td>file</td><td>Path to file (including filename) where callback is defined.</td></tr>
|
||||
</table>
|
@@ -0,0 +1,11 @@
|
||||
<p>The hook_cron_post_execute($function, &$hook) is invoked just after running the cron function.</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>Log that node_cron is done</p>
|
||||
<pre>
|
||||
function hook_cron_post_execute($function, &$hook) {
|
||||
if ($function == 'node_cron') {
|
||||
error_log('node_cron is done');
|
||||
}
|
||||
}
|
||||
</pre>
|
@@ -0,0 +1,9 @@
|
||||
<p>The hook_cron_post_execute_FUNCTION(&$hook) is invoked just after running the cron function.</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>Log that node_cron is done</p>
|
||||
<pre>
|
||||
function hook_cron_post_execute_node_cron($function, &$hook) {
|
||||
error_log('node_cron is done');
|
||||
}
|
||||
</pre>
|
@@ -0,0 +1,15 @@
|
||||
<p>The hook_cron_pre_execute($function, &$hook) is invoked just before running the cron function.</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>Call another function instead of the defined</p>
|
||||
<pre>
|
||||
function hook_cron_pre_execute($function, &$hook) {
|
||||
if ($function == 'node_cron') {
|
||||
$hook['callback'] = 'mymodule_steal_cron_function_from_node_module';
|
||||
}
|
||||
}
|
||||
|
||||
function mymodule_steal_cron_function_from_node_module() {
|
||||
error_log('PWNED');
|
||||
}
|
||||
</pre>
|
@@ -0,0 +1,14 @@
|
||||
<p>The hook_cron_pre_execute_FUNCTION(&$hook) is invoked just before running the cron function.</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>Call another function instead of the defined</p>
|
||||
<pre>
|
||||
function hook_cron_pre_execute_node_cron(&$hook) {
|
||||
$hook['callback'] = 'mymodule_steal_cron_function_from_node_module';
|
||||
}
|
||||
|
||||
function mymodule_steal_cron_function_from_node_module() {
|
||||
error_log('PWNED');
|
||||
}
|
||||
</pre>
|
||||
|
@@ -0,0 +1,11 @@
|
||||
<p>The hook_cron_schedule_alter(&$hooks) allows you to change the cron hooks that are scheduled to be run.</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>Don't run node_cron if 2 + 2 = 4</p>
|
||||
<pre>
|
||||
function hook_cron_schedule_alter(&$hooks) {
|
||||
if (2 + 2 = 4) {
|
||||
unset($hooks['node_cron']);
|
||||
}
|
||||
}
|
||||
</pre>
|
@@ -0,0 +1,58 @@
|
||||
<p>The hook_cronapi($op, $function = NULL) allows you to define new cronjobs</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
// Define custom cron functions
|
||||
function mymodule_cronapi($op, $function = NULL) {
|
||||
switch($op) {
|
||||
case 'list':
|
||||
return array(
|
||||
'mymodule_cronjob_1' => 'Cron-1 Handler',
|
||||
'mymodule_cronjob_2' => 'Cron-2 Handler',
|
||||
'mymodule_cronjob_3' => 'Cron-3 Handler',
|
||||
);
|
||||
|
||||
case 'rule':
|
||||
switch($function) {
|
||||
case 'mymodule_cronjob_1': return '*/13 * * * *';
|
||||
case 'mymodule_cronjob_2': return '0 0 1 * *';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'execute':
|
||||
switch($function) {
|
||||
case 'mymodule_cronjob_2':
|
||||
mymodule_somefunction();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'settings':
|
||||
switch ($function) {
|
||||
// 'mymodule_cronjob_3' disabled by default
|
||||
case 'mymodule_cronjob_3': return array('enabled' => FALSE);
|
||||
}
|
||||
|
||||
case 'configure':
|
||||
switch ($function) {
|
||||
case 'mymodule_cronjob_3': return 'admin/configure-modules-settings/xxx';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom cron-function
|
||||
function mymodule_cronjob_1() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
|
||||
// Custom cron-function
|
||||
function mymodule_somefunction() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
|
||||
// Custom cron-function
|
||||
function mymodule_cronjob_3() {
|
||||
// Do some stuff ...
|
||||
}
|
||||
</pre>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
If you just want a cron job that runs once per day by default, you can use hook_daily().
|
||||
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
// Easy-hook, uses rule: 0 0 * * *
|
||||
function mymodule_daily() {
|
||||
// Do some stuff
|
||||
}
|
||||
</pre>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
If you just want a cron job that runs once per hour by default, you can use hook_hourly().
|
||||
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
// Easy-hook, uses rule: 0 * * * *
|
||||
function mymodule_hourly() {
|
||||
// Do some stuff
|
||||
}
|
||||
</pre>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
If you just want a cron job that runs once a month by default, you can use hook_monthly().
|
||||
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
// Easy-hook, uses rule: 0 0 1 * *
|
||||
function mymodule_monthly() {
|
||||
// Do some stuff
|
||||
}
|
||||
</pre>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
If you just want a cron job that runs once a week by default, you can use hook_weekly().
|
||||
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
// Easy-hook, uses rule: 0 0 * * 1
|
||||
function mymodule_weekly() {
|
||||
// Do some stuff
|
||||
}
|
||||
</pre>
|
||||
|
@@ -0,0 +1,12 @@
|
||||
If you just want a cron job that runs once a year by default, you can use hook_yearly().
|
||||
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
// Easy-hook, uses rule: 0 0 1 1 *
|
||||
function mymodule_yearly() {
|
||||
// Do some stuff
|
||||
}
|
||||
</pre>
|
||||
|
||||
P.S.: It's okay to laugh. The use case for this hook is very likely non-existent.
|
||||
|
@@ -0,0 +1 @@
|
||||
This section explains how to use the hooks implemented by Ultimate Cron.
|
@@ -0,0 +1 @@
|
||||
When setting a polling latency, Ultimate Cron continuously processing queues, and polls for new items in the queue every X miliseconds.
|
@@ -0,0 +1 @@
|
||||
For installations where it is not possible to control the systems cron tab, Poormans cron makes sure, that cron is run every minute. On each request to the server, it checks if the Poormans service is running, and if not, it launches it. The poormans cron launcher is delegated to the <em>ultimate_cron_poorman</em> service host.
|
38
sites/all/modules/contrib/dev/ultimate_cron/help/rules.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<h3>Fields order</h3>
|
||||
<pre>
|
||||
+---------------- minute (0 - 59)
|
||||
| +------------- hour (0 - 23)
|
||||
| | +---------- day of month (1 - 31)
|
||||
| | | +------- month (1 - 12)
|
||||
| | | | +---- day of week (0 - 7) (Sunday=0)
|
||||
| | | | |
|
||||
* * * * *
|
||||
</pre>
|
||||
<p>Each of the patterns from the first five fields may be either * (an asterisk),
|
||||
which matches all legal values, or a list of elements separated by commas (see below).</p>
|
||||
<p>For "day of the week" (field 5), 0 is considered Sunday, 6 is Saturday
|
||||
(7 is an illegal value)</p>
|
||||
<p>A job is executed when the time/date specification fields all match the current
|
||||
time and date. There is one exception: if both "day of month" and "day of week"
|
||||
are restricted (not "*"), then either the "day of month" field (3) or the "day of week"
|
||||
field (5) must match the current day (even though the other of the two fields
|
||||
need not match the current day).</p>
|
||||
|
||||
<h3>Fields operators</h3>
|
||||
<p>There are several ways of specifying multiple date/time values in a field:</p>
|
||||
<ul>
|
||||
<li>The comma (',') operator specifies a list of values, for example: "1,3,4,7,8"</li>
|
||||
<li>The dash ('-') operator specifies a range of values, for example: "1-6", which is equivalent to "1,2,3,4,5,6"</li>
|
||||
<li>The asterisk ('*') operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to 'every hour' (subject to matching other specified fields).</li>
|
||||
<li>The slash ('/') operator (called "step") can be used to skip a given number of values. For example, "*/3" in the hour time field is equivalent to "0,3,6,9,12,15,18,21".</li>
|
||||
<li>The plus ('+') operator (called "offset") can be used as an offset to a given range. For example, "*/10+2" in the hour minute field is equivalent to "2,12,22,32,42,52".</li>
|
||||
</ul>
|
||||
|
||||
<h3>Examples</h3>
|
||||
<pre>
|
||||
*/15 * * * : Execute job every 15 minutes
|
||||
0 2,14 * * *: Execute job every day at 2:00 and 14:00
|
||||
0 2 * * 1-5: Execute job at 2:00 of every working day
|
||||
0 12 1 */2 1: Execute job every 2 month, at 12:00 of first day of the month OR at every monday.
|
||||
</pre>
|
||||
|
@@ -0,0 +1,3 @@
|
||||
Service groups are controlled by the Background Process module.
|
||||
|
||||
Ultimate Cron can delegate a cron job to specific service group.
|
@@ -0,0 +1 @@
|
||||
This section contains help for all the settings in Ultimate Cron.
|
@@ -0,0 +1 @@
|
||||
Every minute, Ultimate Cron launches all scheduled jobs. To prevent congestion, it is possible to limit the amount of cron jobs running at any given time.
|
@@ -0,0 +1,114 @@
|
||||
[settings]
|
||||
title = Settings
|
||||
file = settings
|
||||
|
||||
[catch_up]
|
||||
title = Catch up
|
||||
file = catch_up
|
||||
parent = settings
|
||||
|
||||
[rules]
|
||||
title = Rules
|
||||
file = rules
|
||||
parent = settings
|
||||
|
||||
[polling_latency]
|
||||
title = Polling latency
|
||||
file = polling_latency
|
||||
parent = settings
|
||||
|
||||
[simultaneous_connections]
|
||||
title = Simultaneous connections
|
||||
file = simultaneous_connections
|
||||
parent = settings
|
||||
|
||||
[cleanup_log]
|
||||
title = Cleanup log
|
||||
file = cleanup_log
|
||||
parent = settings
|
||||
|
||||
[poorman]
|
||||
title = Poormans cron
|
||||
file = poorman
|
||||
parent = settings
|
||||
|
||||
[service_group]
|
||||
title = Service group
|
||||
file = service_group
|
||||
parent = settings
|
||||
|
||||
[hooks]
|
||||
title = Hooks
|
||||
file = hooks
|
||||
|
||||
[hook_cron]
|
||||
title = hook_cron
|
||||
file = hook_cron
|
||||
parent = hooks
|
||||
|
||||
[hook_cronapi]
|
||||
title = hook_cronapi
|
||||
file = hook_cronapi
|
||||
parent = hooks
|
||||
|
||||
[hook_cron_alter]
|
||||
title = hook_cron_alter
|
||||
file = hook_cron_alter
|
||||
parent = hooks
|
||||
|
||||
[hook_cron_schedule_alter]
|
||||
title = hook_cron_schedule_alter
|
||||
file = hook_cron_schedule_alter
|
||||
parent = hooks
|
||||
|
||||
[hook_cron_pre_execute]
|
||||
title = hook_cron_pre_execute
|
||||
file = hook_cron_pre_execute
|
||||
parent = hooks
|
||||
|
||||
[hook_cron_pre_execute_FUNCTION]
|
||||
title = hook_cron_pre_execute_FUNCTION
|
||||
file = hook_cron_pre_execute_function
|
||||
parent = hooks
|
||||
|
||||
[hook_cron_post_execute]
|
||||
title = hook_cron_post_execute
|
||||
file = hook_cron_post_execute
|
||||
parent = hooks
|
||||
|
||||
[hook_cron_post_execute_FUNCTION]
|
||||
title = hook_cron_post_execute_FUNCTION
|
||||
file = hook_cron_post_execute_function
|
||||
parent = hooks
|
||||
|
||||
[easy_hooks]
|
||||
title = Easy hooks
|
||||
file = easy_hooks
|
||||
parent = hooks
|
||||
|
||||
[hook_hourly]
|
||||
title = hook_hourly
|
||||
file = hook_hourly
|
||||
parent = easy_hooks
|
||||
|
||||
[hook_daily]
|
||||
title = hook_daily
|
||||
file = hook_daily
|
||||
parent = easy_hooks
|
||||
|
||||
[hook_weekly]
|
||||
title = hook_weekly
|
||||
file = hook_weekly
|
||||
parent = easy_hooks
|
||||
|
||||
[hook_monthly]
|
||||
title = hook_monthly
|
||||
file = hook_monthly
|
||||
parent = easy_hooks
|
||||
|
||||
[hook_yearly]
|
||||
title = hook_yearly
|
||||
file = hook_yearly
|
||||
parent = easy_hooks
|
||||
|
||||
|
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/add.png
Normal file
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 714 B |
After Width: | Height: | Size: 634 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/chart_line.png
Normal file
After Width: | Height: | Size: 526 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/cog.png
Normal file
After Width: | Height: | Size: 512 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/delete.png
Normal file
After Width: | Height: | Size: 715 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/error.png
Normal file
After Width: | Height: | Size: 666 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/hourglass.png
Normal file
After Width: | Height: | Size: 744 B |
After Width: | Height: | Size: 778 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/lock_open.png
Normal file
After Width: | Height: | Size: 727 B |
After Width: | Height: | Size: 519 B |
After Width: | Height: | Size: 668 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 639 B |
After Width: | Height: | Size: 442 B |
BIN
sites/all/modules/contrib/dev/ultimate_cron/icons/tick.png
Normal file
After Width: | Height: | Size: 537 B |
@@ -0,0 +1,211 @@
|
||||
/* ===============================
|
||||
| TABLESORT.JS
|
||||
| Copyright, Andy Croxall (mitya@mitya.co.uk)
|
||||
| For documentation and demo see http://mitya.co.uk/scripts/Animated-table-sort-REGEXP-friendly-111
|
||||
|
|
||||
| USAGE
|
||||
| This script may be used, distributed and modified freely but this header must remain in tact.
|
||||
| For usage info and demo, including info on args and params, see www.mitya.co.uk/scripts
|
||||
=============================== */
|
||||
|
||||
|
||||
jQuery.fn.sortTable = function(params) {
|
||||
|
||||
|
||||
/*-----------
|
||||
| STOP right now if anim already in progress
|
||||
-----------*/
|
||||
|
||||
if ($(this).find(':animated').length > 0) return;
|
||||
|
||||
/*-----------
|
||||
| VALIDATE TABLE & PARAMS
|
||||
| - if no col to sort on passed, complain and return
|
||||
| - if table doesn't contain requested col, complain and return
|
||||
| If !sortType or invalid sortType, assume ascii sort
|
||||
-----------*/
|
||||
|
||||
var error = null;
|
||||
var complain = null;
|
||||
if (!params.onCol) { error = "No column specified to search on"; complain = true; }
|
||||
else if ($(this).find('td:nth-child('+params.onCol+')').length == 0) { error = "The requested column wasn't found in the table"; complain = true; }
|
||||
if (error) { if (complain) alert(error); return; }
|
||||
if (!params.sortType || params.sortType != 'numeric') params.sortType = 'ascii';
|
||||
|
||||
|
||||
/*-----------
|
||||
| PREP
|
||||
| - declare array to store the contents of each <td>, or, if sorting on regexp, the pattern match of the regexp in each <td>
|
||||
| - Give the <table> position: relative to aid animation
|
||||
| - Mark the col we're sorting on with an identifier class
|
||||
-----------*/
|
||||
|
||||
var valuesToSort = [];
|
||||
$(this).css('position', 'relative');
|
||||
var doneAnimating = 0;
|
||||
var tdSelectorText = 'td'+(!params.onCol ? '' : ':nth-child('+params.onCol+')');
|
||||
$(this).find('td:nth-child('+params.onCol+')').addClass('sortOnThisCol');
|
||||
var thiss = this;
|
||||
|
||||
|
||||
/*-----------
|
||||
| Iterate over table and. For each:
|
||||
| - append its content / regexp match (see above) to valuesToSort[]
|
||||
| - create a new <div>, give it position: absolute and copy over the <td>'s content into it
|
||||
| - fix the <td>'s width/height to its offset width/height so that, when we remove its html, it won't change shape
|
||||
| - clear the <td>'s content
|
||||
| - clear the <td>'s content
|
||||
| There is no visual effect in this. But it means each <td>'s content is now 'animatable', since it's position: absolute.
|
||||
-----------*/
|
||||
|
||||
var counter = 0;
|
||||
$(this).find('td').each(function() {
|
||||
if ($(this).is('.sortOnThisCol') || (!params.onCol && !params.keepRelationships)) {
|
||||
var valForSort = !params.child ? $(this).text() : (params.child != 'input' ? $(this).find(params.child).text() : $(this).find(params.child).val());
|
||||
if (params.regexp) {
|
||||
valForSort = valForSort.match(new RegExp(params.regexp))[!params.regexpIndex ? 0 : params.regexpIndex];
|
||||
}
|
||||
valuesToSort.push(valForSort);
|
||||
}
|
||||
var thisTDHTMLHolder = document.createElement('div');
|
||||
with($(thisTDHTMLHolder)) {
|
||||
html($(this).html());
|
||||
if (params.child && params.child == 'input') html(html().replace(/<input /, "<input value='"+$(this).find(params.child).val()+"'", html()));
|
||||
css({position: 'relative', left: 0, top: 0});
|
||||
}
|
||||
$(this).html('');
|
||||
$(this).append(thisTDHTMLHolder);
|
||||
counter++;
|
||||
});
|
||||
|
||||
|
||||
/*-----------
|
||||
| Sort values array.
|
||||
| - Sort (either simply, on ascii, or numeric if sortNumeric == true)
|
||||
| - If descending == true, reverse after sort
|
||||
-----------*/
|
||||
|
||||
params.sortType == 'numeric' ? valuesToSort.sort(function(a, b) { return (a.replace(/[^\d\.]/g, '', a)-b.replace(/[^\d\.]/g, '', b)); }) : valuesToSort.sort();
|
||||
if (params.sortDesc) {
|
||||
valuesToSort_tempCopy = [];
|
||||
for(var u=valuesToSort.length; u--; u>=0) valuesToSort_tempCopy.push(valuesToSort[u]);
|
||||
valuesToSort = valuesToSort_tempCopy;
|
||||
delete(valuesToSort_tempCopy)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------
|
||||
| Now, for each:
|
||||
-----------*/
|
||||
|
||||
for(var k in valuesToSort) {
|
||||
|
||||
//establish current <td> relating to this value of the array
|
||||
var currTD = $($(this).find(tdSelectorText).filter(function() {
|
||||
return (
|
||||
(
|
||||
!params.regexp
|
||||
&&
|
||||
(
|
||||
(
|
||||
params.child
|
||||
&&
|
||||
(
|
||||
(
|
||||
params.child != 'input'
|
||||
&&
|
||||
valuesToSort[k] == $(this).find(params.child).text()
|
||||
)
|
||||
||
|
||||
params.child == 'input'
|
||||
&&
|
||||
valuesToSort[k] == $(this).find(params.child).val()
|
||||
)
|
||||
)
|
||||
||
|
||||
(
|
||||
!params.child
|
||||
&&
|
||||
valuesToSort[k] == $(this).children('div').html()
|
||||
)
|
||||
)
|
||||
)
|
||||
||
|
||||
(
|
||||
params.regexp
|
||||
&&
|
||||
$(this).children('div').html().match(new RegExp(params.regexp))[!params.regexpIndex ? 0 : params.regexpIndex] == valuesToSort[k]
|
||||
)
|
||||
)
|
||||
&&
|
||||
!$(this).hasClass('tableSort_TDRepopulated');
|
||||
}).get(0));
|
||||
|
||||
//give current <td> a class to mark it as having been used, so we don't get confused with duplicate values
|
||||
currTD.addClass('tableSort_TDRepopulated');
|
||||
|
||||
//establish target <td> for this value and store as a node reference on this <td>
|
||||
var targetTD = $($(this).find(tdSelectorText).get(k));
|
||||
currTD.get(0).toTD = targetTD;
|
||||
|
||||
//if we're sorting on a particular column and maintaining relationships, also give the other <td>s in rows a node reference
|
||||
//denoting ITS target, so they move with their lead siibling
|
||||
if (params.keepRelationships) {
|
||||
var counter = 0;
|
||||
$(currTD).parent().children('td').each(function() {
|
||||
$(this).get(0).toTD = $(targetTD.parent().children().get(counter));
|
||||
counter++;
|
||||
});
|
||||
}
|
||||
|
||||
//establish current relative positions for the current and target <td>s and use this to calculate how far each <div> needs to move
|
||||
var currPos = currTD.position();
|
||||
var targetPos = targetTD.position();
|
||||
var moveBy_top = targetPos.top - currPos.top;
|
||||
|
||||
//invert values if going backwards/upwards
|
||||
if (targetPos.top > currPos.top) moveBy_top = Math.abs(moveBy_top);
|
||||
|
||||
/*-----------
|
||||
| ANIMATE
|
||||
| - work out what to animate on.
|
||||
| - if !keepRelationships, animate only <td>s in the col we're sorting on (identified by .sortOnThisCol)
|
||||
| - if keepRelationships, animate all cols but <td>s that aren't .sortOnThisCol follow lead sibiling with .sortOnThisCol
|
||||
| - run animation. On callback, update each <td> with content of <div> that just moved into it and remove <div>s
|
||||
| - If noAnim, we'll still run aniamte() but give it a low duration so it appears instant
|
||||
-----------*/
|
||||
|
||||
var animateOn = params.keepRelationships ? currTD.add(currTD.siblings()) : currTD;
|
||||
var done = 0;
|
||||
animateOn.children('div').animate({top: moveBy_top}, !params.noAnim ? 500 : 0, null, function() {
|
||||
if ($(this).parent().is('.sortOnThisCol') || !params.keepRelationships) {
|
||||
done++;
|
||||
if (done == valuesToSort.length-1) thiss.tableSort_cleanUp();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
jQuery.fn.tableSort_cleanUp = function() {
|
||||
|
||||
/*-----------
|
||||
| AFTER ANIM
|
||||
| - assign each <td> its new content as property of it (DON'T populate it yet - this <td> may still need to be read by
|
||||
| other <td>s' toTD node references
|
||||
| - once new contents for each <td> gathered, populate
|
||||
| - remove some identifier classes and properties
|
||||
-----------*/
|
||||
$(this).find('td').each(function() {
|
||||
if($(this).get(0).toTD) $($(this).get(0).toTD).get(0).newHTML = $(this).children('div').html();
|
||||
});
|
||||
$(this).find('td').each(function() { $(this).html($(this).get(0).newHTML); });
|
||||
$('td.tableSort_TDRepopulated').removeClass('tableSort_TDRepopulated');
|
||||
$(this).find('.sortOnThisCol').removeClass('sortOnThisCol');
|
||||
$(this).find('td[newHTML]').attr('newHTML', '');
|
||||
$(this).find('td[toTD]').attr('toTD', '');
|
||||
|
||||
};
|
4
sites/all/modules/contrib/dev/ultimate_cron/js/jquery.tablesorter.min.js
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
(function ($) {
|
||||
|
||||
|
||||
$(function() {
|
||||
// Ping Drupal for initial status of processes.
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/admin/ultimate-cron/service/process-status',
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
success: function (result) {
|
||||
// Drupal.settings.ultimate_cron.initial_processes = result.processes;
|
||||
// Drupal.settings.ultimate_cron.processes = result.processes;
|
||||
// setTimeout(&ultimateCronInitialProcess, 100);
|
||||
}
|
||||
});
|
||||
|
||||
// Setup progress counter
|
||||
setInterval(function() {
|
||||
var time = (new Date()).getTime() / 1000;
|
||||
$.each(Drupal.settings.ultimate_cron.processes, function (name, process) {
|
||||
if (process.exec_status == 2) {
|
||||
var row = 'row-' + name;
|
||||
var seconds = Math.round((time - Drupal.settings.ultimate_cron.skew) - process.start_stamp);
|
||||
seconds = seconds < 0 ? 0 : seconds;
|
||||
var formatted = (new Date(seconds * 1000)).toISOString().substring(11, 19);
|
||||
if (process.progress > 0) {
|
||||
var progress = Math.round(process.progress * 100);
|
||||
formatted += ' (' + progress + '%)';
|
||||
}
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status-running').closest('tr.' + row).find('td.ultimate-cron-admin-end').html(formatted);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
});
|
||||
|
||||
Drupal.Nodejs.callbacks.nodejsBackgroundProcess = {
|
||||
updateSkew: function (time) {
|
||||
jsTime = (new Date()).getTime() / 1000;
|
||||
Drupal.settings.ultimate_cron.skew = jsTime - time;
|
||||
},
|
||||
|
||||
callback: function (message) {
|
||||
var action = message.data.action;
|
||||
if (
|
||||
// action != 'locked' &&
|
||||
action != 'claimed' &&
|
||||
action != 'dispatch' &&
|
||||
// action != 'remove' &&
|
||||
action != 'setProgress' &&
|
||||
action != 'ultimateCronStatus'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
var process = message.data.background_process;
|
||||
var ultimate_cron = message.data.ultimate_cron;
|
||||
var regex = new RegExp('^' + Drupal.settings.ultimate_cron.handle_prefix);
|
||||
var name = process.handle.replace(regex, '');
|
||||
if (name == process.handle) {
|
||||
return;
|
||||
}
|
||||
name = encodeURIComponent(name).replace(/%/, '_');
|
||||
Drupal.settings.ultimate_cron.processes[name] = process;
|
||||
|
||||
var row = 'row-' + name;
|
||||
|
||||
switch (action) {
|
||||
case 'dispatch':
|
||||
this.updateSkew(message.data.timestamp);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('class', 'ultimate-cron-admin-status ultimate-cron-admin-status-running');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-start').html(ultimate_cron.start_stamp);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-end').html(Drupal.t('Starting'));
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').html('<span>' + Drupal.t('Starting') + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('title', Drupal.t('Running on !service_host', {'!service_host': process.service_host ? process.service_host : Drupal.t('N/A')}));
|
||||
var link = $('tr.' + row + ' td.ultimate-cron-admin-execute a');
|
||||
link.attr('href', ultimate_cron.unlockURL);
|
||||
link.attr('title', Drupal.t('Unlock'));
|
||||
link.html('<span>' + Drupal.t('Unlock') + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-execute').attr('class', 'ultimate-cron-admin-unlock');
|
||||
break;
|
||||
case 'claimed':
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('class', 'ultimate-cron-admin-status ultimate-cron-admin-status-running');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-start').html(ultimate_cron.start_stamp);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-end').html('00:00:00');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').html('<span>' + Drupal.t('Running') + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('title', Drupal.t('Running on !service_host', {'!service_host': process.service_host ? process.service_host : Drupal.t('N/A')}));
|
||||
var link = $('tr.' + row + ' td.ultimate-cron-admin-execute a');
|
||||
link.attr('href', ultimate_cron.unlockURL);
|
||||
link.attr('title', Drupal.t('Unlock'));
|
||||
link.html('<span>' + Drupal.t('Unlock') + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-execute').attr('class', 'ultimate-cron-admin-unlock');
|
||||
break;
|
||||
case 'setProgress':
|
||||
this.updateSkew(message.data.timestamp);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('class', 'ultimate-cron-admin-status ultimate-cron-admin-status-running');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-start').html(ultimate_cron.start_stamp);
|
||||
// $('tr.' + row + ' td.ultimate-cron-admin-end').html(ultimate_cron.progress);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').html('<span>' + Drupal.t('Running') + '</span>');
|
||||
// $('tr.' + row + ' td.ultimate-cron-admin-status').attr('title', Drupal.t('Running on !service_host', {'!service_host': process.service_host ? process.service_host : Drupal.t('N/A')}));
|
||||
var link = $('tr.' + row + ' td.ultimate-cron-admin-execute a');
|
||||
link.attr('href', ultimate_cron.unlockURL);
|
||||
link.attr('title', Drupal.t('Unlock'));
|
||||
link.html('<span>' + Drupal.t('Unlock') + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-execute').attr('class', 'ultimate-cron-admin-unlock');
|
||||
break;
|
||||
case 'ultimateCronStatus':
|
||||
switch (parseInt(process.exec_status)) {
|
||||
case 1:
|
||||
message.data.action = 'dispatch';
|
||||
return this.callback(message);
|
||||
case 2:
|
||||
message.data.action = 'setProgress';
|
||||
return this.callback(message);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
var sel = location.hash.substring(1);
|
||||
sel = sel ? sel : 'show-all';
|
||||
$('a#ultimate-cron-' + sel).trigger('click');
|
||||
}
|
||||
};
|
||||
|
||||
Drupal.Nodejs.callbacks.nodejsProgress = {
|
||||
callback: function (message) {
|
||||
switch (message.data.action) {
|
||||
case 'setProgress':
|
||||
return Drupal.Nodejs.callbacks.nodejsBackgroundProcess.callback(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Drupal.Nodejs.callbacks.nodejsUltimateCron = {
|
||||
callback: function (message) {
|
||||
var action = message.data.action;
|
||||
switch (action) {
|
||||
case 'log':
|
||||
var log = message.data.log;
|
||||
var name = encodeURIComponent(log.name).replace(/%/, '_');
|
||||
delete Drupal.settings.ultimate_cron.processes[name];
|
||||
var row = 'row-' + name;
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('class', 'ultimate-cron-admin-status ultimate-cron-admin-status-' + log.formatted.severity);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').html('<span>' + log.severity + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-status').attr('title', log.formatted.msg ? log.formatted.msg : Drupal.t('No errors'));
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-start').html(log.formatted.start_stamp);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-start').attr('title', Drupal.t('Previous run started @ !timestamp', {'!timestamp': log.formatted.start_stamp}));
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-end').html(log.formatted.duration);
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-end').attr('title', Drupal.t('Previous run finished @ !timestamp', {'!timestamp': log.formatted.end_stamp}));
|
||||
var link = $('tr.' + row + ' td.ultimate-cron-admin-unlock a');
|
||||
link.attr('href', log.formatted.executeURL);
|
||||
link.attr('title', Drupal.t('Run'));
|
||||
link.html('<span>' + Drupal.t('Run') + '</span>');
|
||||
$('tr.' + row + ' td.ultimate-cron-admin-unlock').attr('class', 'ultimate-cron-admin-execute');
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
var sel = location.hash.substring(1);
|
||||
sel = sel ? sel : 'show-all';
|
||||
$('a#ultimate-cron-' + sel).trigger('click');
|
||||
}
|
||||
};
|
||||
|
||||
}(jQuery));
|
||||
|
@@ -0,0 +1,46 @@
|
||||
jQuery(document).ready(function($) {
|
||||
// @todo Make client side status switch work on all themes?
|
||||
return;
|
||||
|
||||
$('a[href$="admin/config/system/cron"]').click(function() {
|
||||
$(".ultimate-cron-admin-status").parent().show();
|
||||
$(this).parent().siblings().removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
return false;
|
||||
});
|
||||
$('a[href$="admin/config/system/cron/overview/error"]').click(function() {
|
||||
$("tr .ultimate-cron-admin-status:not(.ultimate-cron-admin-status-error)").parent().hide();
|
||||
$("tr .ultimate-cron-admin-status-error").parent().show();
|
||||
$(this).parent().siblings().removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
return false;
|
||||
});
|
||||
$('a[href$="admin/config/system/cron/overview/warning"]').click(function() {
|
||||
$("tr .ultimate-cron-admin-status:not(.ultimate-cron-admin-status-warning)").parent().hide();
|
||||
$("tr .ultimate-cron-admin-status-warning").parent().show();
|
||||
$(this).parent().siblings().removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
return false;
|
||||
});
|
||||
$('a[href$="admin/config/system/cron/overview/info"]').click(function() {
|
||||
$("tr .ultimate-cron-admin-status:not(.ultimate-cron-admin-status-info)").parent().hide();
|
||||
$("tr .ultimate-cron-admin-status-info").parent().show();
|
||||
$(this).parent().siblings().removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
return false;
|
||||
});
|
||||
$('a[href$="admin/config/system/cron/overview/success"]').click(function() {
|
||||
$("tr .ultimate-cron-admin-status:not(.ultimate-cron-admin-status-success)").parent().hide();
|
||||
$("tr .ultimate-cron-admin-status-success").parent().show();
|
||||
$(this).parent().siblings().removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
return false;
|
||||
});
|
||||
$('a[href$="admin/config/system/cron/overview/running"]').click(function() {
|
||||
$("tr .ultimate-cron-admin-status:not(.ultimate-cron-admin-status-running)").parent().hide();
|
||||
$("tr .ultimate-cron-admin-status-running").parent().show();
|
||||
$(this).parent().siblings().removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
return false;
|
||||
});
|
||||
});
|
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
|
||||
<head>
|
||||
<?php print $head ?>
|
||||
<title><?php print $head_title ?></title>
|
||||
<?php print $styles ?>
|
||||
<?php print $scripts ?>
|
||||
</head>
|
||||
<body>
|
||||
<?php print $content ?>
|
||||
</body>
|
||||
</html>
|
173
sites/all/modules/contrib/dev/ultimate_cron/tests/rules.test
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Tests for Ultimate Cron's cron parser
|
||||
*/
|
||||
class UltimateCronRulesUnitTestCase extends DrupalUnitTestCase {
|
||||
function setUp() {
|
||||
parent::setUp('ultimate_cron');
|
||||
}
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Rules',
|
||||
'description' => 'Test crontab rules parser.',
|
||||
'group' => 'Cron',
|
||||
);
|
||||
}
|
||||
|
||||
private function runTest($options) {
|
||||
// Setup values
|
||||
$options['rules'] = is_array($options['rules']) ? $options['rules'] : array($options['rules']);
|
||||
$options['catch_up'] = isset($options['catch_up']) ? $options['catch_up'] : 86400 * 365; // @todo Adapting Elysia Cron test cases with a catchup of 1 year
|
||||
|
||||
// Generate result message
|
||||
require_once dirname(__FILE__) . '/../CronRule.class.php';
|
||||
$message = array();
|
||||
foreach ($options['rules'] as $rule) {
|
||||
$cron = new CronRule($rule);
|
||||
$intervals = $cron->getIntervals();
|
||||
$parsed_rule = '';
|
||||
foreach ($intervals as $key => $value) {
|
||||
$parsed_rule .= "$key: " . implode(',', $value) . "\n";
|
||||
}
|
||||
#$parsed_rule = str_replace(" ", "\n", $cron->rebuildRule($cron->getIntervals()));
|
||||
$last_scheduled = $cron->getLastRan(strtotime($options['now']));
|
||||
$message[] = "<span title=\"$parsed_rule\">$rule</span> @ " . date('Y-m-d H:i:s', $last_scheduled);
|
||||
}
|
||||
$message[] = 'now @ ' . $options['now'];
|
||||
$message[] = 'last-run @ ' . $options['last_run'];
|
||||
$message[] = 'catch-up @ ' . $options['catch_up'];
|
||||
$message[] = ($options['result'] ? '' : 'not ') . 'expected to run';
|
||||
|
||||
// Do the actual test
|
||||
$result = ultimate_cron_should_run($options['rules'], strtotime($options['last_run']), strtotime($options['now']), $options['catch_up']);
|
||||
|
||||
return array($options['result'] == $result, implode('<br/>', $message));
|
||||
}
|
||||
|
||||
function testRules() {
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '0 12 * * *' , 'last_run' => '2008-01-02 12:00:00', 'now' => '2008-01-02 12:01:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '0 12 * * *' , 'last_run' => '2008-01-02 12:00:00', 'now' => '2008-01-02 15:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '0 12 * * *' , 'last_run' => '2008-01-02 12:00:00', 'now' => '2008-01-03 11:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '0 12 * * *' , 'last_run' => '2008-01-02 12:00:00', 'now' => '2008-01-03 12:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * * *' , 'last_run' => '2008-01-02 23:59:00', 'now' => '2008-01-03 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * *' , 'last_run' => '2008-01-02 23:59:00', 'now' => '2008-01-03 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * *' , 'last_run' => '2008-01-02 23:59:00', 'now' => '2008-01-04 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * *' , 'last_run' => '2008-01-02 23:58:00', 'now' => '2008-01-02 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * *' , 'last_run' => '2008-01-02 23:58:00', 'now' => '2008-01-03 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-05 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-06 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-06 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-07 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-06 23:29:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-06 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-05 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-06 23:58:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:58:00', 'now' => '2008-01-06 23:28:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:28:00', 'now' => '2008-01-05 23:29:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:28:00', 'now' => '2008-01-05 23:30:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:28:00', 'now' => '2008-01-05 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '29,59 23 * * 0' , 'last_run' => '2008-01-05 23:28:00', 'now' => '2008-01-06 23:29:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '29,59 23 * * 5' , 'last_run' => '2008-02-22 23:59:00', 'now' => '2008-02-28 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '29,59 23 * * 5' , 'last_run' => '2008-02-22 23:59:00', 'now' => '2008-02-29 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '29,59 23 * * 5' , 'last_run' => '2008-02-22 23:59:00', 'now' => '2008-03-01 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * * 3' , 'last_run' => '2008-12-31 23:59:00', 'now' => '2009-01-01 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * * 3' , 'last_run' => '2008-12-31 23:59:00', 'now' => '2009-01-07 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * * 3' , 'last_run' => '2008-12-31 23:59:00', 'now' => '2009-01-07 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * 2 5' , 'last_run' => '2008-02-22 23:59:00', 'now' => '2008-02-29 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * 2 5' , 'last_run' => '2008-02-22 23:59:00', 'now' => '2008-03-01 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * 2 5' , 'last_run' => '2008-02-29 23:59:00', 'now' => '2008-03-07 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 * 2 5' , 'last_run' => '2008-02-29 23:59:00', 'now' => '2009-02-06 23:58:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 * 2 5' , 'last_run' => '2008-02-29 23:59:00', 'now' => '2009-02-06 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 */10 * *' , 'last_run' => '2008-01-10 23:58:00', 'now' => '2008-01-10 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 */10 * *' , 'last_run' => '2008-01-10 23:59:00', 'now' => '2008-01-11 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 */10 * *' , 'last_run' => '2008-01-10 23:59:00', 'now' => '2008-01-20 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5,10-15 * *' , 'last_run' => '2008-01-04 23:59:00', 'now' => '2008-01-05 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5,10-15 * *' , 'last_run' => '2008-01-04 23:59:00', 'now' => '2008-01-06 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 1-5,10-15 * *' , 'last_run' => '2008-01-05 23:59:00', 'now' => '2008-01-06 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 1-5,10-15 * *' , 'last_run' => '2008-01-05 23:59:00', 'now' => '2008-01-10 23:58:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5,10-15 * *' , 'last_run' => '2008-01-05 23:59:00', 'now' => '2008-01-10 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5,10-15 * *' , 'last_run' => '2008-01-05 23:59:00', 'now' => '2008-01-16 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-01-04 23:59:00', 'now' => '2008-01-05 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-01-05 23:59:00', 'now' => '2008-01-06 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-01-06 23:59:00', 'now' => '2008-01-07 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-01-06 23:59:00', 'now' => '2008-01-13 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-02-04 23:59:00', 'now' => '2008-02-05 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-02-05 23:59:00', 'now' => '2008-02-10 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '59 23 1-5 1 0' , 'last_run' => '2008-02-10 23:59:00', 'now' => '2008-02-17 23:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 08:58:00', 'now' => '2008-02-10 08:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 08:59:00', 'now' => '2008-02-10 09:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 08:59:00', 'now' => '2008-02-10 17:59:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 08:59:00', 'now' => '2008-02-10 18:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 18:00:00', 'now' => '2008-02-10 18:01:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 18:00:00', 'now' => '2008-02-10 19:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => '2008-02-10 18:00:00', 'now' => '2008-03-10 09:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
}
|
||||
|
||||
function testRulesExtended() {
|
||||
$result = $this->runTest(array('result' => FALSE, 'rules' => '0 0 * jan,oct *', 'last_run' => '2008-01-31 00:00:00', 'now' => '2008-03-10 09:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
$result = $this->runTest(array('result' => TRUE , 'rules' => '0 0 * jan,oct *', 'last_run' => '2008-01-31 00:00:00', 'now' => '2008-10-01 00:00:00'));
|
||||
$this->assertTRUE($result[0], $result[1]);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,702 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback: runs cron and returns to status-report page.
|
||||
*/
|
||||
function ultimate_cron_run_cron() {
|
||||
// Run the cron and return
|
||||
ultimate_cron_cron_run(TRUE);
|
||||
drupal_goto('admin/reports/status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form.
|
||||
*/
|
||||
function ultimate_cron_settings_form() {
|
||||
$form = array();
|
||||
$advanced_help_enabled = module_exists('advanced_help');
|
||||
// General settings -----------------------------------
|
||||
$form['general'] = array(
|
||||
'#title' => t('General'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
'#tree' => FALSE,
|
||||
);
|
||||
$form['general']['ultimate_cron_handle_prefix'] = array(
|
||||
'#title' => t("Handle prefix"),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'handle_prefix',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Handle prefix. Use with care. Changing this from the default value ("' . ULTIMATE_CRON_HANDLE_PREFIX . '"), might break compatibility with 3rd party modules. Also, make sure that no jobs are running when changing this.'),
|
||||
);
|
||||
$form['general']['ultimate_cron_simultaneous_connections'] = array(
|
||||
'#title' => t("Simultaneous connections"),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_simultaneous_connections', ULTIMATE_CRON_SIMULTANEOUS_CONNECTIONS),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'simultaneous_connections',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Maximum number of simultaneous connections'),
|
||||
);
|
||||
$form['general']['ultimate_cron_rule'] = array(
|
||||
'#title' => t("Default rule"),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_rule', ULTIMATE_CRON_RULE),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'rules',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Enter the default fallback rule'),
|
||||
);
|
||||
$form['general']['ultimate_cron_cleanup_log'] = array(
|
||||
'#title' => t("Clean up logs older than X seconds"),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_cleanup_log', ULTIMATE_CRON_CLEANUP_LOG),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'cleanup_log',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Enter maximum age, in seconds, for log entries'),
|
||||
);
|
||||
$form['general']['ultimate_cron_catch_up'] = array(
|
||||
'#title' => t('Default catch up'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_catch_up', ULTIMATE_CRON_CATCH_UP),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'catch_up',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Time in seconds to catch up, if a job could not be run within its time frame. (blank = ' . variable_get('ultimate_cron_catch_up', ULTIMATE_CRON_CATCH_UP) . ')'),
|
||||
);
|
||||
$form['general']['ultimate_cron_queue_polling_latency'] = array(
|
||||
'#title' => t("Queue polling latency"),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_queue_polling_latency', ULTIMATE_CRON_QUEUE_POLLING_LATENCY),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'polling_latency',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Queue polling latency in miliseconds. Leave blank to disable continuous processing of queues.'),
|
||||
);
|
||||
$form['general']['ultimate_cron_queue_lease_time'] = array(
|
||||
'#title' => t('Queue lease time'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('ultimate_cron_queue_lease_time', ULTIMATE_CRON_QUEUE_LEASE_TIME),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'queue_lease_time',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Time in seconds to keep lock on claimed item'),
|
||||
);
|
||||
$methods = module_invoke_all('service_group');
|
||||
$options = ultimate_cron_get_service_groups();
|
||||
foreach ($options as $key => &$value) {
|
||||
$value = (empty($value['description']) ? $key : $value['description']) . ' (' . join(',', $value['hosts']) . ') : ' . $methods['methods'][$value['method']];
|
||||
}
|
||||
$form['general']['ultimate_cron_service_group'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Service group'),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'service_group',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Service group to use for all jobs. See Background Process !url for managing service groups.', array('!url' => l(t('settings'), 'admin/config/system/background-process'))),
|
||||
'#options' => $options,
|
||||
'#default_value' => variable_get('ultimate_cron_service_group', ULTIMATE_CRON_SERVICE_GROUP),
|
||||
);
|
||||
$form['general']['ultimate_cron_poorman'] = array(
|
||||
'#title' => t("Poormans cron"),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => variable_get('ultimate_cron_poorman', ULTIMATE_CRON_POORMAN),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'poorman',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Keep background process alive, checking for cron every minute.'),
|
||||
);
|
||||
|
||||
$form = system_settings_form($form);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function settings form.
|
||||
*/
|
||||
function ultimate_cron_function_settings_form($form, &$form_state, $function) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[(string)$function])) {
|
||||
drupal_not_found();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Load settings
|
||||
$hook = $hooks[$function];
|
||||
$conf = ultimate_cron_get_settings($function);
|
||||
$conf += _ultimate_cron_default_settings();
|
||||
|
||||
// Setup form
|
||||
drupal_set_title(check_plain($function));
|
||||
$form = array();
|
||||
$advanced_help_enabled = module_exists('advanced_help');
|
||||
|
||||
// General settings -----------------------------------
|
||||
$form['function'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $function,
|
||||
);
|
||||
$form['general'] = array(
|
||||
'#title' => t('General'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$form['general']['enabled'] = array(
|
||||
'#title' => t('Enabled'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['enabled'],
|
||||
'#description' => t('Enable this cron job.'),
|
||||
);
|
||||
$form['general']['rules'] = array(
|
||||
'#title' => t('Rules'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => implode(';', $conf['rules']),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'rules',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Semi-colon separated list of rules for this job. (blank = ' . implode(';', $hook['settings']['rules']) . ')'),
|
||||
);
|
||||
$form['general']['catch_up'] = array(
|
||||
'#title' => t('Catch up'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $conf['catch_up'],
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'catch_up',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Time in seconds to catch up, if a job could not be run within its time frame. (blank = ' . variable_get('ultimate_cron_catch_up', ULTIMATE_CRON_CATCH_UP) . ')'),
|
||||
);
|
||||
if (strpos($function, 'ultimate_cron_queue_') === 0) {
|
||||
$form['general']['queue_lease_time'] = array(
|
||||
'#title' => t('Queue lease time'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $conf['queue_lease_time'],
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'queue_lease_time',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Time in seconds to keep lock on claimed item. (blank = ' . variable_get('ultimate_cron_queue_lease_time', ULTIMATE_CRON_QUEUE_LEASE_TIME) . ')'),
|
||||
);
|
||||
}
|
||||
|
||||
$methods = module_invoke_all('service_group');
|
||||
$service_groups = $options = ultimate_cron_get_service_groups();
|
||||
foreach ($options as $key => &$value) {
|
||||
$value = (empty($value['description']) ? $key : $value['description']) . ' (' . join(',', $value['hosts']) . ') : ' . $methods['methods'][$value['method']];
|
||||
}
|
||||
$options += array(
|
||||
NULL => 'Ultimate Cron service group (' . join(',', $service_groups[variable_get('ultimate_cron_service_group', ULTIMATE_CRON_SERVICE_GROUP)]['hosts']) . ') : ' . $methods['methods'][$service_groups[variable_get('ultimate_cron_service_group', ULTIMATE_CRON_SERVICE_GROUP)]['method']]
|
||||
);
|
||||
$form['general']['service_group'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Service group'),
|
||||
'#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array(
|
||||
'module' => 'ultimate_cron',
|
||||
'topic' => 'service_group',
|
||||
'type' => 'icon')
|
||||
) : '') . t('Service group to use for this job. See Background Process !url for managing service groups.', array('!url' => l(t('settings'), 'admin/config/system/background-process'))),
|
||||
'#options' => $options,
|
||||
'#default_value' => isset($conf['service_group']) ? $conf['service_group'] : NULL,
|
||||
);
|
||||
|
||||
$form['buttons'] = array(
|
||||
'#weight' => 1000,
|
||||
);
|
||||
$form['buttons']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save settings'),
|
||||
);
|
||||
$form['#redirect'] = 'admin/config/system/cron';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate handler for function settings.
|
||||
*/
|
||||
function ultimate_cron_function_settings_form_validate($form, &$form_state) {
|
||||
$conf =& $form_state['values']['general'];
|
||||
$conf['rules'] = trim($conf['rules']);
|
||||
$conf['rules'] = $conf['rules'] ? explode(';', $conf['rules']) : array();
|
||||
|
||||
if ($conf['rules']) {
|
||||
foreach ($conf['rules'] as &$rule) {
|
||||
$rule = trim($rule);
|
||||
if (!ultimate_cron_validate_rule($rule)) {
|
||||
form_set_error('rules', t('Invalid rule.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
unset($conf['rules']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for function settings.
|
||||
*/
|
||||
function ultimate_cron_function_settings_form_submit($form, &$form_state) {
|
||||
$conf =& $form_state['values']['general'];
|
||||
ultimate_cron_set_settings($form_state['values']['function'], $conf);
|
||||
unset($form_state['storage']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page overviewing cron jobs.
|
||||
*/
|
||||
function ultimate_cron_view_page($status = NULL) {
|
||||
require_once 'CronRule.class.php';
|
||||
drupal_add_css(drupal_get_path('module', 'ultimate_cron') . '/css/ultimate_cron.admin.css');
|
||||
drupal_add_js(drupal_get_path('module', 'ultimate_cron') . '/js/ultimate_cron.js');
|
||||
|
||||
if (module_exists('nodejs')) {
|
||||
drupal_add_js(array(
|
||||
'ultimate_cron' => array(
|
||||
'processes' => new stdClass(),
|
||||
'skew' => 0,
|
||||
'handle_prefix' => variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX),
|
||||
),
|
||||
), 'setting');
|
||||
nodejs_send_content_channel_token('ultimate_cron');
|
||||
nodejs_send_content_channel_token('background_process');
|
||||
nodejs_send_content_channel_token('progress');
|
||||
drupal_add_js(drupal_get_path('module', 'ultimate_cron') . '/js/nodejs.ultimate_cron.js');
|
||||
}
|
||||
|
||||
module_load_install('ultimate_cron');
|
||||
$requirements = ultimate_cron_requirements('runtime');
|
||||
if ($requirements['ultimate_cron']['severity'] != REQUIREMENT_OK) {
|
||||
drupal_set_message($requirements['ultimate_cron']['value'], 'error');
|
||||
drupal_set_message($requirements['ultimate_cron']['description'], 'error');
|
||||
}
|
||||
|
||||
// Get hooks and their data
|
||||
$data = _ultimate_cron_preload_cron_data();
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
|
||||
$modules = array();
|
||||
foreach ($hooks as $function => $hook) {
|
||||
$hook['settings'] = $data[$function]['settings'] + $hook['settings'];
|
||||
$hook['background_process'] = $data[$function]['background_process'];
|
||||
$hook['log'] = ultimate_cron_get_log($function);
|
||||
$modules[$hook['module']][$function] = $hook;
|
||||
}
|
||||
|
||||
$headers = array('', t('Module'), t('Function'), t('Rules'), t('Start'), t('Duration'), t('Status'), array('colspan' => 3, 'data' => ''), l(t('Run all'), 'admin/reports/status/run-cron', array('query' => drupal_get_destination())));
|
||||
$output = '';
|
||||
|
||||
$rows = array();
|
||||
|
||||
$handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
|
||||
|
||||
$overview = array();
|
||||
$overview['running'] = 0;
|
||||
$overview['success'] = 0;
|
||||
$overview['info'] = 0;
|
||||
$overview['warning'] = 0;
|
||||
$overview['error'] = 0;
|
||||
|
||||
|
||||
// Used for JS encodeURIComponent emulation
|
||||
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
|
||||
|
||||
foreach ($modules as $module => $hooks) {
|
||||
foreach ($hooks as $function => $hook) {
|
||||
// Setup settings
|
||||
$conf = $hook['settings'];
|
||||
$rules = $hook['settings']['rules'];
|
||||
$cron = new CronRule();
|
||||
$parsed_rules = array();
|
||||
foreach ($rules as $rule) {
|
||||
$cron->rule = $rule;
|
||||
$cron->offset = $hook['delta'];
|
||||
$parsed_rules[] = $cron->parseRule();
|
||||
}
|
||||
|
||||
// Setup process
|
||||
$process = $hook['background_process'];
|
||||
$service_host = empty($process->service_host) ? t('N/A') : $process->service_host;
|
||||
|
||||
// Setup log
|
||||
$log = $hook['log'];
|
||||
if (!$log) {
|
||||
$log = array(
|
||||
'severity' => -1,
|
||||
'status' => NULL,
|
||||
'start' => NULL,
|
||||
'end' => NULL,
|
||||
);
|
||||
}
|
||||
$severity_type = $log['severity'] < 0 ? 'success' : ($log['severity'] >= WATCHDOG_NOTICE ? 'info' : ($log['severity'] >= WATCHDOG_WARNING ? 'warning' : 'error'));
|
||||
$css_status = !empty($process) ? 'running' : $severity_type;
|
||||
$short_msg = $log['severity'];
|
||||
$msg = !empty($log['msg']) ? $log['msg'] : t('No errors');
|
||||
|
||||
$duration = '';
|
||||
if ($process) {
|
||||
$overview['running']++;
|
||||
$log['previous_start'] = $log['start'];
|
||||
$log['previous_end'] = $log['end'];
|
||||
$log['start'] = $process->start;
|
||||
if ($process->status == BACKGROUND_PROCESS_STATUS_RUNNING) {
|
||||
$log['end'] = microtime(TRUE);
|
||||
}
|
||||
else {
|
||||
$log['end'] = NULL;
|
||||
}
|
||||
$progress = progress_get_progress($handle_prefix . $function);
|
||||
if ($progress && $progress->progress > 0) {
|
||||
$duration .= sprintf(" (%d%%)", $progress->progress * 100);
|
||||
}
|
||||
}
|
||||
|
||||
$overview[$severity_type]++;
|
||||
$link_configure = '';
|
||||
if (!empty($hook['configure'])) {
|
||||
$link_configure = _ultimate_cron_l('Settings', $hook['configure']);
|
||||
}
|
||||
|
||||
$link_unlock = '';
|
||||
if ($process) {
|
||||
$link_unlock = _ultimate_cron_l('Unlock', 'background-process/unlock/' . $process->handle);
|
||||
}
|
||||
|
||||
$link_settings = _ultimate_cron_l('Schedule', 'admin/config/system/cron/settings/' . $function);
|
||||
$link_execute = _ultimate_cron_l('Run', 'admin/ultimate-cron/service/start/' . $function);
|
||||
$link_log = _ultimate_cron_l('Log', 'admin/reports/cron/' . $function);
|
||||
|
||||
$enable = !empty($conf) && empty($conf['enabled']);
|
||||
$link_toggle = _ultimate_cron_l($enable ? 'Enable' : 'Disable', 'admin/ultimate-cron/service/' . ($enable ? 'enable' : 'disable') . '/' . $function);
|
||||
|
||||
$data = array(
|
||||
array('class' => $enable ? 'ultimate-cron-admin-enable' : 'ultimate-cron-admin-disable'),
|
||||
array('class' => 'ultimate-cron-admin-module'),
|
||||
array('class' => 'ultimate-cron-admin-function'),
|
||||
array('class' => 'ultimate-cron-admin-rules'),
|
||||
array('class' => 'ultimate-cron-admin-start'),
|
||||
array('class' => 'ultimate-cron-admin-end'),
|
||||
array('class' => 'ultimate-cron-admin-status ultimate-cron-admin-status-' . $css_status),
|
||||
array('class' => 'ultimate-cron-admin-settings'),
|
||||
array('class' => 'ultimate-cron-admin-configure'),
|
||||
array('class' => 'ultimate-cron-admin-log'),
|
||||
array('class' => $process ? 'ultimate-cron-admin-unlock' : 'ultimate-cron-admin-execute'),
|
||||
);
|
||||
$data[0]['data'] = $link_toggle;
|
||||
$data[0]['title'] = $enable ? t('Enable') : t('Disable');
|
||||
$data[1]['data'] = ultimate_cron_module_name($module);
|
||||
$data[2]['data'] = $hook['description'];
|
||||
$data[2]['title'] = $function;
|
||||
$data[3]['data'] = join("<br/>", $rules);
|
||||
$data[3]['title'] = join("\n", $parsed_rules);
|
||||
$data[4]['data'] = $log['start'] ? format_date((int)$log['start'], 'custom', 'Y-m-d H:i:s') : t('Never');
|
||||
$data[5]['data'] = $log['end'] ? gmdate('H:i:s', (int)($log['end'] - $log['start'])) . $duration : ($process ? t('Starting') : t('N/A'));
|
||||
$finish = !empty($log['previous_end']) ? $log['previous_end'] : $log['end'];
|
||||
$data[5]['title'] = t('Previous run finished @ !timestamp', array(
|
||||
'!timestamp' => $finish ? format_date((int)$finish, 'custom', 'Y-m-d H:i:s') : t('N/A')
|
||||
));
|
||||
if (!empty($log['previous_start'])) {
|
||||
$data[4]['title'] = t('Previous run started @ !timestamp', array(
|
||||
'!timestamp' => format_date((int)$log['previous_start'], 'custom', 'Y-m-d H:i:s'),
|
||||
));
|
||||
$data[5]['title'] .= ' - ' . t('Run time: !duration', array(
|
||||
'!duration' => gmdate('H:i:s', (int)($log['previous_end'] - $log['previous_start'])) . $duration,
|
||||
));
|
||||
}
|
||||
if ($process) {
|
||||
$data[6]['data'] = '<span>' . t('Running') . '</span>';
|
||||
$data[6]['title'] = t('Running on @host', array('@host' => $service_host));
|
||||
}
|
||||
else {
|
||||
$data[6]['data'] = '<span>' . $short_msg . '</span>';
|
||||
$data[6]['title'] = strip_tags(html_entity_decode($msg, ENT_QUOTES));
|
||||
}
|
||||
$data[7]['data'] = $link_settings;
|
||||
$data[7]['title'] = t('Schedule');
|
||||
$data[8]['data'] = $link_configure;
|
||||
$data[8]['title'] = $link_configure ? t('Settings') : '';
|
||||
$data[9]['data'] = $link_log;
|
||||
$data[9]['title'] = t('Log');
|
||||
$data[10]['data'] = ($process ? $link_unlock : $link_execute);
|
||||
$data[10]['title'] = ($process ? t('Unlock') : t('Run'));
|
||||
|
||||
$rows[(int)$enable][] = array(
|
||||
'class' => array('row-' . str_replace('%', '_', strtr(rawurlencode($function), $revert))),
|
||||
'data' => $data,
|
||||
'style' => ($status && $status != 'all' && ($css_status != $status) ? 'display: none' : ''),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($rows[0])) {
|
||||
$output .= theme('table', array(
|
||||
'header' => $headers,
|
||||
'rows' => $rows[0],
|
||||
'attributes' => array('id' => array('ultimate-cron-view'))
|
||||
));
|
||||
$output .= '<div class="clear-block"></div>';
|
||||
}
|
||||
if (!empty($rows[1])) {
|
||||
$headers = array('', t('Module'), t('Function'), t('Rules'), t('Start'), t('Duration'), t('Status'), array('colspan' => 4, 'data' => ''));
|
||||
$output .= theme('table', array(
|
||||
'header' => $headers,
|
||||
'rows' => $rows[1],
|
||||
'attributes' => array('id' => array('ultimate-cron-view'))
|
||||
));
|
||||
$output .= '<div class="clear-block"></div>';
|
||||
}
|
||||
|
||||
if ($overview['running']) {
|
||||
drupal_set_message(format_plural($overview['running'],
|
||||
'@jobs job is currently running',
|
||||
'@jobs jobs are currently running',
|
||||
array('@jobs' => $overview['running'])
|
||||
));
|
||||
}
|
||||
if ($overview['warning']) {
|
||||
drupal_set_message(format_plural($overview['warning'],
|
||||
'@jobs job had warnings during its last run',
|
||||
'@jobs jobs had warnings during their last run',
|
||||
array('@jobs' => $overview['warning'])
|
||||
), 'warning');
|
||||
}
|
||||
if ($overview['error']) {
|
||||
drupal_set_message(format_plural($overview['error'],
|
||||
'@jobs job had errors during its last run',
|
||||
'@jobs jobs had errors during their last run',
|
||||
array('@jobs' => $overview['error'])
|
||||
), 'error');
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function log page.
|
||||
*/
|
||||
function ultimate_cron_function_log_page($function) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[(string)$function])) {
|
||||
drupal_not_found();
|
||||
exit;
|
||||
}
|
||||
|
||||
drupal_add_css(drupal_get_path('module', 'ultimate_cron') . '/css/ultimate_cron.admin.css');
|
||||
|
||||
$header = array(
|
||||
array('data' => t('Start'), 'field' => 'start_stamp', 'sort' => 'DESC'),
|
||||
array('data' => t('End'), 'field' => 'end_stamp'),
|
||||
t('Duration'),
|
||||
t('Service host'),
|
||||
t('Status'),
|
||||
t('Message'),
|
||||
);
|
||||
|
||||
drupal_set_title(check_plain($function));
|
||||
|
||||
$query = db_select('ultimate_cron_log', 'l');
|
||||
$query = $query->condition('l.name', $function)
|
||||
->extend('PagerDefault')
|
||||
->limit(10)
|
||||
->extend('TableSort')
|
||||
->orderByHeader($header)
|
||||
->fields('l', array('lid', 'name', 'start_stamp', 'end_stamp', 'service_host', 'exec_status', 'msg', 'severity'))
|
||||
->orderBy('l.start_stamp', 'DESC');
|
||||
$logs = $query->execute()->fetchAll();
|
||||
|
||||
$handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
|
||||
|
||||
$output = '';
|
||||
$rows = array();
|
||||
if (empty($_GET['page']) && $process = background_process_get_process($handle_prefix . $function)) {
|
||||
$data = array(
|
||||
array('class' => array('ultimate-cron-admin-start')),
|
||||
array('class' => array('ultimate-cron-admin-end')),
|
||||
array('class' => array('ultimate-cron-admin-duration')),
|
||||
array('class' => array('ultimate-cron-admin-service-host')),
|
||||
array('class' => array('ultimate-cron-admin-status ultimate-cron-admin-status-running')),
|
||||
array('class' => array('ultimate-cron-admin-message')),
|
||||
);
|
||||
$duration = time() - $process->start_stamp;
|
||||
$duration = gmdate('H:i:s', (int)$duration);
|
||||
$progress = progress_get_progress($handle_prefix . $function);
|
||||
if ($progress && $progress->progress > 0) {
|
||||
$duration .= sprintf(" (%d%%)", $progress->progress * 100);
|
||||
}
|
||||
$data[0]['data'] = format_date((int)$process->start_stamp, 'custom', 'Y-m-d H:i:s');
|
||||
$data[1]['data'] = t('N/A');
|
||||
$data[2]['data'] = $duration;
|
||||
$data[3]['data'] = $process->service_host ? $process->service_host : t('N/A');
|
||||
$data[4]['data'] = '<span>' . t('running') . '</span>';
|
||||
$data[5]['data'] = '';
|
||||
$rows[] = $data;
|
||||
}
|
||||
|
||||
foreach ($logs as $log) {
|
||||
$log->function = $log->name;
|
||||
$log->status = $log->exec_status;
|
||||
$log->start = $log->start_stamp;
|
||||
$log->end = $log->end_stamp;
|
||||
$severity_type = $log->severity < 0 ? 'success' : ($log->severity >= WATCHDOG_NOTICE ? 'info' : ($log->severity >= WATCHDOG_WARNING ? 'warning' : 'error'));
|
||||
$css_status = $severity_type;
|
||||
$data = array(
|
||||
array('class' => array('ultimate-cron-admin-start')),
|
||||
array('class' => array('ultimate-cron-admin-end')),
|
||||
array('class' => array('ultimate-cron-admin-duration')),
|
||||
array('class' => array('ultimate-cron-admin-service-host')),
|
||||
array('class' => array('ultimate-cron-admin-status ultimate-cron-admin-status-' . $css_status)),
|
||||
array('class' => array('ultimate-cron-admin-message')),
|
||||
);
|
||||
$data[0]['data'] = format_date((int)$log->start, 'custom', 'Y-m-d H:i:s');
|
||||
$data[1]['data'] = format_date((int)$log->end, 'custom', 'Y-m-d H:i:s');
|
||||
$data[2]['data'] = gmdate('H:i:s', (int)($log->end - $log->start));
|
||||
$data[3]['data'] = $log->service_host ? $log->service_host : t('N/A');
|
||||
$data[4]['data'] = '<span>' . $log->status . '</span>';
|
||||
$data[5]['data'] = $log->msg;
|
||||
$rows[] = $data;
|
||||
}
|
||||
|
||||
$output .= theme('table', array(
|
||||
'header' => $header,
|
||||
'rows' => $rows,
|
||||
'attributes' => array('id' => 'ultimate-cron-view')
|
||||
));
|
||||
$output .= theme('pager');
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a single function.
|
||||
*
|
||||
* @param $function
|
||||
* @return string
|
||||
* Output to page
|
||||
*/
|
||||
function ultimate_cron_service_start($function) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[(string)$function])) {
|
||||
drupal_not_found();
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($modules = _ultimate_cron_incompatible_modules()) {
|
||||
drupal_set_message(t('%function could not start (incompatible module installed)', array('%function' => $function)), 'error');
|
||||
drupal_set_message(t('%modules is installed on the system, but is incompatible with Ultimate Cron.<br/>Please disable the conflicting modules.<br/>You might want to !url settings first.', array('%modules' => join(', ', $modules), '!url' => l(t('import'), 'admin/settings/cron/import'))), 'error');
|
||||
drupal_goto();
|
||||
}
|
||||
|
||||
// When run manually don't double check the rules
|
||||
$hooks[$function]['skip_catch_up'] = TRUE;
|
||||
|
||||
ultimate_cron_load_hook_data($hooks[$function]);
|
||||
$handle = ultimate_cron_run_hook($function, $hooks[$function]);
|
||||
|
||||
if ($handle === FALSE) {
|
||||
drupal_set_message(t('%function could not start (already running?)', array('%function' => $function)), 'error');
|
||||
}
|
||||
elseif ($handle === NULL) {
|
||||
drupal_set_message(t('%function could not start (service unavailable)', array('%function' => $function)), 'error');
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('%function started', array('%function' => $function)));
|
||||
}
|
||||
|
||||
drupal_goto();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable cron job
|
||||
* @param type $function
|
||||
* @param type $enabled
|
||||
*/
|
||||
function ultimate_cron_service_enable($function, $enabled) {
|
||||
$conf = ultimate_cron_get_settings($function);
|
||||
$conf['enabled'] = $enabled;
|
||||
ultimate_cron_set_settings($function, $conf);
|
||||
drupal_goto();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message for all running processes.
|
||||
*/
|
||||
function ultimate_cron_service_process_status() {
|
||||
$handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
|
||||
$processes = array();
|
||||
$query = db_select('background_process', 'b')
|
||||
->fields('b')
|
||||
->condition('handle', $handle_prefix . '%', 'LIKE');
|
||||
foreach ($query->execute()->fetchAllAssoc('handle', PDO::FETCH_OBJ) as $process) {
|
||||
$process = BackgroundProcess::load($process);
|
||||
$name = preg_replace('/^' . $handle_prefix . '/', '', $process->handle);
|
||||
$processes[$name] = $process;
|
||||
$process->sendMessage('ultimateCronStatus');
|
||||
}
|
||||
return drupal_json_output(array('processes' => $processes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Import form.
|
||||
*/
|
||||
function ultimate_cron_import_form() {
|
||||
$form = array();
|
||||
$options = array();
|
||||
|
||||
if ($options) {
|
||||
$form['import']['module'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#title' => t('Module'),
|
||||
'#description' => t('Module to import settings from'),
|
||||
);
|
||||
$form['import']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#submit' => array('ultimate_cron_import_form_submit'),
|
||||
'#value' => t('Import'),
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for import.
|
||||
*/
|
||||
function ultimate_cron_import_form_submit($form, &$form_state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for links on cron list
|
||||
* @param $text
|
||||
* Text for link
|
||||
* @param $path
|
||||
* Path to link to
|
||||
* @return type
|
||||
*/
|
||||
function _ultimate_cron_l($text, $path) {
|
||||
return l(
|
||||
'<span>' . t($text) . '</span>',
|
||||
$path,
|
||||
array(
|
||||
'query' => drupal_get_destination(),
|
||||
'html' => TRUE,
|
||||
)
|
||||
);
|
||||
}
|
@@ -0,0 +1,356 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Drush commands for Ultimate Cron!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function ultimate_cron_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$items['cron-list'] = array(
|
||||
'description' => "List cron jobs.",
|
||||
'arguments' => array(
|
||||
'type' => 'The type of jobs to list (all, running, enabled, disabled, unsafe)',
|
||||
),
|
||||
'options' => array(
|
||||
'module' => 'Only show jobs from comma separated list of modules',
|
||||
),
|
||||
'examples' => array(
|
||||
'drush cron-list running',
|
||||
),
|
||||
'aliases' => array('cl'),
|
||||
);
|
||||
|
||||
$items['cron-run'] = array(
|
||||
'description' => "Run cron job.",
|
||||
'arguments' => array(
|
||||
'function' => 'Function to run',
|
||||
),
|
||||
'options' => array(
|
||||
'cli' => "Don't spawn a background process through http",
|
||||
'check-rule' => "Check rule to determine if job should run",
|
||||
'logfile' => "File to log to when spawning cli processes"
|
||||
),
|
||||
'examples' => array(
|
||||
'drush cron-run node_cron',
|
||||
),
|
||||
'aliases' => array('cr'),
|
||||
);
|
||||
|
||||
$items['cron-enable'] = array(
|
||||
'description' => "Enable cron job.",
|
||||
'arguments' => array(
|
||||
'function' => 'Function to enable',
|
||||
),
|
||||
'examples' => array(
|
||||
'drush cron-enable node_cron',
|
||||
),
|
||||
'aliases' => array('ce'),
|
||||
);
|
||||
|
||||
$items['cron-disable'] = array(
|
||||
'description' => "Disable cron job.",
|
||||
'arguments' => array(
|
||||
'function' => 'Function to disable',
|
||||
),
|
||||
'examples' => array(
|
||||
'drush cron-disable node_cron',
|
||||
),
|
||||
'aliases' => array('cd'),
|
||||
);
|
||||
|
||||
$items['cron-unlock'] = array(
|
||||
'description' => "Unlock cron job.",
|
||||
'arguments' => array(
|
||||
'function' => 'Function to unlock',
|
||||
),
|
||||
'examples' => array(
|
||||
'drush cron-unlock node_cron',
|
||||
),
|
||||
'aliases' => array('cu'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_drush_help().
|
||||
*/
|
||||
function ultimate_cron_drush_help($section) {
|
||||
switch ($section) {
|
||||
case 'drush:cron-list':
|
||||
return dt("This command will list cron jobs.");
|
||||
case 'drush:cron-run':
|
||||
return dt("This command will run a cron job.");
|
||||
case 'drush:cron-enable':
|
||||
return dt("This command will enable a cron job.");
|
||||
case 'drush:cron-disable':
|
||||
return dt("This command will disable a cron job.");
|
||||
case 'drush:cron-unlock':
|
||||
return dt("This command will unlock a cron job.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List cron jobs.
|
||||
*/
|
||||
function drush_ultimate_cron_cron_list($type = 'all') {
|
||||
$module = drush_get_option('module');
|
||||
$module = $module ? explode(",", $module) : array();
|
||||
// Get hooks and their data
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
$data = _ultimate_cron_preload_cron_data();
|
||||
$jobs = array();
|
||||
|
||||
$modules = array();
|
||||
foreach ($hooks as $function => $hook) {
|
||||
if (!$module || $module == $hook['module']) {
|
||||
$modules[$hook['module']][$function] = $hook;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($hooks as $function => &$hook) {
|
||||
if ($module && !in_array($hook['module'], $module)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hook['settings'] = $data[$function]['settings'] + $hook['settings'];
|
||||
$hook['background_process'] = $data[$function]['background_process'];
|
||||
$hook['log'] = ultimate_cron_get_log($function);
|
||||
|
||||
switch ($type) {
|
||||
case 'enabled':
|
||||
if (!empty($hook['settings']['enabled'])) {
|
||||
$jobs[] = $hook;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
if (empty($hook['settings']['enabled'])) {
|
||||
$jobs[] = $hook;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'running':
|
||||
if (!empty($data[$hook['function']]['background_process'])) {
|
||||
$jobs[] = $hook;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'unsafe':
|
||||
if (!empty($hook['unsafe'])) {
|
||||
$jobs[] = $hook;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'failed':
|
||||
if (isset($hook['log']['status']) && empty($hook['log']['status'])) {
|
||||
$jobs[] = $hook;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
default:
|
||||
$jobs[] = $hook;
|
||||
}
|
||||
}
|
||||
|
||||
$table = array();
|
||||
$table[] = array('', dt('Module'), dt('Function'), dt('Rules'), dt('Start'), dt('Duration'));
|
||||
foreach ($jobs as $hook) {
|
||||
$legend = '';
|
||||
if (!empty($hook['background_process'])) {
|
||||
$legend .= 'R';
|
||||
$hook['log']['start'] = $hook['background_process']->start;
|
||||
$hook['log']['end'] = microtime(TRUE);
|
||||
}
|
||||
if (empty($hook['settings']['enabled'])) $legend .= 'D';
|
||||
|
||||
$start = isset($hook['log']['start']) ? format_date((int)$hook['log']['start'], 'custom', 'Y-m-d H:i:s') : dt('N/A');
|
||||
$end = isset($hook['log']['end']) ? gmdate('H:i:s', (int)($hook['log']['end'] - $hook['log']['start'])) : dt('N/A');
|
||||
$rules = $hook['settings']['rules'];
|
||||
$table[] = array($legend, $hook['module'], $hook['function'], implode("\n", $rules), $start, $end);
|
||||
}
|
||||
drush_print_table($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run cron job(s)
|
||||
*/
|
||||
function drush_ultimate_cron_cron_run($function = NULL) {
|
||||
$cli = drush_get_option('cli');
|
||||
$check_rule = drush_get_option('check-rule');
|
||||
$logfile = drush_get_option('logfile');
|
||||
$logfile = is_string($logfile) ? $logfile : '/dev/null';
|
||||
|
||||
// Get global options
|
||||
$options = drush_get_context('cli');
|
||||
$cmd_options = '';
|
||||
|
||||
// Determine new parameter string for sub-requests
|
||||
$passthru = array('root', 'php', 'uri', 'simulate');
|
||||
foreach ($options as $key => $option) {
|
||||
if (in_array($key, $passthru)) {
|
||||
$cmd_options .= ' --' . $key . '=' . escapeshellarg($option);
|
||||
}
|
||||
}
|
||||
|
||||
if ($function == 'all') {
|
||||
if ($cli) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
$schedule = ultimate_cron_get_schedule($hooks);
|
||||
foreach ($schedule as $function => $hook) {
|
||||
if (!empty($options['simulate'])) {
|
||||
// Dry-run ...
|
||||
drush_print(dt('[!function]: Simulated launch @ !ts', array('!ts' => date('Y-m-d H:i:s'), '!function' => $function)));
|
||||
continue;
|
||||
}
|
||||
|
||||
drush_print(dt('[!function]: Launching @ !ts', array('!ts' => date('Y-m-d H:i:s'), '!function' => $function)));
|
||||
|
||||
// Launch the sub-request
|
||||
$cmd = $_SERVER['SCRIPT_FILENAME'] . " $cmd_options cron-run $function --cli " . ($check_rule ? '--check-rule' : '');
|
||||
exec("$cmd >> " . escapeshellarg($logfile) . " 2>&1 &");
|
||||
}
|
||||
drush_print(dt('[!ts] Launced !jobs jobs', array('!ts' => date('Y-m-d H:i:s'), '!jobs' => count($schedule))));
|
||||
|
||||
// Update drupals cron timestamp, but don't clear the cache for all variables!
|
||||
if (empty($options['simulate'])) {
|
||||
$name = 'cron_last';
|
||||
$value = time();
|
||||
global $conf;
|
||||
db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
|
||||
$conf[$name] = $value;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (empty($options['simulate'])) {
|
||||
ultimate_cron_cron_run(TRUE);
|
||||
}
|
||||
$messages = drupal_get_messages();
|
||||
if (!empty($messages['status'])) {
|
||||
foreach ($messages['status'] as $message) {
|
||||
drush_print(strip_tags($message));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[$function])) {
|
||||
return drush_set_error(dt('[!function]: not found', array('!function' => $function)));
|
||||
}
|
||||
|
||||
$hook = &$hooks[$function];
|
||||
|
||||
// When run manually don't double check the rules
|
||||
if (drush_get_option('check-rule')) {
|
||||
$hook['log'] = ultimate_cron_get_log($function);
|
||||
if (!ultimate_cron_hook_should_run($hook)) {
|
||||
drush_print(dt("[!function]: not sceduled to run at this time", array('!function' => $function)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$hook['skip_catch_up'] = TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($options['simulate'])) {
|
||||
// Dry-run ...
|
||||
drush_print("[$function]: Simulated run");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($options['simulate'])) {
|
||||
// Dry-run ...
|
||||
drush_print("[$function]: Simulated run");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cli) {
|
||||
$start = microtime(TRUE);
|
||||
$result = ultimate_cron_run_hook_cli($function, $hook);
|
||||
}
|
||||
else {
|
||||
$result = ultimate_cron_run_hook($function, $hook);
|
||||
}
|
||||
|
||||
|
||||
if ($result === FALSE) {
|
||||
return drush_set_error(dt('[!function]: could not start (already running?)', array('!function' => $function)));
|
||||
}
|
||||
|
||||
if ($cli) {
|
||||
$log = ultimate_cron_get_log($function);
|
||||
if ($log['start'] >= $start && !empty($log['msg'])) {
|
||||
drush_print("[$function]: " . $log['msg']);
|
||||
}
|
||||
return $result ? NULL : drush_set_error(dt('[!function]: could not start (service unavailable)', array('!function' => $function)));
|
||||
}
|
||||
|
||||
if ($result === NULL) {
|
||||
return drush_set_error(dt('[!function]: could not start (service unavailable)', array('!function' => $function)));
|
||||
}
|
||||
else {
|
||||
drush_print(dt('!function started', array('!function' => $function)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a cron job
|
||||
*/
|
||||
function drush_ultimate_cron_cron_enable($function) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[$function])) {
|
||||
return drush_set_error(dt('"!function" not found', array('!function' => $function)));
|
||||
}
|
||||
$conf = ultimate_cron_get_settings($function);
|
||||
$conf['enabled'] = TRUE;
|
||||
ultimate_cron_set_settings($function, $conf);
|
||||
drush_print(dt('!function enabled', array('!function' => $function)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a cron job
|
||||
*/
|
||||
function drush_ultimate_cron_cron_disable($function) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[$function])) {
|
||||
return drush_set_error(dt('"!function" not found', array('!function' => $function)));
|
||||
}
|
||||
$conf = ultimate_cron_get_settings($function);
|
||||
$conf['enabled'] = FALSE;
|
||||
ultimate_cron_set_settings($function, $conf);
|
||||
drush_print(dt('!function disabled', array('!function' => $function)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock a cron job
|
||||
*/
|
||||
function drush_ultimate_cron_cron_unlock($function) {
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
if (!isset($hooks[$function])) {
|
||||
return drush_set_error(dt('"!function" not found', array('!function' => $function)));
|
||||
}
|
||||
|
||||
$handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
|
||||
$handle = $handle_prefix . $function;
|
||||
if ($process = background_process_get_process($handle)) {
|
||||
// Unlock the process
|
||||
if (background_process_remove_process($process->handle, $process->start)) {
|
||||
drush_print(dt('Process for !function unlocked (process handle: !handle)', array('!handle' => $handle, '!function' => $function)));
|
||||
module_invoke_all('background_process_shutdown', $process, FALSE, t('Manually unlocked'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_set_error(dt('Process for !function not found (process handle: !handle)', array('!handle' => $handle, '!function' => $function)));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,17 @@
|
||||
name = "Ultimate Cron"
|
||||
description = "Cron"
|
||||
core = 7.x
|
||||
|
||||
dependencies[] = background_process
|
||||
dependencies[] = progress
|
||||
|
||||
files[] = tests/rules.test
|
||||
|
||||
configure = admin/config/system/cron/settings
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-01
|
||||
version = "7.x-1.9"
|
||||
core = "7.x"
|
||||
project = "ultimate_cron"
|
||||
datestamp = "1364843419"
|
||||
|
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Installation file for Ultimate Cron
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function ultimate_cron_schema() {
|
||||
$schema = array();
|
||||
|
||||
$schema['ultimate_cron'] = array(
|
||||
'description' => 'Cron job function list',
|
||||
'export' => array(
|
||||
'key' => 'name',
|
||||
'key name' => 'Function name',
|
||||
'primary key' => 'fid',
|
||||
'identifier' => 'name',
|
||||
'default hook' => 'default_ultimate_cron_function',
|
||||
'save callback' => 'ultimate_cron_crud_save',
|
||||
'api' => array(
|
||||
'owner' => 'ultimate_cron',
|
||||
'api' => 'default_ultimate_cron_functions',
|
||||
'minimum_version' => 1,
|
||||
'current_version' => 1,
|
||||
),
|
||||
),
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
'description' => 'Function ID',
|
||||
'type' => 'serial',
|
||||
'size' => 'normal',
|
||||
'not null' => TRUE,
|
||||
'no export' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'Function name',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'settings' => array(
|
||||
'description' => 'Settings',
|
||||
'type' => 'text',
|
||||
'serialize' => TRUE,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('fid'),
|
||||
'unique keys' => array(
|
||||
'uniq_name' => array('name')
|
||||
),
|
||||
);
|
||||
|
||||
$schema['ultimate_cron_log'] = array(
|
||||
'description' => 'Logs',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => 'Log ID',
|
||||
'type' => 'serial',
|
||||
'size' => 'normal',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'Function name',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'start_stamp' => array(
|
||||
'description' => 'Timstamp of execution start',
|
||||
'type' => 'float',
|
||||
'size' => 'big',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'end_stamp' => array(
|
||||
'description' => 'Timstamp of execution end',
|
||||
'type' => 'float',
|
||||
'size' => 'big',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'service_host' => array(
|
||||
'description' => 'Service host',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'exec_status' => array(
|
||||
'description' => 'Status of the execution',
|
||||
'type' => 'int',
|
||||
'size' => 'normal',
|
||||
'not null' => FALSE,
|
||||
'default' => NULL,
|
||||
),
|
||||
'severity' => array(
|
||||
'description' => 'Log level severity',
|
||||
'type' => 'int',
|
||||
'size' => 'normal',
|
||||
'not null' => TRUE,
|
||||
'default' => -1,
|
||||
),
|
||||
'msg' => array(
|
||||
'description' => 'Message',
|
||||
'type' => 'text',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
'indexes' => array(
|
||||
'idx_last' => array('name', 'start_stamp'),
|
||||
'idx_count' => array('name', 'end_stamp'),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function ultimate_cron_enable() {
|
||||
// Disable built-in poor mans cron
|
||||
variable_set('cron_safe_threshold', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function ultimate_cron_uninstall() {
|
||||
variable_del('ultimate_cron_simultaneous_connections');
|
||||
variable_del('ultimate_cron_rule');
|
||||
variable_del('ultimate_cron_cleanup_log');
|
||||
variable_del('ultimate_cron_catch_up');
|
||||
variable_del('ultimate_cron_queue_polling_latency');
|
||||
variable_del('ultimate_cron_queue_lease_time');
|
||||
variable_del('ultimate_cron_poorman');
|
||||
variable_del('ultimate_cron_launch_window');
|
||||
variable_del('ultimate_cron_max_execution_time');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function ultimate_cron_requirements($phase) {
|
||||
$response = array();
|
||||
switch ($phase) {
|
||||
case 'install':
|
||||
return $response;
|
||||
case 'runtime':
|
||||
$t = get_t();
|
||||
$response['title'] = 'Ultimate Cron';
|
||||
$response['value'] = $t('OK');
|
||||
$response['severity'] = REQUIREMENT_OK;
|
||||
if ($modules = _ultimate_cron_incompatible_modules()) {
|
||||
$response['severity'] = REQUIREMENT_ERROR;
|
||||
$response['value'] = $t('Ultimate Cron is DISABLED!');
|
||||
$response['description'] = $t('%modules is installed on the system, but is incompatible with Ultimate Cron.<br/>Please disable the modules %modules.<br/>You might want to !url settings first.', array('%modules' => join(', ', $modules), '!url' => l(t('import'), 'admin/settings/cron/import')));
|
||||
}
|
||||
if (ini_get('safe_mode')) {
|
||||
$desc = $t('Safe mode enabled. Ultimate Cron is unable to control maximum execution time for cron jobs. This may cause cron jobs to end prematurely.');
|
||||
if ($response['severity'] < REQUIREMENT_WARNING) {
|
||||
$response['severity'] = REQUIREMENT_WARNING;
|
||||
$response['value'] = $t('Safe mode enabled');
|
||||
$response['description'] = $desc;
|
||||
}
|
||||
else {
|
||||
$response['description'] .= '<br/>' . $desc;
|
||||
}
|
||||
}
|
||||
$result = array();
|
||||
$result['ultimate_cron'] = $response;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Major version upgrade of Drupal
|
||||
*/
|
||||
function ultimate_cron_update_7000(&$context) {
|
||||
$context['sandbox']['major_version_upgrade'] = array(
|
||||
7101 => TRUE,
|
||||
7102 => TRUE,
|
||||
7103 => TRUE,
|
||||
7104 => TRUE,
|
||||
7105 => TRUE,
|
||||
7106 => TRUE,
|
||||
7107 => TRUE,
|
||||
7108 => FALSE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move messages to log table.
|
||||
*/
|
||||
function ultimate_cron_update_7101(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7101])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
$schema_version = (int)(db_query("SELECT schema_version FROM {system} WHERE name = 'ultimate_cron'")->fetchField());
|
||||
if ($schema_version >= 7000) {
|
||||
// Old hook_update_N was 7000
|
||||
return;
|
||||
}
|
||||
db_add_field('ultimate_cron_log', 'msg', array(
|
||||
'description' => 'Message',
|
||||
'type' => 'text',
|
||||
'not null' => FALSE,
|
||||
));
|
||||
db_query("UPDATE {ultimate_cron_log} l JOIN {ultimate_cron_log_message} m ON l.lid = m.lid SET l.msg = m.msg");
|
||||
db_drop_table('ultimate_cron_log_message');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert polling latenct from microseconds to miliseconds.
|
||||
*/
|
||||
function ultimate_cron_update_7102(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7102])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
$schema_version = (int)(db_query("SELECT schema_version FROM {system} WHERE name = 'ultimate_cron'")->fetchField());
|
||||
if ($schema_version >= 7001) {
|
||||
// Old hook_update_N was 7001
|
||||
return;
|
||||
}
|
||||
// Convert polling latency from microseconds to miliseconds.
|
||||
$polling_latency = variable_get('ultimate_cron_queue_polling_latency', NULL);
|
||||
if ($polling_latency) {
|
||||
$polling_latency /= 1000;
|
||||
variable_set('ultimate_cron_queue_polling_latency', $polling_latency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge ultimate_cron_function and ultimate_cron_configuration into ultimate_cron
|
||||
*/
|
||||
function ultimate_cron_update_7103(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7103])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
$schema_version = (int)(db_query("SELECT schema_version FROM {system} WHERE name = 'ultimate_cron'")->fetchField());
|
||||
if ($schema_version >= 7002) {
|
||||
// Old hook_update_N was 7002
|
||||
return;
|
||||
}
|
||||
$schema = ultimate_cron_schema();
|
||||
db_create_table('ultimate_cron', $schema['ultimate_cron']);
|
||||
db_query("INSERT INTO {ultimate_cron} SELECT f.fid, f.function, c.configuration AS settings FROM ultimate_cron_function f LEFT JOIN {ultimate_cron_configuration} c ON f.fid = c.fid");
|
||||
db_drop_table('ultimate_cron_function');
|
||||
db_drop_table('ultimate_cron_configuration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch from fid to function name in ultimate_cron_log
|
||||
*/
|
||||
function ultimate_cron_update_7104(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7104])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
$schema_version = (int)(db_query("SELECT schema_version FROM {system} WHERE name = 'ultimate_cron'")->fetchField());
|
||||
if ($schema_version >= 7003) {
|
||||
// Old hook_update_N was 7003
|
||||
return;
|
||||
}
|
||||
db_add_field('ultimate_cron_log', 'function', array(
|
||||
'description' => 'Function name',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'initial' => 'function',
|
||||
));
|
||||
$fids = db_select('ultimate_cron_log', 'u')->fields('u', array('fid'))->distinct()->execute();
|
||||
while ($fid = $fids->fetchObject()) {
|
||||
$function = db_select('ultimate_cron', 'u')->fields('u', array('function'))->condition('fid', $fid->fid, '=')->execute()->fetchObject();
|
||||
db_update('ultimate_cron_log')->fields(array('function' => $function->function))->condition('fid', $fid->fid, '=')->execute();
|
||||
}
|
||||
db_drop_field('ultimate_cron_log', 'fid');
|
||||
db_drop_index('ultimate_cron_log', 'idx_last');
|
||||
db_drop_index('ultimate_cron_log', 'idx_count');
|
||||
db_add_index('ultimate_cron_log', 'idx_last', array('function', 'start'));
|
||||
db_add_index('ultimate_cron_log', 'idx_count', array('function', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing index to database
|
||||
*/
|
||||
function ultimate_cron_update_7105(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7105])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
$items = db_select('ultimate_cron')
|
||||
->fields('ultimate_cron', array('fid', 'function'))
|
||||
->orderBy('fid', 'ASC')
|
||||
->execute()
|
||||
->fetchAllAssoc('fid', PDO::FETCH_ASSOC);
|
||||
$fids = array();
|
||||
$keep = array();
|
||||
foreach ($items as $item) {
|
||||
if (isset($keep[$item['function']])) {
|
||||
$fids[] = $keep[$item['function']];
|
||||
}
|
||||
$keep[$item['function']] = $item['fid'];
|
||||
}
|
||||
if ($fids) {
|
||||
db_delete('ultimate_cron')
|
||||
->condition('fid', $fids)
|
||||
->execute();
|
||||
}
|
||||
db_add_unique_key('ultimate_cron', 'uniq_function', array('function'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change schema to SQL 99 compliance
|
||||
*/
|
||||
function ultimate_cron_update_7106(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7106])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
db_drop_unique_key('ultimate_cron', 'idx_function');
|
||||
db_change_field('ultimate_cron', 'function', 'name', array(
|
||||
'description' => 'Function name',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
db_add_unique_key('ultimate_cron', 'idx_name', array('name'));
|
||||
|
||||
db_change_field('ultimate_cron_log', 'function', 'name', array(
|
||||
'description' => 'Function name',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
db_change_field('ultimate_cron_log', 'start', 'start_stamp', array(
|
||||
'description' => 'Timstamp of execution start',
|
||||
'type' => 'float',
|
||||
'size' => 'big',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
));
|
||||
db_change_field('ultimate_cron_log', 'end', 'end_stamp', array(
|
||||
'description' => 'Timstamp of execution end',
|
||||
'type' => 'float',
|
||||
'size' => 'big',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
));
|
||||
db_change_field('ultimate_cron_log', 'status', 'exec_status', array(
|
||||
'description' => 'Status of the execution',
|
||||
'type' => 'int',
|
||||
'size' => 'normal',
|
||||
'not null' => FALSE,
|
||||
'default' => NULL,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add service host to log.
|
||||
*/
|
||||
function ultimate_cron_update_7107(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7107])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
db_add_field('ultimate_cron_log', 'service_host', array(
|
||||
'description' => 'Service host',
|
||||
'type' => 'varchar',
|
||||
'length' => 127,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add severity level to log.
|
||||
*/
|
||||
function ultimate_cron_update_7108(&$context) {
|
||||
if (!empty($context['sandbox']['major_version_upgrade'][7108])) {
|
||||
// This udate is already part of latest 6.x
|
||||
return;
|
||||
}
|
||||
db_add_field('ultimate_cron_log', 'severity', array(
|
||||
'description' => 'Log level severity',
|
||||
'type' => 'int',
|
||||
'size' => 'normal',
|
||||
'not null' => TRUE,
|
||||
'default' => -1,
|
||||
));
|
||||
}
|
1404
sites/all/modules/contrib/dev/ultimate_cron/ultimate_cron.module
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
/**
|
||||
* Implements hook_nagios_info().
|
||||
*/
|
||||
function ultimate_cron_nagios_info() {
|
||||
return array(
|
||||
'name' => t('Ultimate Cron Monitoring'),
|
||||
'id' => 'ULTIMATE_CRON',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_nagios().
|
||||
*/
|
||||
function ultimate_cron_nagios($check = 'nagios') {
|
||||
$status = array();
|
||||
foreach(ultimate_cron_nagios_functions() as $function => $description) {
|
||||
if (variable_get('ultimate_cron_nagios_func_' . $function, TRUE) && ($check == 'nagios' || $check == $function)) {
|
||||
$func = $function . '_check';
|
||||
$result = $func();
|
||||
$status[$result['key']] = $result['data'];
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_nagios_settings().
|
||||
*/
|
||||
function ultimate_cron_nagios_settings() {
|
||||
$form = array();
|
||||
|
||||
foreach(ultimate_cron_nagios_functions() as $function => $description) {
|
||||
$var = 'ultimate_cron_nagios_func_' . $function;
|
||||
$form[$var] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $function,
|
||||
'#default_value' => variable_get($var, TRUE),
|
||||
'#description' => $description,
|
||||
);
|
||||
}
|
||||
|
||||
$group = 'thresholds';
|
||||
$form[$group] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
'#title' => t('Thresholds'),
|
||||
'#description' => t('Thresholds for reporting critical alerts to Nagios.'),
|
||||
);
|
||||
|
||||
$form[$group]['ultimate_cron_nagios_running_threshold'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Running jobs count'),
|
||||
'#default_value' => variable_get('ultimate_cron_nagios_running_threshold', 50),
|
||||
'#description' => t('Issue a critical alert when more than this number of jobs are running. Default is 50.'),
|
||||
);
|
||||
|
||||
$form[$group]['ultimate_cron_nagios_failed_threshold'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Failed jobs count'),
|
||||
'#default_value' => variable_get('ultimate_cron_nagios_failed_threshold', 10),
|
||||
'#description' => t('Issue a critical alert when more than this number of jobs failed their last run. Default is 10.'),
|
||||
);
|
||||
|
||||
$form[$group]['ultimate_cron_nagios_longrunning_threshold'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Long running jobs'),
|
||||
'#default_value' => variable_get('ultimate_cron_nagios_longrunning_threshold', 0),
|
||||
'#description' => t('Issue a critical alert when more than this number of jobs are running longer than usual. Default is 0.')
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_nagios_checks().
|
||||
*/
|
||||
function ultimate_cron_nagios_checks() {
|
||||
return ultimate_cron_nagios_functions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of drush hook_nagios_check().
|
||||
*/
|
||||
function ultimate_cron_nagios_check($function) {
|
||||
// We don't bother to check if the function has been enabled by the user.
|
||||
// Since this runs via drush, web security is not an issue.
|
||||
$func = $function . '_check';
|
||||
$result = $func();
|
||||
$status[$result['key']] = $result['data'];
|
||||
return $status;
|
||||
}
|
||||
|
||||
/************** HELPER FUNCTIONS ***********************************/
|
||||
/**
|
||||
* Return a list of nagios check functions
|
||||
* @see ultimate_cron_nagios()
|
||||
*/
|
||||
function ultimate_cron_nagios_functions() {
|
||||
return array(
|
||||
'ultimate_cron_running' => t('Check number of currently running jobs'),
|
||||
'ultimate_cron_failed' => t('Check the number of jobs that failed last run'),
|
||||
|
||||
'ultimate_cron_longrunning' => t('Check the number of jobs that are running longer than usual'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about running jobs - currently running or failed.
|
||||
*
|
||||
* @staticvar array $overview
|
||||
* @param string $mode Which mode to get info about; 'running' or 'errors'
|
||||
* @return int
|
||||
*/
|
||||
function ultimate_cron_nagios_get_job_info($mode = 'running') {
|
||||
// Ensure valid mode
|
||||
if (!in_array($mode, array('running', 'errors'))) {
|
||||
$mode = 'running';
|
||||
}
|
||||
static $overview = array();
|
||||
|
||||
if (!isset($overview[$mode])) {
|
||||
$overview[$mode] = 0;
|
||||
// Get hooks and their data
|
||||
$data = _ultimate_cron_preload_cron_data();
|
||||
$hooks = ultimate_cron_get_hooks();
|
||||
|
||||
$modules = array();
|
||||
foreach ($hooks as $function => $hook) {
|
||||
if (!$module || $module == $hook['module']) {
|
||||
$hook['settings'] = $data[$function]['settings'] + $hook['settings'];
|
||||
$hook['background_process'] = $data[$function]['background_process'];
|
||||
$hook['log'] = ultimate_cron_get_log($function);
|
||||
|
||||
// Setup process
|
||||
if ($hook['background_process']) {
|
||||
$overview['running']++;
|
||||
}
|
||||
$log = $hook['log'];
|
||||
if (isset($log['status']) && !$log['status']) {
|
||||
$overview['errors']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $overview[$mode];
|
||||
}
|
||||
|
||||
/*************** NAGIOS CHECK FUNCTIONS ********************************/
|
||||
/**
|
||||
* Check number of running jobs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function ultimate_cron_running_check() {
|
||||
$running = ultimate_cron_nagios_get_job_info('running');
|
||||
$threshold = variable_get('ultimate_cron_nagios_running_threshold', 50);
|
||||
if (count($running) > $threshold) {
|
||||
$data = array(
|
||||
'status' => NAGIOS_STATUS_CRITICAL,
|
||||
'type' => 'state',
|
||||
'text' => t('@jobs currently running - it is more than @threshold', array('@jobs' => $running, '@threshold' => $threshold)),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'status' => NAGIOS_STATUS_OK,
|
||||
'type' => 'state',
|
||||
'text' => t('@jobs currently running', array('@jobs' => $running)),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'key' => 'ULTIMATE_CRON_RUNNING',
|
||||
'data' => $data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check number of jobs that failed last run.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function ultimate_cron_failed_check() {
|
||||
$failed = ultimate_cron_nagios_get_job_info('errors');
|
||||
$threshold = variable_get('ultimate_cron_nagios_failed_threshold', 10);
|
||||
if (count($failed) > $threshold) {
|
||||
$data = array(
|
||||
'status' => NAGIOS_STATUS_CRITICAL,
|
||||
'type' => 'state',
|
||||
'text' => t('@jobs failed their last run - it is more than @threshold', array('@jobs' => $failed, '@threshold' => $threshold)),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'status' => NAGIOS_STATUS_OK,
|
||||
'type' => 'state',
|
||||
'text' => t('@jobs failed their last run', array('@jobs' => $failed)),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'key' => 'ULTIMATE_CRON_FAILED',
|
||||
'data' => $data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check number of jobs running longer than usual.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @todo Implement the logic
|
||||
*/
|
||||
function ultimate_cron_longrunning_check() {
|
||||
$longrunning = 0;
|
||||
|
||||
// Get running jobs
|
||||
|
||||
// Find out how long they have been running
|
||||
|
||||
// Calculate average run time per job (over a threshold? E.g. queues run very fast if there is nothing to process)
|
||||
|
||||
// If
|
||||
|
||||
$threshold = variable_get('ultimate_cron_nagios_longrunning_threshold', 0);
|
||||
if ($longrunning > $threshold) {
|
||||
$data = array(
|
||||
'status' => NAGIOS_STATUS_CRITICAL,
|
||||
'type' => 'state',
|
||||
'text' => t('@jobs jobs are running longer than usual - it is more than @threshold', array('@jobs' => $longrunning, '@threshold' => $threshold)),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'status' => NAGIOS_STATUS_OK,
|
||||
'type' => 'state',
|
||||
'text' => t('@jobs jobs are running longer than usual', array('@jobs' => $longrunning)),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'key' => 'ULTIMATE_CRON_LONGRUNNING',
|
||||
'data' => $data,
|
||||
);
|
||||
}
|