<commit_before>/* global animateSpinner FilePreviewModal */

var Assets = (function() {
  function refreshAssets() {
    var elements = $("[data-status='asset-loading']");

    if (!elements.length) {
      return false;
    }

    $.each(elements, function(_, el) {
      var $el = $(el);

      // Perform an AJAX call to present URL
      // to check if file already exists
      $.ajax({
        url: $el.data('present-url'),
        type: 'GET',
        dataType: 'json',
        success: function(data) {
          if (data.processing === true) {
            return;
          }

          if (data.processing === false) {
            $el.html(data.placeholder_html);
            $el.attr('data-status', 'asset-loaded');
            animateSpinner(null, false);
            FilePreviewModal.init();
          }
        },
        error: function() {
          animateSpinner(null, false);
        }
      });
    });

    return true;
  }

  function finalizeAssets() {
    var elements = $("[data-status='asset-loading']");

    $.each(elements, function(_, el) {
      var $el = $(el);
      $el.attr('data-status', 'asset-failed');
      if ($el.data('filename')) {
        $el.html($el.data('filename'));
      }
    });
  }

  function setupAssetsLoading() {
    var DELAY = 5000;
    var REPETITIONS = 60;
    var cntr = 0;
    var intervalId;

    if (window.assetsPollingIsRunning) return;

    intervalId = window.setInterval(function() {
      cntr += 1;
      if (cntr >= REPETITIONS || !refreshAssets()) {
        finalizeAssets();
        window.clearInterval(intervalId);
        window.assetsPollingIsRunning = false;
      }
    }, DELAY);

    window.assetsPollingIsRunning = true;
  }

  return Object.freeze({
    setupAssetsLoading: setupAssetsLoading
  });
}());<commit_msg>Refactor assets polling to use setTimeout [SCI-3461]<commit_after>/* global animateSpinner FilePreviewModal */

var Assets = (function() {
  var DELAY = 5000;
  var REPETITIONS_LIMIT = 30;

  function finalizeAsset(element) {
    var $el = $(element);

    $el.attr('data-status', 'asset-failed');
    if ($el.data('filename')) {
      $el.html($el.data('filename'));
    }
  }

  function refreshAsset(element) {
    var $el = $(element);

    if ($el.data('refreshCounter') > REPETITIONS_LIMIT) {
      finalizeAsset($el);
      return;
    }

    // Perform an AJAX call to present URL
    // to check if file already exists
    $.ajax({
      url: $el.data('present-url'),
      type: 'GET',
      dataType: 'json',
      success: function(data) {
        if (data.processing === true) {
          setTimeout(function() {
            refreshAsset($el);
          }, DELAY);
        }

        if (data.processing === false) {
          $el.html(data.placeholder_html);
          $el.attr('data-status', 'asset-loaded');
          animateSpinner($el, false);
          FilePreviewModal.init();
        }
      },
      error: function() {
        animateSpinner(null, false);
      }
    });

    $el.data().refreshCounter += 1;
  }

  function setupAssetsLoading() {
    var elements = $("[data-status='asset-loading']");

    if (!elements.length) {
      return;
    }

    $.each(elements, function(_, el) {
      var $el = $(el);

      if ($el.data('refreshIsRunning') === true) return;

      $el.data('refreshCounter', 1);
      $el.data('refreshIsRunning', true);

      setTimeout(function() {
        refreshAsset($el);
      }, DELAY);
    });
  }

  return Object.freeze({
    setupAssetsLoading: setupAssetsLoading
  });
}());
{'fraction_non_alphanumeric': 0.15829571106094809, 'fraction_numerical': 0.0056433408577878106, 'mean_word_length': 2.2374429223744294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '796392', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1077, 'n_words': 225}