<commit_before>class Api::V1::WebhooksController < Api::V1::BaseApiController
  before_filter :require_api_auth_token

  def feed_fetcher
    if params[:feed_onestop_id].present?
      workers = [
        Feed.find_by_onestop_id!(params[:feed_onestop_id]).async_fetch_feed_version
      ]
    else
      workers = Feed.async_fetch_all_feeds
    end
    if workers
      render json: {
        code: 200,
        message: "FeedFetcherWorkers #{workers.join(', ')} enqueued.",
        errors: []
      }
    else
      raise 'FeedFetcherWorkers could not be created or enqueued.'
    end
  end

  def feed_eater
    feed = Feed.find_by_onestop_id!(params[:feed_onestop_id])
    feed_version_sha1 = params[:feed_version_sha1]
    if feed_version_sha1.present?
      feed_version = feed.feed_versions.find_by(sha1: feed_version_sha1)
    else
      feed_version = feed.feed_versions.first!
    end
    import_level = params[:import_level].present? ? params[:import_level].to_i : 0
    feed_eater_worker = FeedEaterWorker.perform_async(feed.onestop_id, feed_version.sha1, import_level)
    if feed_eater_worker
      render json: {
        code: 200,
        message: "FeedEaterWorker ##{feed_eater_worker} has been enqueued.",
        errors: []
      }
    else
      raise 'FeedEaterWorker could not be created or enqueued.'
    end
  end
end<commit_msg>Webhook for FeedActivationWorker<commit_after>class Api::V1::WebhooksController < Api::V1::BaseApiController
  before_filter :require_api_auth_token

  def feed_fetcher
    if params[:feed_onestop_id].present?
      workers = [
        Feed.find_by_onestop_id!(params[:feed_onestop_id]).async_fetch_feed_version
      ]
    else
      workers = Feed.async_fetch_all_feeds
    end
    if workers
      render json: {
        code: 200,
        message: "FeedFetcherWorkers #{workers.join(', ')} enqueued.",
        errors: []
      }
    else
      raise 'FeedFetcherWorkers could not be created or enqueued.'
    end
  end

  def feed_eater
    feed = Feed.find_by_onestop_id!(params[:feed_onestop_id])
    feed_version_sha1 = params[:feed_version_sha1]
    if feed_version_sha1.present?
      feed_version = feed.feed_versions.find_by(sha1: feed_version_sha1)
    else
      feed_version = feed.feed_versions.first!
    end
    import_level = params[:import_level].present? ? params[:import_level].to_i : 0
    feed_eater_worker = FeedEaterWorker.perform_async(feed.onestop_id, feed_version.sha1, import_level)
    if feed_eater_worker
      render json: {
        code: 200,
        message: "FeedEaterWorker ##{feed_eater_worker} has been enqueued.",
        errors: []
      }
    else
      raise 'FeedEaterWorker could not be created or enqueued.'
    end
  end

  def feed_activation
    feed = Feed.find_by_onestop_id!(params[:feed_onestop_id])
    feed_version = feed.feed_versions.find_by(sha1: params[:feed_version_sha1])
    feed_activation_worker = FeedActivationWorker.perform_async(feed.onestop_id, feed_version.sha1)
    if feed_activation_worker
      render json: {
        code: 200,
        message: "FeedActivationWorker ##{feed_activation_worker} has been enqueued.",
        errors: []
      }
    else
      raise 'FeedActivationWorker could not be created or enqueued.'
    end
  end

end
{'fraction_non_alphanumeric': 0.08698315467075038, 'fraction_numerical': 0.011026033690658498, 'mean_word_length': 3.2581486310299868, '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': '4323348', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1078, 'n_words': 205}