r-lib / liteq
Showing 2 of 20 files from the diff.

@@ -41,11 +41,12 @@
Loading
41 41
  file.path(lockdir, paste0(queue, "-", id, ".lock"))
42 42
}
43 43
44 -
#' Publish a message in a queue
44 +
#' Publish messages in a queue
45 45
#'
46 46
#' @param queue The queue object.
47 -
#' @param title The title of the message. It can be the empty string.
48 -
#' @param message The body of the message. It can be the empty string.
47 +
#' @param title The title of the messages. It can be the empty string.
48 +
#' @param message The body of the messages. It can be the empty string.
49 +
#'   Must be the same length as `title`.
49 50
#'
50 51
#' @family liteq messages
51 52
#' @seealso [liteq] for examples
@@ -53,8 +54,9 @@
Loading
53 54
54 55
publish <- function(queue, title = "", message = "") {
55 56
  assert_that(is_queue(queue))
56 -
  assert_that(is_string(title))
57 -
  assert_that(is_string(message))
57 +
  assert_that(is.character(title))
58 +
  assert_that(is.character(message))
59 +
  assert_that(length(title) == length(message))
58 60
  db_publish(queue$db, queue$name, title, message)
59 61
}
60 62

@@ -169,14 +169,20 @@
Loading
169 169
}
170 170
171 171
db_publish <- function(db, queue, title, message) {
172 -
  do_db_execute(
173 -
    db,
174 -
    "INSERT INTO ?tablename (title, message)
175 -
     VALUES (?title, ?message)",
176 -
    tablename = db_queue_name(queue),
177 -
    title = title,
178 -
    message = message
179 -
  )
172 +
  con <- db_connect(db)
173 +
  on.exit(dbDisconnect(con))
174 +
  dbWithTransaction(con, {
175 +
    for (i in seq_along(title)) {
176 +
      db_execute(
177 +
        con,
178 +
        "INSERT INTO ?tablename (title, message)
179 +
         VALUES (?title, ?message)",
180 +
        tablename = db_queue_name(queue),
181 +
        title = title[i],
182 +
        message = message[i]
183 +
      )
184 +
    }
185 +
  })
180 186
  invisible()
181 187
}
182 188
Files Coverage
R 0.00%
Project Totals (5 files) 0.00%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading