<commit_before>namespace :mockbot do
  desc %(Publish a product from MockBot with the given sku.)
  task :publish, [:sku] => :environment do |t, args|

    args.with_defaults sku: nil
    sku = args.sku
    Spree::Product.delay.publish_from_mockbot(sku)
    # rake_publisher.delay.publish(sku)

    # args.with_defaults sku: nil
    # sku = args.sku
    #
    # if sku.nil?
    #   STDOUT.puts %(
    #     Please provide a sku, for example:
    #     `bundle exec rake mockbot:upload[some_product_sku]`
    #   )
    #   next
    # end
    #
    # Thread.current[:response] = Struct.new(:original_uri)
    #   .new(Spree::Store.default.first.domains.split(/\s/).first)
    #
    # begin
    #   idea = Spree::Mockbot::Idea.where(sku: sku).first
    # rescue Errno::ECONNREFUSED
    #   STDOUT.puts %(
    #     MockBot connection refused. Is it down?
    #   )
    #   next
    # rescue ActiveResource::UnauthorizedAccess
    #   STDOUT.puts %(
    #     MockBot authorization failed. Go check out the authentication settings for MockBot
    #     in the Spree Admin.
    #   )
    #   next
    # rescue StandardError => e
    #   STDOUT.puts "Error while connecting to MockBot: #{e.message}"
    #   next
    # end
    # if idea.nil?
    #   STDOUT.puts "Found no idea with sku #{sku}."
    #   next
    # end
    #
    # publisher = idea.publisher
    # publisher.try(:destroy)
    #
    # publisher = Spree::Mockbot::Idea::Publisher
    #             .create(idea_sku: sku)
    #
    # begin
    #   publisher.do_everything!
    # rescue Spree::Mockbot::Idea::PublishError => e
    #   STDOUT.puts %(
    #     Error during `#{publisher.current_step}` step: #{e.message}
    #   )
    #   next
    # rescue SpreeMockbotIntegration::Sku::SkuError => e
    #   STDOUT.puts %(
    #     Sku error during `#{publisher.current_step}` step: #{e.message}
    #   )
    #   next
    # end
    #
    # publisher.destroy
    #
    # STDOUT.puts %(
    #   Successfully published products for idea #{sku}!
    # )
  end

  desc 'Publish products that are ready_to_publish'
  task publish_all: :environment do
    page = 1
    ideas = Spree::Mockbot::Idea.all(params: {page: page})
    until ideas.empty?
      ideas.each do |idea|
        if idea.status == 'ready_to_publish'
          Spree::Product.delay.publish_from_mockbot(idea.sku)
        end
      end
      page += 1
      ideas = Spree::Mockbot::Idea.all(params: {page: page})
    end
  end

end
<commit_msg>Revised "Publish from Mockbot" to not delay<commit_after>namespace :mockbot do
  desc %(Publish a product from MockBot with the given sku.)
  task :publish, [:sku] => :environment do |t, args|

    args.with_defaults sku: nil
    sku = args.sku
    Spree::Product.publish_from_mockbot(sku)

  end

  desc 'Publish products that are ready_to_publish'
  task publish_all: :environment do
    page = 1
    ideas = Spree::Mockbot::Idea.all(params: {page: page})
    until ideas.empty?
      ideas.each do |idea|
        if idea.status == 'ready_to_publish'
          puts idea.sku
          puts Time.now
          begin
            Spree::Product.publish_from_mockbot(idea.sku)
          rescue Exception => e
            puts e
          end
        end
      end
      page += 1
      ideas = Spree::Mockbot::Idea.all(params: {page: page})
    end
  end

end

{'fraction_non_alphanumeric': 0.11509490810485086, 'fraction_numerical': 0.0012051822838204278, 'mean_word_length': 2.2773938795656465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4314420', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1141, 'n_words': 262}