<commit_before>module.exports = function delayer(channel, opts) {
  opts = opts || {};
  opts.separator = opts.separator || '.';
  opts.prefix = opts.prefix || 'delay';
  opts.threshold = opts.threshold || 10000;
  opts.round = opts.round || 1000;

  channel.delay = function delay(delayMs) {
    return {
      publish: function publish(exchange, routingKey, content, options) {
        delayMs = Math.round(delayMs / opts.round) * opts.round;

        var ttl = delayMs;
        var time = { ms: 1000, s: 60, m: 60, h: 24, d: 30, mo: 12, y: 999999 };

        delayMs = Object.keys(time).map(function(unit) {
          var mod = delayMs % time[unit];
          delayMs = Math.floor(delayMs / time[unit]);
          if (!mod) {
            return '';
          }
          return mod + unit;
        }).reverse().join('');

        var name = opts.prefix + opts.separator + [exchange, delayMs].join(opts.separator);

        return channel.assertQueue(name, {
          durable: true,
          autoDelete: true,
          arguments: {
            'x-dead-letter-exchange': exchange,
            'x-dead-letter-routing-key': routingKey,
            'x-message-ttl': ttl,
            'x-expires': ttl + opts.threshold
          }
        }).then(function () {
          return channel.sendToQueue(name, content, options);
        });
      }
    };
  };
};<commit_msg>publish to wait exchange to keep original routing keys<commit_after>module.exports = function delayer(channel, opts) {
  opts = opts || {};
  opts.separator = opts.separator || '.';
  opts.prefix = opts.prefix || 'delay';
  opts.threshold = opts.threshold || 10000;
  opts.round = opts.round || 1000;

  channel.delay = function delay(delayMs) {
    return {
      publish: function publish(exchange, routingKey, content, options) {
        delayMs = Math.ceil(delayMs / opts.round) * opts.round;

        var ttl = delayMs;
        var time = { ms: 1000, s: 60, m: 60, h: 24, d: 30, mo: 12, y: 999999 };

        delayMs = Object.keys(time).map(function(unit) {
          var mod = delayMs % time[unit];
          delayMs = Math.floor(delayMs / time[unit]);
          if (!mod) {
            return '';
          }
          return mod + unit;
        }).reverse().join('');

        var name = [opts.prefix, exchange, delayMs].join(opts.separator);

        return channel.assertExchange(name, 'fanout', {
          durable: true,
          autoDelete: true
        }).then(function () {
          return channel.assertQueue(name, {
            durable: true,
            autoDelete: true,
            arguments: {
              'x-dead-letter-exchange': exchange,
              'x-message-ttl': ttl,
              'x-expires': ttl + opts.threshold
            }
          });
        }).then(function () {
          return channel.bindQueue(name, name, '#');
        }).then(function () {
          return channel.publish(name, routingKey, content, options);
        });
      }
    };
  };
};
{'fraction_non_alphanumeric': 0.14541160593792174, 'fraction_numerical': 0.019568151147098516, 'mean_word_length': 1.985901309164149, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4238327', 'n_tokens_mistral': 936, 'n_tokens_neox': 859, 'n_words': 204}