JSON.parse env before checking for delta, and use progress.percentage

This commit is contained in:
Pablo Carranza Vélez 2015-11-11 00:51:51 -03:00 committed by Pablo Carranza Velez
parent 1bc149866d
commit 8e4e844cfa
2 changed files with 15 additions and 12 deletions

View File

@ -127,22 +127,24 @@ isValidPort = (port) ->
fetch = (app) ->
onProgress = (progress) ->
device.updateState(download_progress: progress.percent)
device.updateState(download_progress: progress.percentage)
docker.getImage(app.imageId).inspectAsync()
.catch (error) ->
logSystemEvent(logTypes.downloadApp, app)
device.updateState(status: 'Downloading', download_progress: 0)
if app.env.RESIN_DELTA?
fetchPromise = dockerUtils.rsyncImageWithProgress(app.imageId, onProgress)
else
fetchPromise = dockerUtils.fetchImageWithProgress(app.imageId, onProgress)
fetchPromise.then ->
logSystemEvent(logTypes.downloadAppSuccess, app)
device.updateState(status: 'Idle', download_progress: null)
docker.getImage(app.imageId).inspectAsync()
Promise.try ->
JSON.parse(app.env)
.then (env) ->
if env['RESIN_DELTA'] == '1'
fetchPromise = dockerUtils.rsyncImageWithProgress(app.imageId, onProgress)
else
fetchPromise = dockerUtils.fetchImageWithProgress(app.imageId, onProgress)
fetchPromise.then ->
logSystemEvent(logTypes.downloadAppSuccess, app)
device.updateState(status: 'Idle', download_progress: null)
docker.getImage(app.imageId).inspectAsync()
.catch (err) ->
logSystemEvent(logTypes.downloadAppError, app, err)
throw err

View File

@ -50,9 +50,10 @@ exports.rsyncImageWithProgress = (imgDest, onProgress) ->
rsyncDiff = new Promise (resolve, reject) ->
console.log("#{config.deltaHost}/api/v1/delta?src=#{imgSrc}&dest=#{imgDest}", timeout: 5 * 60 * 1000)
progress request.get("#{config.deltaHost}/api/v1/delta?src=#{imgSrc}&dest=#{imgDest}", timeout: 5 * 60 * 1000)
.on 'progress', onProgress
.on 'progress', (progress) ->
onProgress(percentage: progress.percent)
.on 'end', ->
onProgress(percent: 100)
onProgress(percentage: 100)
.on 'response', (res) ->
if res.statusCode isnt 200
reject()