[Xfce4-commits] <xfce4-weather-plugin:master> Fix high download retry frequency.
Harald Judt
noreply at xfce.org
Sun Dec 9 23:44:31 CET 2012
Updating branch refs/heads/master
to d3c97d0e4de01fc13c451346b5a3d5ba4f74f1b7 (commit)
from 89a12b770faf16c3dbb0ffa2522c2bde60b3d7c6 (commit)
commit d3c97d0e4de01fc13c451346b5a3d5ba4f74f1b7
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Dec 9 19:25:03 2012 +0100
Fix high download retry frequency.
If download fails, retries will happen too often, four times a minute.
That is absolutely wrong. The update code clearly needs to be rewritten,
but let's fix that error first, set the retry interval to 3 minutes
and fix this properly later.
panel-plugin/weather-parsers.c | 8 ++++----
panel-plugin/weather-parsers.h | 4 ++--
panel-plugin/weather.c | 30 ++++++++++++++++++++++++++++--
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 03b055b..89b09d5 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -291,7 +291,7 @@ parse_time(xmlNode *cur_node,
/*
* Parse XML weather data and merge it with current data.
*/
-void
+gboolean
parse_weather(xmlNode *cur_node,
xml_weather *wd)
{
@@ -299,10 +299,10 @@ parse_weather(xmlNode *cur_node,
g_assert(wd != NULL);
if (G_UNLIKELY(wd == NULL))
- return;
+ return FALSE;
if (G_UNLIKELY(cur_node == NULL || !NODE_IS_TYPE(cur_node, "weatherdata")))
- return;
+ return FALSE;
for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next) {
if (cur_node->type != XML_ELEMENT_NODE)
@@ -321,7 +321,7 @@ parse_weather(xmlNode *cur_node,
parse_time(child_node, wd);
}
}
- return;
+ return TRUE;
}
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index 4a54701..53b23d8 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -128,8 +128,8 @@ xml_time *make_timeslice(void);
time_t parse_timestring(const gchar *ts,
gchar *format);
-void parse_weather(xmlNode *cur_node,
- xml_weather *wd);
+gboolean parse_weather(xmlNode *cur_node,
+ xml_weather *wd);
xml_astro *parse_astro(xmlNode *cur_node);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index a229858..bd829ee 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -43,6 +43,7 @@
#define CACHE_FILE_MAX_AGE (48 * 3600)
#define BORDER (8)
#define CONNECTION_TIMEOUT (10) /* connection timeout in seconds */
+#define DATA_RETRY_WAIT (180) /* download retry wait time in seconds */
#define DATA_AND_UNIT(var, item) \
value = get_data(conditions, data->units, item, data->round); \
@@ -314,6 +315,20 @@ update_current_conditions(plugin_data *data)
}
+static time_t
+calc_conn_retry_time(gint regular_interval) {
+ time_t now_t = time(NULL);
+ struct tm now_tm;
+
+ now_tm = *localtime(&now_t);
+ now_t = time_calc(now_tm, 0, 0, 0, 0, 0,
+ 0 - regular_interval + DATA_RETRY_WAIT);
+ weather_debug("Calculated time to delay next retry to %d seconds, is %d.",
+ DATA_RETRY_WAIT, now_t);
+ return now_t;
+}
+
+
static void
cb_astro_update(SoupSession *session,
SoupMessage *msg,
@@ -328,6 +343,10 @@ cb_astro_update(SoupSession *session,
xml_astro_free(data->astrodata);
data->astrodata = astro;
data->last_astro_update = time(NULL);
+ } else {
+ /* download or parsing failed, set last_astro_update so that
+ downloading will be retried after DATA_RETRY_WAIT time */
+ data->last_astro_update = calc_conn_retry_time(DATA_MAX_AGE);
}
weather_dump(weather_dump_astrodata, data->astrodata);
}
@@ -347,11 +366,18 @@ cb_weather_update(SoupSession *session,
if (G_LIKELY(doc)) {
root_node = xmlDocGetRootElement(doc);
if (G_LIKELY(root_node)) {
- parse_weather(root_node, data->weatherdata);
- data->last_data_update = time(NULL);
+ if (parse_weather(root_node, data->weatherdata))
+ data->last_data_update = time(NULL);
+ else
+ data->last_data_update = calc_conn_retry_time(DATA_MAX_AGE);
}
xmlFreeDoc(doc);
+ } else {
+ /* download or parsing failed, set last_data_update so that
+ downloading will be retried after DATA_RETRY_WAIT time */
+ data->last_data_update = calc_conn_retry_time(DATA_MAX_AGE);
}
+
xml_weather_clean(data->weatherdata);
weather_debug("Updating current conditions.");
update_current_conditions(data);
More information about the Xfce4-commits
mailing list