Skip to content

Commit

Permalink
factor application querying and creation out of the main deploy function
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Oct 2, 2013
1 parent 4558c7c commit d89e0a7
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,16 @@ deploy <- function(appDir = getwd(), appName = NULL, account = NULL) {

# determine the deployment target and target account info
target <- deploymentTarget(appDir, appName, account)
appName <- target$appName
account <- target$account
accountInfo <- accountInfo(target$account)

# list the existing applications for this account and see if we
# need to create a new application
app <- NULL
existingApps <- lucid$applications(accountInfo$accountId)
for (existingApp in existingApps) {
if (identical(existingApp$name, target$appName)) {
app <- existingApp
break
}
}

# if there is no record of deploying this application locally yet there
# is an application of that name already deployed then confirm
if (!target$isUpdate && !is.null(app) && interactive()) {
prompt <- paste("Update existing application at ", app$url,
"? [Y/n] ", sep="")
input <- readline(prompt)
if (nzchar(input) && !identical(input, "y") && !identical(input, "Y"))
stop("Application deployment aborted")
}

# create the application if we need to
if (is.null(app)) {
app <- lucid$createApplication(target$appName,
"shiny",
accountInfo$accountId)
}
# get the application to deploy (creates a new app on demand)
application <- applicationForTarget(lucid, accountInfo, target)

# upload the bundle
bundle <- lucid$uploadApplication(app$id, bundlePath)
bundle <- lucid$uploadApplication(application$id, bundlePath)

# deploy the bundle
task <- lucid$deployApplication(app$id, bundle$id)
task <- lucid$deployApplication(application$id, bundle$id)

# poll for task status

Expand All @@ -77,7 +50,7 @@ deploy <- function(appDir = getwd(), appName = NULL, account = NULL) {
target$appName,
target$account,
bundle$id,
app$url)
application$url)

invisible(TRUE)
}
Expand Down Expand Up @@ -194,6 +167,43 @@ deploymentTarget <- function(appDir, appName, account) {
}
}

# get the application associated with the passed deployment target
# (creates a new application if necessary)
applicationForTarget <- function(lucid, accountInfo, target) {

# list the existing applications for this account and see if we
# need to create a new application
app <- NULL
existingApps <- lucid$applications(accountInfo$accountId)
for (existingApp in existingApps) {
if (identical(existingApp$name, target$appName)) {
app <- existingApp
break
}
}

# if there is no record of deploying this application locally however there
# is an application of that name already deployed then confirm
if (!target$isUpdate && !is.null(app) && interactive()) {
prompt <- paste("Update existing application at ", app$url,
"? [Y/n] ", sep="")
input <- readline(prompt)
if (nzchar(input) && !identical(input, "y") && !identical(input, "Y"))
stop("Application deployment cancelled", call. = FALSE)
}

# create the application if we need to
if (is.null(app)) {
app <- lucid$createApplication(target$appName,
"shiny",
accountInfo$accountId)
}

# return the application
app
}


saveDeployment <- function(appDir, name, account, bundleId, url) {

deployment <- deploymentRecord(name, account, bundleId, url)
Expand Down

0 comments on commit d89e0a7

Please sign in to comment.