From 34af2a3a8e1f7b9fa6a9797f6d501bc3f2c1fd84 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 19 May 2001 13:41:52 +0000 Subject: CHANGES: - Rewrote the cron system. Removed cron.module and moved all cron related options to settings.module. Cron was a confusing thing: it has been made simpler both in terms of code and configuration. + You had to rehash your modules to make the cron show up in the list. This is no longer required. + You couldn't tell what cron "watchdog" or cron "story" were up to. Instead, we now display a clear description message for every cron involved. + The user interface of setting.module - and the admin section in general, looks a bit ackward but I couldn't care less and don't want to see this improve at the time being. - Improved setting.module: + Now uses variable_set(). + Added some help and documentaition on how to setup cron. - Improved ./export. - Updated CHANGELOG. TODO: - I'm now going to look into UnConeD's question with regard to check_output() and $theme->node(), as well as the filter and macro stuff. I'll probably be fine-tuning setting.module a bit more on my way. --- modules/cron.module | 65 ---------------------------------------- modules/cvs.module | 22 +++++++++----- modules/headline.module | 42 ++++++++++++++++---------- modules/rating.module | 28 +++++++++++------ modules/settings.module | 38 +++++++++++++++-------- modules/watchdog.module | 10 +++++-- modules/watchdog/watchdog.module | 10 +++++-- 7 files changed, 102 insertions(+), 113 deletions(-) delete mode 100644 modules/cron.module (limited to 'modules') diff --git a/modules/cron.module b/modules/cron.module deleted file mode 100644 index 97b59a10e..000000000 --- a/modules/cron.module +++ /dev/null @@ -1,65 +0,0 @@ - -

Cron (which stands for chronograph) is a periodic command scheduler: it executes commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period of n seconds). Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution.

-

Note that cron does not guarantee the commands will be executed at the specified interval. However, the engine will make sure that the commands are run as close to the specified intervals as possible.

-

Check the documentation page for more information about cron and how to setup it correctly.

