Skip to content

Commit

Permalink
Merge pull request #252 from jread-usgs/wait
Browse files Browse the repository at this point in the history
Wait
  • Loading branch information
Jordan S Read committed Feb 11, 2016
2 parents 258b38d + 6c1aefe commit 01f8668
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 81 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: geoknife
Type: Package
Title: Web-Processing of Large Gridded Datasets
Version: 1.1.6
Date: 2016-01-15
Version: 1.2.1
Date: 2016-02-11
Authors@R: c( person("Jordan", "Read", role = c("aut","cre"),
email = "jread@usgs.gov"),
person("Jordan", "Walker", role = c("aut"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -43,6 +43,7 @@ export(values)
export(variables)
export(variables_query)
export(version)
export(wait)
export(webdata)
export(webgeom)
export(webprocess)
Expand Down Expand Up @@ -94,5 +95,6 @@ importFrom(sp,Polygons)
importFrom(sp,SpatialPolygons)
importFrom(sp,coordinates)
importFrom(utils,lsf.str)
importFrom(utils,packageName)
importFrom(utils,packageVersion)
importFrom(utils,read.table)
2 changes: 1 addition & 1 deletion R/01-webdata-obj.R
Expand Up @@ -8,7 +8,7 @@ pkg.env$gconfig <- list('wps.url'='http://cida.usgs.gov/gdp/process/WebProcessin
'verbose' = FALSE,
'version' = '1.0.0')

#' @importFrom utils lsf.str
#' @importFrom utils lsf.str packageName
.onLoad <- function(libname, pkgname){
setJobState()
funs <- unclass(lsf.str(envir = asNamespace(packageName()), all = TRUE))
Expand Down
2 changes: 1 addition & 1 deletion R/geoknife-generic.R
Expand Up @@ -72,7 +72,7 @@ geoknife <- function(stencil, fabric, knife = webprocess(...), ...){
}

if (knife@wait){
waitUntilFinished(geojob, sleep.time = knife@sleep.time)
wait(geojob, sleep.time = knife@sleep.time)
}
return(geojob)
}
Expand Down
22 changes: 17 additions & 5 deletions R/waitUntilFinished.R
@@ -1,13 +1,25 @@

#' @title hold up R while GDP is processing
#' @description keeps R in a loop while GDP works on the request.
#' Checks \code{\link{running}}. Will drop out of loop whenever !running(geojob)
#' @keywords internal
#' hold up R while GDP is processing
#'
waitUntilFinished <- function(.Object, sleep.time = gconfig('sleep.time')){
#' keeps R in a loop while GDP works on the request. Checks \code{\link{running}}.
#' Will drop out of loop whenever !running(geojob)
#'
#' @param .Object a geojob
#' @param sleep.time a number of seconds to wait in between checking the process
#' @return invisible return of .Object, unaltered
#' @examples
#' \dontrun{
#' job <- geoknife(stencil = c(-89,42), fabric = 'prism')
#' 2+2
#' wait(job)
#' check(job) # should be complete
#' }
#' @export
wait <- function(.Object, sleep.time = gconfig('sleep.time')){
running <- running(.Object, retry = TRUE)
while(running){
Sys.sleep(sleep.time)
running <- running(.Object, retry = TRUE)
}
invisible(.Object)
}
3 changes: 2 additions & 1 deletion README.Rmd
Expand Up @@ -103,10 +103,11 @@ plot(data[,1:2], ylab = variables(fabric))
job <- geoknife(webgeom('state::New Hampshire'), fabric = 'prism', email = 'fake.email@gmail.com')
```

###`geoknife` Functions (as of v0.12.1)
###`geoknife` Functions (as of v1.1.5)
| Function | Title |
| ------------- |:-------------|
| `geoknife` | slice up gridded data according to overlap with feature(s) |
| `gconfig` | set or query package settings for `geoknife` processing defaults |
| `algorithm` | the algorithm of a `webprocess` |
| `attribute` | the attribute of an `webgeom` |
| `check` | check status of `geojob` |
Expand Down
55 changes: 28 additions & 27 deletions README.md
@@ -1,4 +1,4 @@
`geoknife` package version 1.1.4
`geoknife` package version 1.1.6
================================

[![Build status](https://ci.appveyor.com/api/projects/status/0iacmg82mp50426o/branch/master)](https://ci.appveyor.com/project/jread-usgs/geoknife/branch/master) [![Build Status](https://travis-ci.org/USGS-R/geoknife.svg)](https://travis-ci.org/USGS-R/geoknife) [![Coverage Status](https://coveralls.io/repos/USGS-R/geoknife/badge.svg)](https://coveralls.io/r/USGS-R/geoknife) [![Download Count](http://cranlogs.r-pkg.org/badges/geoknife)](https://cran.r-project.org/package=geoknife)
Expand Down Expand Up @@ -87,7 +87,7 @@ check(job)
## [1] "Process successful"
##
## $URL
## [1] "http://cida.usgs.gov:80/gdp/process/RetrieveResultServlet?id=0ac86798-7a2f-47c8-b153-3673e77e3e80OUTPUT"
## [1] "http://cida.usgs.gov:80/gdp/process/RetrieveResultServlet?id=3089e8d3-1ce7-4058-aa14-989ee4e67ae1OUTPUT"
##
## $statusType
## [1] "ProcessSucceeded"
Expand Down Expand Up @@ -115,31 +115,32 @@ plot(data[,1:2], ylab = variables(fabric))
job <- geoknife(webgeom('state::New Hampshire'), fabric = 'prism', email = 'fake.email@gmail.com')
```

### `geoknife` Functions (as of v0.12.1)

| Function | Title |
|--------------|:-------------------------------------------------------------|
| `geoknife` | slice up gridded data according to overlap with feature(s) |
| `algorithm` | the algorithm of a `webprocess` |
| `attribute` | the attribute of an `webgeom` |
| `check` | check status of `geojob` |
| `download` | download the results of a `geojob` |
| `error` | convenience function for state of `geojob` |
| `running` | convenience function for state of `geojob` |
| `successful` | convenience function for state of `geojob` |
| `start` | start a `geojob` |
| `cancel` | cancel a `geojob` |
| `geom` | the geom of a `webgeom` |
| `inputs` | the inputs of a `webprocess` |
| `id` | the process id of a `geojob` |
| `values` | the values of a `webgeom` |
| `result` | load the output of a completed `geojob` into data.frame |
| `variables` | the variables for a `webdata` object |
| `times` | the times of a `webdata` object |
| `url` | the url of a `webdata`, `webgeom`, `geojob`, or `webprocess` |
| `version` | the version of a `webgeom` or `webdata` |
| `xml` | the xml of a `geojob` |
| `query` | query datasets or variables |
### `geoknife` Functions (as of v1.1.5)

| Function | Title |
|--------------|:-----------------------------------------------------------------|
| `geoknife` | slice up gridded data according to overlap with feature(s) |
| `gconfig` | set or query package settings for `geoknife` processing defaults |
| `algorithm` | the algorithm of a `webprocess` |
| `attribute` | the attribute of an `webgeom` |
| `check` | check status of `geojob` |
| `download` | download the results of a `geojob` |
| `error` | convenience function for state of `geojob` |
| `running` | convenience function for state of `geojob` |
| `successful` | convenience function for state of `geojob` |
| `start` | start a `geojob` |
| `cancel` | cancel a `geojob` |
| `geom` | the geom of a `webgeom` |
| `inputs` | the inputs of a `webprocess` |
| `id` | the process id of a `geojob` |
| `values` | the values of a `webgeom` |
| `result` | load the output of a completed `geojob` into data.frame |
| `variables` | the variables for a `webdata` object |
| `times` | the times of a `webdata` object |
| `url` | the url of a `webdata`, `webgeom`, `geojob`, or `webprocess` |
| `version` | the version of a `webgeom` or `webdata` |
| `xml` | the xml of a `geojob` |
| `query` | query datasets or variables |

### `geoknife` classes (as of v0.12.0)

Expand Down
15 changes: 4 additions & 11 deletions cran-comments.md
@@ -1,17 +1,10 @@
## Resubmission
This is a resubmission. In this version I have:

* Added a new output type to data subsets (geotiff)
* Added a new vignette (plotting geotiffs)

* Modified the GET and POST requests to work correctly with the release and dev version of the httr package
* Modified the GET and POST requests to capture a warning message from the new CRAN version of the httr package

* improved documentation
* Added a new feature that allows users to turn on a verbose mode for web requests, and also set defaults for a number of variables.

* Fixed the CITATION file DOI, which was improperly formatted

### a note about geoknife URLs:
this package has a numer of service URLs that can be found in code,
in help text, and in vignettes. Some of these URLs will return 404s
without the proper POST body
(e.g., http://cida.usgs.gov/gdp/process/WebProcessingService). These
should be ignored for the purpose of testing valid urls.
* Removed urls in the vignette that cause 404s to url checks (as they are urls that receive POST bodies, not GET/HEAD requests)
31 changes: 15 additions & 16 deletions inst/doc/geoknife.html
Expand Up @@ -71,7 +71,7 @@
<div id="header">
<h1 class="title">geoknife package</h1>
<h4 class="author"><em>Jordan Read</em></h4>
<h4 class="date"><em>10 February, 2016</em></h4>
<h4 class="date"><em>11 February, 2016</em></h4>
</div>

<div id="TOC">
Expand Down Expand Up @@ -369,20 +369,19 @@ <h3>query function for <code>webgeom</code></h3>
## [4] &quot;derivative:CONUS_States&quot;
## [5] &quot;sample:CONUS_states&quot;
## [6] &quot;sample:CSC_Boundaries&quot;
## [7] &quot;upload:E4_UTM&quot;
## [8] &quot;derivative:FWS_LCC&quot;
## [9] &quot;sample:FWS_LCC&quot;
## [10] &quot;draw:GL&quot;
## [11] &quot;draw:GRSF&quot;
## [12] &quot;derivative:wbdhu8_alb_simp&quot;
## [13] &quot;derivative:Level_III_Ecoregions&quot;
## [14] &quot;derivative:NCA_Regions&quot;
## [15] &quot;derivative:US_Counties&quot;
## [16] &quot;draw:box&quot;
## [17] &quot;upload:climate_E4&quot;
## [18] &quot;upload:layers&quot;
## [19] &quot;sample:nps_boundary_2013&quot;
## [20] &quot;sample:simplified_HUC8s&quot;</code></pre>
## [7] &quot;derivative:FWS_LCC&quot;
## [8] &quot;sample:FWS_LCC&quot;
## [9] &quot;draw:GRSF&quot;
## [10] &quot;derivative:wbdhu8_alb_simp&quot;
## [11] &quot;derivative:Level_III_Ecoregions&quot;
## [12] &quot;derivative:NCA_Regions&quot;
## [13] &quot;draw:SD&quot;
## [14] &quot;derivative:US_Counties&quot;
## [15] &quot;draw:box&quot;
## [16] &quot;upload:haynes_wshed_project&quot;
## [17] &quot;upload:layers&quot;
## [18] &quot;sample:nps_boundary_2013&quot;
## [19] &quot;sample:simplified_HUC8s&quot;</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">query</span>(stencil, <span class="st">'attributes'</span>)</code></pre></div>
<pre><code>## [1] &quot;STATE&quot;</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">query</span>(stencil, <span class="st">'values'</span>)</code></pre></div>
Expand Down Expand Up @@ -653,7 +652,7 @@ <h3><code>cancel</code> geojob</h3>
<p>The <code>geoknife</code> package currently limits the user processing requests to single-running processes, so as to avoid creating thousands of requests in error, which could overwhelm the processing resources. If there is a reason to support additional jobs at one time, please email the package maintainers with your query.</p>
<p>To cancel and existing job: Cancel a running job but retain the details:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">id</span>(job)</code></pre></div>
<pre><code>## [1] &quot;http://cida.usgs.gov:80/gdp/process/RetrieveResultServlet?id=8d6f59b2-09be-4802-ab8a-a2609da1c158&quot;</code></pre>
<pre><code>## [1] &quot;http://cida.usgs.gov:80/gdp/process/RetrieveResultServlet?id=8ec535ed-711f-4192-b139-e6119fb89154&quot;</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">job &lt;-<span class="st"> </span><span class="kw">cancel</span>(job)
<span class="kw">id</span>(job)</code></pre></div>
<pre><code>## [1] &quot;&lt;no active job&gt;&quot;</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion inst/doc/plot_geotiff.html
Expand Up @@ -71,7 +71,7 @@
<div id="header">
<h1 class="title">subset gridded data as geotiff and plot</h1>
<h4 class="author"><em>Jordan Read, Alison Appling</em></h4>
<h4 class="date"><em>10 February, 2016</em></h4>
<h4 class="date"><em>11 February, 2016</em></h4>
</div>

<div id="TOC">
Expand Down
29 changes: 29 additions & 0 deletions man/wait.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions man/waitUntilFinished.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion tests/testthat/test-download_result.R
@@ -1,6 +1,6 @@
context("download and load")


gconfig(wps.url = "http://cida-test.er.usgs.gov/gdp/process/WebProcessingService")
test_that("download works", {
testthat::skip_on_cran()
cancel()
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-gconfig.R
Expand Up @@ -15,6 +15,8 @@ test_that("can set !read.only variables", {
expect_false(gconfig('wait'))
gconfig('wait'=TRUE)
expect_true(gconfig('wait'))
gconfig('wait'=FALSE)
expect_false(gconfig('wait'))
})

test_that("can set !read.only variables on webprocess()", {
Expand Down
14 changes: 13 additions & 1 deletion tests/testthat/test-waitUntilFinished.R
Expand Up @@ -12,4 +12,16 @@ test_that("creating simple job", {
expect_true(geoknife:::canStart())
geoknife(stencil, fabric, wait = FALSE)
expect_false(geoknife:::getJobState() == "Process successful")
})
})

context("Test re-enter wait loop")
test_that("creation of webprocess object", {
testthat::skip_on_cran()
fabric <- webdata('prism',times <- c('1895-01-01T00:00:00Z', '1999-01-01T00:00:00Z')) # should take longer than a re-check
cancel()
job <- geoknife(stencil = c(-89,42), fabric, wait=FALSE)
expect_equal(2+2, 4)
expect_true(running(job))
wait(job)
expect_false(running(job))
})

0 comments on commit 01f8668

Please sign in to comment.