<commit_before>angular.module( 'update.update', [
    'emguo.poller',
    'resources.users'
  ])
  .factory("Update", function($modal,
                              $timeout,
                              $q,
                              poller,
                              UsersUpdateStatus){

    var status = {}
    var url_slug
    var modalInstance
    var pollingInterval = 10  // 10ms...as soon as we get server resp, ask again.
    var deferred

    var clear = function(){
      status = {}
      url_slug = null
      deferred = null
      modalInstance = null
    }

    var tick = function(){
      UsersUpdateStatus.get({id:url_slug}).$promise.then(function(resp){
          console.log("tick() got response back from server", resp)
          status = resp
          if (resp.percent_complete == 100){
            console.log("tick() satisfied success criteria, breaking out of recursion loop")
            modalInstance.close()
            deferred.resolve("Update finished!")
            clear()
          }
          else {
            $timeout(tick, pollingInterval)
          }
        }
      )
    }

    var showUpdateModal = function(url_slug_arg){
      deferred = $q.defer()
      url_slug = url_slug_arg

      if (modalInstance){
        // we can only have one modal instance running at once...otherwise, it breaks.
        deferred.reject("there's already an update modal up.")
        return deferred.promise
      }


      UsersUpdateStatus.get({id:url_slug}).$promise.then(
        function(resp) {
          status = resp

          if (status.percent_complete < 100){

            // open the modal
            modalInstance = $modal.open({
              templateUrl: 'update/update-progress.tpl.html',
              controller: 'updateProgressModalCtrl',
              backdrop:"static",<commit_msg>catch bad responses from GET /user/:id/update_status calls.<commit_after>angular.module( 'update.update', [
    'emguo.poller',
    'resources.users'
  ])
  .factory("Update", function($modal,
                              $timeout,
                              $q,
                              poller,
                              UsersUpdateStatus){

    var status = {}
    var url_slug
    var modalInstance
    var pollingInterval = 10  // 10ms...as soon as we get server resp, ask again.
    var deferred

    var clear = function(){
      status = {}
      url_slug = null
      deferred = null
      modalInstance = null
    }

    var tick = function(){
      UsersUpdateStatus.get({id:url_slug}).$promise.then(
        function(resp){
          console.log("tick() got response back from server", resp)
          status = resp
          if (resp.percent_complete == 100){
            console.log("tick() satisfied success criteria, breaking out of recursion loop")
            modalInstance.close()
            deferred.resolve("Update finished!")
            clear()
          }
          else {
            $timeout(tick, pollingInterval)
          }
        },
        function(resp){
          console.log("failed to get update status; trying again.", resp)
          $timeout(tick, pollingInterval)
        }
      )
    }

    var showUpdateModal = function(url_slug_arg){
      deferred = $q.defer()
      url_slug = url_slug_arg

      if (modalInstance){
        // we can only have one modal instance running at once...otherwise, it breaks.
        deferred.reject("there's already an update modal up.")
        return deferred.promise
      }


      UsersUpdateStatus.get({id:url_slug}).$promise.then(
        function(resp) {
          status = resp

          if (status.percent_complete < 100){

            // open the modal
            modalInstance = $modal.open({
              templateUrl: 'update/update-progress.tpl.html',
              controller: 'updateProgressModalCtrl',
              backdrop:"static",
{'fraction_non_alphanumeric': 0.10257731958762886, 'fraction_numerical': 0.005154639175257732, 'mean_word_length': 1.7026462395543176, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6882346', 'n_tokens_mistral': 1035, 'n_tokens_neox': 998, 'n_words': 253}