- $value) { - db_query("UPDATE crons SET scheduled = '$value' WHERE module = '$key'"); - } -} - -function cron_execute($name) { - watchdog("message", "cron: executed '". $name ."_cron()'"); - module_invoke($name, "cron"); - db_query("UPDATE crons SET timestamp = ". time() ." WHERE module = '$name'"); -} - -function cron_display() { - $intervals = array(300, 900, 1800, 3600, 7200, 10800, 21600, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200); - - // Perform query: - $result = db_query("SELECT * FROM crons"); - - // Generate output: - $output .= "
\n"; - $output .= "\n"; - $output .= " \n"; - while ($cron = db_fetch_object($result)) { - foreach ($intervals as $value) $period .= "\n"; - $output .= " \n"; - unset($period); - } - $output .= "
moduleperiodlast runnext runoperations
". check_output($cron->module) ."". ($cron->timestamp ? format_interval(time() - $cron->timestamp) ." ago" : "never") ."". ($cron->timestamp ? format_interval($cron->timestamp + $cron->scheduled - time()) ." left" : "never") ."module\">execute
\n"; - $output .= "\n"; - $output .= "
\n"; - print $output; -} - -function cron_admin() { - global $op, $edit, $name; - - print "overview | help
\n"; - - switch($op) { - case "help": - cron_help(); - break; - case "execute": - cron_execute($name); - cron_display(); - break; - case "Save crons": - cron_save($edit); - // fall through - default: - cron_display(); - } -} - -?> diff --git a/modules/cvs.module b/modules/cvs.module index 8aaf65b08..f31dd2d26 100644 --- a/modules/cvs.module +++ b/modules/cvs.module @@ -1,19 +1,27 @@ variable_get("cvs_cron_time", time())) { - while ($cvs = db_fetch_object($result)) { - $body .= "File: $cvs->files\nDate: ". format_date($cvs->timestamp) ."\nUser: $cvs->user\n\n$cvs->message\n----------------------------------------------------------------------\n"; - } + print "cvs cron ran"; - $result = db_query("UPDATE cvs SET status = '1'"); + variable_set("cvs_cron_last", time()); - if ($body) mail(variable_get(cvs_mail, "root@localhost"), "CVS log messages", $body, "From: no-reply"); + $result = db_query("SELECT * FROM cvs WHERE status = '0' ORDER BY timestamp DESC LIMIT 50"); + while ($cvs = db_fetch_object($result)) { + $body .= "File: $cvs->files\nDate: ". format_date($cvs->timestamp) ."\nUser: $cvs->user\n\n$cvs->message\n----------------------------------------------------------------------\n"; + } + $result = db_query("UPDATE cvs SET status = '1'"); + + if ($body) mail(variable_get(cvs_mail, "root@localhost"), "CVS log messages", $body, "From: no-reply"); + } } function cvs_conf() { - return form_textfield(t("CVS digest recepient"), "cvs_mail", variable_get(cvs_mail, "root@localhost"), 30, 55, t("The e-mail address to mail the CVS log messages to. Multiple recipients can be specified by putting a comma between each address.")); + $period = array(43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600)); + $output .= form_textfield(t("Digest recepients"), "cvs_mail", variable_get("cvs_mail", "root@localhost"), 30, 55, t("The e-mail address to mail the CVS log messages to. Multiple recipients can be specified by putting a comma between each address.")); + $output .= form_select(t("Digest interval"), "cvs_cron_time" , variable_get("cvs_cron_time", 86400), $period, t("The time interval at which batched CVS digests are dispatched. Requires crontab.")); + return $output; } function cvs_page() { diff --git a/modules/headline.module b/modules/headline.module index 8402e504a..cfb347086 100644 --- a/modules/headline.module +++ b/modules/headline.module @@ -2,6 +2,33 @@ include_once "modules/backend.class"; +function headline_help() { + ?> +

Drupal's headline module both imports and exports RDF/RSS headlines.

+

A lot of news-oriented websites are now publishing news (headlines) and making their content available through XML, RSS and RDF backend files. They syndicate free content and allow retrieval and further transmission, aggregation, and online publication. In its current state, drupal's headline module supports RDF and RSS backends.

+

RSS was originally developed by Netscape to allow adding news channels to "My Netscape" sites, but it has since become adopted as the de facto net standard for distributing headlines and brief dynamic texts.

+

The headline module goes out to a list of configured news sites once an hour or so (driven by cron), downloads new RSS/RDF data and makes it available to your visitors. In addition, your headlines are exported as well and can be retrieved by other sites from export/headlines.rdf.

+ format_interval(900), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 64800 => format_interval(64800), 86400 => format_interval(86400)); + $output .= form_select(t("Update interval"), "headline_cron_time" , variable_get("headline_cron_time", 86400), $period, t("The update interval indicating how often you want to update your headline channels. Requires crontab.")); + return $output; +} + + +function headline_cron() { + if (time() - variable_get("headline_cron_last", 0) > variable_get("headline_cron_time", time())) { + variable_set("headline_cron_last", time()); + + $result = db_query("SELECT * FROM channel"); + while ($channel = db_fetch_object($result)) { + $backend = new Backend($channel->id); + } + } +} + function headline_blocks() { global $theme; @@ -52,21 +79,6 @@ function headline_page() { } } -function headline_cron() { - $result = db_query("SELECT * FROM channel"); - while ($channel = db_fetch_object($result)) { - $backend = new Backend($channel->id); - } -} - -function headline_help() { - ?> -

Drupal's headline module both imports and exports RDF/RSS headlines.

-

A lot of news-oriented websites are now publishing news (headlines) and making their content available through XML, RSS and RDF backend files. They syndicate free content and allow retrieval and further transmission, aggregation, and online publication. In its current state, drupal's headline module supports RDF and RSS backends.

-

RSS was originally developed by Netscape to allow adding news channels to "My Netscape" sites, but it has since become adopted as the de facto net standard for distributing headlines and brief dynamic texts.

-

The headline module goes out to a list of configured news sites once an hour or so (driven by cron), downloads new RSS/RDF data and makes it available to your visitors. In addition, your headlines are exported as well and can be retrieved by other sites from export/headlines.rdf.

- format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600)); + $output .= form_select(t("Update interval"), "rating_cron_time" , variable_get("rating_cron_time", 86400), $period, t("The update interval for the user ratings. Requires crontab.")); + return $output; +} + function rating_cron() { - $r1 = db_query("SELECT id FROM users ORDER BY rating DESC"); - while ($account = db_fetch_object($r1)) { - db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'"); - $rating[$account->id] = ++$i; - } + if (time() - variable_get("rating_cron_last", 0) > variable_get("rating_cron_time", time())) { + variable_set("rating_cron_last", time()); + + $r1 = db_query("SELECT id FROM users ORDER BY rating DESC"); + while ($account = db_fetch_object($r1)) { + db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'"); + $rating[$account->id] = ++$i; + } - db_query("DELETE FROM rating"); + db_query("DELETE FROM rating"); - $r2 = db_query("SELECT id FROM users ORDER BY rating DESC"); - while ($account = db_fetch_object($r2)) { - db_query("INSERT INTO rating (user, new, old) VALUES ('$account->id', '". ++$j ."', '". $rating[$account->id] ."')"); + $r2 = db_query("SELECT id FROM users ORDER BY rating DESC"); + while ($account = db_fetch_object($r2)) { + db_query("INSERT INTO rating (user, new, old) VALUES ('$account->id', '". ++$j ."', '". $rating[$account->id] ."')"); + } } } diff --git a/modules/settings.module b/modules/settings.module index 2edda844a..736ddbee2 100644 --- a/modules/settings.module +++ b/modules/settings.module @@ -1,5 +1,17 @@ +

Drupal comes with system-wide defaults but the setting-module provides control over many Drupal preferences, behaviors including visual and operational settings.

+

Cron

+

Some settings require a cron or crontab. Cron (which stands for chronograph) is a periodic command scheduler: it executes commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period of n seconds). Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution.

+

Whenever cron.php is accessed, cron will run: it checks for the jobs cron controls, and their periods in seconds. If a certain task wasn't executed in the last n seconds, where n is the period of that job, it will be executed. When all the executed commands terminate, cron is done.

+

The recommended way to setup your cron system is to setup a Unix/Linux crontab that frequently visits cron.php. Note that cron does not guarantee the commands will be executed at the specified interval. However, Drupal will try his best and run the crons as close to the specified intervals as possible. The more you visit cron.php, the more accurate cron will be.

+

If your hosting company does not allow you to setup crontabs, you can always ask someone else to setup a crontab for you. After all, virtually any Unix/Linux machine with access to the internet can setup a crontab to frequently visit cron.php.

+

For the Unix/Linux crontab itself, use a browser like lynx or wget but make sure the process terminates: either use /usr/bin/lynx -source cron.php or /usr/bin/wget -O /dev/null cron.php. Take a look at the example scripts in the scripts-directory and make sure to adjust them to your needs. A good crontab-line to run the cron-script once every hour would be: 00 * * * * /home/www/drupal/scripts/cron-lynx.

+ Development settings\n"; - $output .= form_select(t("Display timings"), "dev_timing", variable_get(dev_timing, 0), array("Disabled", "Enabled"), t("Display the time it took to generate a page: for drupal development only.")); + $output .= form_select(t("Display timings"), "dev_timing", variable_get(dev_timing, 0), array("Disabled", "Enabled"), t("Display the time it took to generate a page: for Drupal development only.")); return $output; } @@ -57,17 +69,9 @@ function setting_modules() { return $output; } -function settings_save($edit) { - global $conf; - - // save all variables: - if ($edit) { - db_query("DELETE FROM variable"); - foreach ($edit as $name=>$value) db_query("INSERT INTO variable (name, value) VALUES ('". check_input($name) ."', '". check_input($value) ."')"); - } - - // update context: - $conf = variable_init(); +function settings_save($edit = array()) { + // save variables: + foreach ($edit as $name=>$value) variable_set($name, $value); return "all settings have been saved."; } @@ -90,15 +94,23 @@ function settings_overview() { function settings_admin() { global $edit, $op; + print "overview | help
\n"; + switch ($op) { + case "help": + settings_help(); + break; case "Reset to defaults": print status(settings_default($edit)); + print settings_overview(); break; case "Save settings": print status(settings_save($edit)); + print settings_overview(); break; + default: + print settings_overview(); } - print settings_overview(); } ?> \ No newline at end of file diff --git a/modules/watchdog.module b/modules/watchdog.module index a3d04b36d..8397da666 100644 --- a/modules/watchdog.module +++ b/modules/watchdog.module @@ -3,12 +3,18 @@ function watchdog_help() { ?>

The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time. The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.

-

To ease administration, the watchdog will automatically remove old logs.

+

To ease administration, the watchdog will automatically discard old log entries.

format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200)); + $output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("The time watchdog entries should be kept. Older entries will be automatically discarded. Requires crontab.")); + return $output; +} + function watchdog_cron() { - db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get(watchdog_clear, "302400")); + db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800)); } function watchdog_overview() { diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module index a3d04b36d..8397da666 100644 --- a/modules/watchdog/watchdog.module +++ b/modules/watchdog/watchdog.module @@ -3,12 +3,18 @@ function watchdog_help() { ?>

The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time. The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.

-

To ease administration, the watchdog will automatically remove old logs.

+

To ease administration, the watchdog will automatically discard old log entries.

format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200)); + $output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("The time watchdog entries should be kept. Older entries will be automatically discarded. Requires crontab.")); + return $output; +} + function watchdog_cron() { - db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get(watchdog_clear, "302400")); + db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800)); } function watchdog_overview() { -- cgit v1.2.3