Skip to content

Commit 0bafb3b

Browse files
committed
sdd1.04a and more robust record_sdd() function
1 parent 19fac42 commit 0bafb3b

File tree

12 files changed

+160
-130
lines changed

12 files changed

+160
-130
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: BioDataScience
22
Type: Package
3-
Version: 0.6.0
3+
Version: 0.7.0
44
Title: A Series of Learnr Documents for Biological Data Science
55
Description: Interactive documents using learnr for studying biological data science.
66
Authors@R: c(

NEWS.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
# BioDataScience News
22

3+
## Changes in version 0.7.0
4+
5+
- Tutorial 04a_test finalized
6+
7+
8+
## Changes in version 0.6.1
9+
10+
- More robust code for record_sdd()
11+
12+
313
## Changes in version 0.6.0
414

515
- Tutorial 03a_test finalized
616

17+
718
## Changes in version 0.5.0
819

9-
- add new datasest biometry
20+
- Add new dataset biometry
1021

1122

1223
## Changes in version 0.4.0

R/record_sdd.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ record_sdd <- function(tutorial_id, tutorial_version, user_id, event, data) {
4545
#}
4646
# Once http request with stitch will be available, we could do something like
4747
#https://stitch.mongodb.com/api/client/v2.0/app/sdd-relay-aizkd/service/sdd-http/incoming_webhook/webhook0
48+
db_injected <- FALSE
4849
m <- try(mongo("sdd",
4950
#url = "mongodb://sdd:sdd@ds125388.mlab.com:25388/sdd-test")$insert(entry)
5051
url = "mongodb://sdd:sdd@sdd-umons-shard-00-00-umnnw.mongodb.net:27017,sdd-umons-shard-00-01-umnnw.mongodb.net:27017,sdd-umons-shard-00-02-umnnw.mongodb.net:27017/test?ssl=true&replicaSet=sdd-umons-shard-0&authSource=admin"),
@@ -53,18 +54,24 @@ record_sdd <- function(tutorial_id, tutorial_version, user_id, event, data) {
5354
# No run() methods in mongolite 1.5
5455
#m$run(command = "{\"ping\": 1}", simplify = TRUE)$ok == 1) {
5556
m$count() > -1) {
56-
m$insert(entry)
57+
res <- try(m$insert(entry), silent = TRUE)
5758
# If there is something in the biodatascience file, inject it also now
58-
if (file.exists(bds_file)) {
59-
dat <- readLines(bds_file)
60-
unlink(bds_file)
61-
if (length(dat))
62-
for (i in 1:length(dat))
63-
m$insert(unserialize(base64_dec(dat[i])))
59+
if (!inherits(res, "try-error")) {
60+
db_injected <- TRUE
61+
# Check if we also need to inject pending records
62+
if (file.exists(bds_file)) {
63+
dat <- readLines(bds_file)
64+
unlink(bds_file)
65+
if (length(dat))
66+
for (i in 1:length(dat))
67+
m$insert(unserialize(base64_dec(dat[i])))
68+
}
6469
}
6570
# No disconnect() method in mongolite 1.5
6671
#m$disconnect()
67-
} else {# MongoDB database not available... save locally
72+
}
73+
# Only get rid of the entry if it was actually injected in the database
74+
if (!isTRUE(db_injected)) {# MongoDB database not available, or error... save locally
6875
add_file_base64(entry, file = bds_file)
6976
}
7077
}

0 commit comments

Comments
 (0)