<commit_before>module Brahma
  class JobSender
    def initialize(name, redis)
      @redis = redis
      @name = name
    end

    def echo(message)
      send({type: :echo, message: message})
    end

    def email(to, subject, content)
      send({type: :email, to: to, subject: subject, content: content, create: Time.now, timeout: 60*60*24})
    end

    def send(request={})
      @redis.with do |conn|
        conn.lpush queue, Marshal.dump(request)
      end
    end


    def receive(timeout)
      @redis.with do |conn|
        task = conn.brpop(queue, timeout)
        unless task.nil?
          yield Marshal.load(task[1])
        end
      end
    end

    private
    def queue
      "worker://#{@name}"
    end
  end
end<commit_msg>message和jobsender分离<commit_after>module Brahma
  module Job
    module Request
      module_function

      def echo(message)
        {type: :echo, message: message}
      end

      def email(to, subject, content)
        {type: :email, to: to, subject: subject, content: content, create: Time.now, timeout: 60*60*24}
      end
    end

    class RabbitJobSender
      def initialize

      end
      def send(request)

      end
      def receive(timeout)

      end
    end

    class RedisSender
      def initialize(name, redis)
        @redis = redis
        @name = name
      end

      def send(request)
        @redis.with do |conn|
          conn.lpush queue, Marshal.dump(request)
        end
      end


      def receive(timeout)
        @redis.with do |conn|
          task = conn.brpop(queue, timeout)
          unless task.nil?
            yield Marshal.load(task[1])
          end
        end
      end

      private
      def queue
        "worker://#{@name}"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09407069555302167, 'fraction_numerical': 0.00798175598631699, 'mean_word_length': 1.826086956521739, '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': '303026', 'n_tokens_mistral': 560, 'n_tokens_neox': 533, 'n_words': 154}