Database Reference
In-Depth Information
the binding prefix
local
. If you wish to change this, you can use the special parame‐
ter
bindingPrefix
in the configuration of the XQuery scheduled job.
Scheduled weather retrieval (XQuery)
Supplied alongside this chapter is an XQuery file called
weather.xq
, in the
chapters/
advanced-topics
folder of the
book-code
Git repository (see
“Getting the Source Code”
on page 15
). This XQuery has been designed as a simple example of what you can
achieve with a scheduled XQuery job. The XQuery simply connects to a public web
service and downloads the current weather for a particular city, parses the results,
and stores them into the database. By scheduling this XQuery, you can build up a
dataset of weather over time, which you can then later query to understand how the
weather changed.
To use the example, you must store the query into the database (for example, at
/db/
weather.xq
), set it as executable by the
guest
user, create a collection for storing
weather data, and make that writable by the
guest
user. You then need to add the
scheduled job configuration shown in
Example 16-7
to
$EXIST_HOME/conf.xml
and
restart eXist.
Example 16-7. Scheduled configuration for the weather example
<job
type=
"user"
xquery=
"/db/weather.xq"
name=
"hourly-weather"
cron-trigger=
"0 0 0/1 * * ?"
>
<parameter
name=
"city"
value=
"Exeter"
/>
<parameter
name=
"country"
value=
"United Kingdom"
/>
<parameter
name=
"weather-collection"
value=
"/db/weather"
/>
</job>
This scheduler configuration will cause the XQuery
/db/weather.xq
to be executed
every hour.
Alternatively, you could schedule it using the
scheduler:schedule-xquery-cron-
job
XQuery extension function, as shown in
Example 16-8
.
Example 16-8. Immediate scheduling for the weather example
scheduler:schedule-xquery-cron-job
(
"/db/weather.xq"
,
"0 0 0/1 * * ?"
,
"hourly-weather"
,
<parameters>
<param
name
=
"
city
"
value
=
"
Exeter
"
/>
<param
name
=
"
country
"
value
=
"
United Kingdom
"
/>
<param
name
=
"
weather-collection
"
value
=
"
/db/weather
"
/>
</parameters>
)
Search WWH ::
Custom Search