 TIME_BETWEEN_UPDATE_CHECKS = 1000 * 60 * 60 * 24 # once a day
 
 
+# Check updates download the application manifest and extract version from it.
+# Then it compares it with the actual version number. If it's higher, a
+# *needUpdate* flag is set to true on the application model.
 checkUpdate = (notifier, app) ->
     log.info "#{app.name} - checking for an update..."
     app.checkForUpdate (err, setUpdate) ->
-        log.debug "#{app.version}"
         if err?
             log.error "#{app.name} - Error while checking update."
-            console.log err
+            log.raw err
         else if setUpdate
             log.info "#{app.name} - update required."
             notifier.createTemporary

            log.info "#{app.name} - no update required."


checkUpdates = ->
    notifier = new NotificationsHelper 'home'


    Application.all (err, apps) ->
        if err
            log.error "Error when checking apps versions:"
            log.raw err
        else
            for app in apps
                checkUpdate notifier, app


# Start check update cron.
module.exports = ->
    checkUpdates()
    setInterval checkUpdates, TIME_BETWEEN_UPDATE_CHECKS
