From 6651ab6419d8b498cc143cb7e82d8d99807ae83b Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Tue, 22 Jan 2013 11:58:24 -0500 Subject: [PATCH] refactor, note results of restart experiment --- api.coffee | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/api.coffee b/api.coffee index cda3905..3108f4f 100644 --- a/api.coffee +++ b/api.coffee @@ -92,10 +92,7 @@ request = (method, path, content_type, data, token, callback) -> method: method headers: 'Content-Type': content_type opts.headers['Authorization'] = token if token? - # no Accept header: -> unsupported media type - opts.headers['Accept'] = '*/*;q=0.8' # -> bad request (in json) - #opts.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' # -> bad request (in json) or blank 404 - #opts.headers['Accept'] = 'application/json' -> unsupported media type + opts.headers['Accept'] = '*/*;q=0.8' async.waterfall [ (callback) -> if content_type is 'multipart/form-data' @@ -171,14 +168,7 @@ exports.login = login = (username, password, callback) -> exports.app_publish = (token, app_name, zip_file, callback) -> exports.app_update_files token, app_name, zip_file, (err) -> return callback err if err? - # FIXME add "restart" call that only calls app_info once - exports.app_stop token, app_name, (err) -> - if err? - return callback "Couldn't stop the app (to restart it). App is probably still running old version (though perhaps accessing new files.). Server responded: #{err}" - exports.app_start token, app_name, (err) -> - if err? - return callback "CRITICAL ERROR: Couldn't start the app back up! Server responded: #{err}" - callback() + exports.app_restart token, app_name, callback exports.app_update_files = (token, app_name, zip_file, callback) -> request( @@ -200,10 +190,13 @@ exports.app_set_info = (token, app_name, info, callback) -> json_put "/apps/#{app_name}", info, token, callback app_set_state = (token, app_name, state, callback) -> - exports.app_info token, app_name, (err, info) -> - return callback err if err? - info.state = state - exports.app_set_info token, app_name, info, callback + async.waterfall [ + (callback) -> + exports.app_info token, app_name, callback + (info, callback) -> + info.state = state + exports.app_set_info token, app_name, info, callback + ], callback exports.app_start = (token, app_name, callback) -> app_set_state token, app_name, 'STARTED', callback @@ -211,6 +204,13 @@ exports.app_start = (token, app_name, callback) -> exports.app_stop = (token, app_name, callback) -> app_set_state token, app_name, 'STOPPED', callback +exports.app_restart = (token, app_name, callback) -> + # Server requires you to fetch the app state before each call to change + # it, so there's no quicker way than just calling app_stop then app_start + async.waterfall [ + (callback) -> exports.app_stop token, app_name, callback + (callback) -> exports.app_start token, app_name, callback + ], callback app_get = (path) -> return (token, app_name, callback) -> -- 1.7.10.4