annotate UrlRequestScheduler.R @ 7:882f2f20028b draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 608d9e59a0d2dcf85a037968ddb2c61137fb9bce
author prog
date Sun, 09 Apr 2017 10:44:21 -0400
parents b8f70d8216b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
1 if ( ! exists('UrlRequestScheduler')) { # Do not load again if already loaded
0
3afe41d3e9e7 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit bb4d3e23d99828bfee16d31d794c49a17313ec2f
prog
parents:
diff changeset
2
6
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
3 #############
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
4 # CONSTANTS #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
5 #############
0
3afe41d3e9e7 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit bb4d3e23d99828bfee16d31d794c49a17313ec2f
prog
parents:
diff changeset
6
6
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
7 RLIB.GET <- 'GET'
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
8 RLIB.POST <- 'POST'
0
3afe41d3e9e7 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit bb4d3e23d99828bfee16d31d794c49a17313ec2f
prog
parents:
diff changeset
9
6
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
10 #####################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
11 # CLASS DECLARATION #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
12 #####################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
13
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
14 UrlRequestScheduler <- setRefClass("UrlRequestScheduler", fields = list(.n = "numeric", .t = "numeric", .time.of.last.request = "ANY", .useragent = "character", .ssl.verifypeer = "logical", .nb.max.tries = "integer", .verbose = "integer"))
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
15
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
16 # n: number of connections
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
17 # t: time (in seconds)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
18
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
19 # The scheduler restrict the number of connections at n per t seconds.
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
20
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
21 ###############
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
22 # CONSTRUCTOR #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
23 ###############
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
24
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
25 UrlRequestScheduler$methods( initialize = function(n = 1, t = 1, useragent = NA_character_, ssl.verifypeer = TRUE, ...) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
26 .n <<- n
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
27 .t <<- t
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
28 .time.of.last.request <<- -1
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
29 .useragent <<- useragent
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
30 .nb.max.tries <<- 10L
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
31 .ssl.verifypeer <<- ssl.verifypeer
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
32 .verbose <<- 0L
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
33 callSuper(...) # calls super-class initializer with remaining parameters
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
34 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
35
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
36 ##################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
37 # SET USER AGENT #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
38 ##################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
39
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
40 UrlRequestScheduler$methods( setUserAgent = function(useragent) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
41 .useragent <<- useragent
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
42 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
43
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
44 ###############
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
45 # SET VERBOSE #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
46 ###############
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
47
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
48 UrlRequestScheduler$methods( setVerbose = function(verbose) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
49 .verbose <<- verbose
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
50 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
51
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
52 ##################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
53 # WAIT AS NEEDED #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
54 ##################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
55
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
56 # Wait the specified between two requests.
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
57 UrlRequestScheduler$methods( .wait.as.needed = function() {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
58
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
59 # Compute minimum waiting time between two URL requests
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
60 waiting_time <- .self$.t / .self$.n
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
61
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
62 # Wait, if needed, before previous URL request and this new URL request.
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
63 if (.self$.time.of.last.request > 0) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
64 spent_time <- Sys.time() - .self$.time.of.last.request
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
65 if (spent_time < waiting_time)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
66 Sys.sleep(waiting_time - spent_time)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
67 }
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
68
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
69 # Store current time
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
70 .time.of.last.request <<- Sys.time()
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
71 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
72
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
73 ####################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
74 # GET CURL OPTIONS #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
75 ####################
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
76
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
77 UrlRequestScheduler$methods( .get_curl_opts = function(url) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
78 opts <- curlOptions(useragent = .self$.useragent, timeout.ms = 60000, verbose = FALSE)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
79 return(opts)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
80 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
81
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
82 ###########
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
83 # GET URL #
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
84 ###########
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
85
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
86 UrlRequestScheduler$methods( .doGetUrl = function(url, params = NULL, method = RLIB.GET) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
87
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
88 content <- NA_character_
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
89
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
90 # Use form to send URL request
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
91 if ( ! is.null(params) && ! is.na(params))
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
92 switch(method,
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
93 GET = { content <- getForm(url, .opts = .self$.get_curl_opts(), .params = params) },
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
94 POST = { content <- postForm(url, .opts = .self$.get_curl_opts(), .params = params) },
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
95 stop(paste('Unknown method "', method, '".'))
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
96 )
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
97
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
98 # Get URL normally
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
99 else
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
100 content <- getURL(url, .opts = .self$.get_curl_opts(), ssl.verifypeer = .self$.ssl.verifypeer)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
101
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
102 return(content)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
103 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
104
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
105 UrlRequestScheduler$methods( getUrl = function(url, params = NULL, method = RLIB.GET) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
106
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
107 # Load library here and not inside .doGetUrl() since it is called from inside a try/catch clause, hence if library is missing the error will be ignored.
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
108 library(bitops)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
109 library(RCurl)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
110
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
111 content <- NA_character_
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
112
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
113 # Wait required time between two requests
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
114 .self$.wait.as.needed()
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
115
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
116 # Run query
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
117 for (i in seq(.self$.nb.max.tries)) {
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
118 tryCatch({ content <- .self$.doGetUrl(url, params = params, method = method) },
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
119 error = function(e) { if (.self$.verbose > 0) print("Retry connection to server...") } )
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
120 if ( ! is.na(content))
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
121 break
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
122 }
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
123
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
124 return(content)
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
125 })
b8f70d8216b3 planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
prog
parents: 1
diff changeset
126 }