Class: Sidediq::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sidediq/cli.rb

Class Method Summary collapse

Class Method Details

.startObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sidediq/cli.rb', line 16

def self.start

    pp CONFIG.config
    socket_type = case CONFIG.config[:socket_type]
        when "pull"
            ZMQ::PULL
        else
            raise "Invalid socket type (only 'pull' is supported for now)"
        end

    socket_bind = CONFIG.config[:bind_address]

    context = ZMQ::Context.new
    socket  = context.socket(socket_type)
    socket.bind(socket_bind)

    print "Server is running and waiting for messages...\n"

    loop do
        msg = ""
        socket.recv_string(msg)
        puts "Server received: #{msg}"
        # socket.send_string("ACK: #{msg}", 0)
        job_data = JSON.parse(msg)
        Sidediq::Job.execute(job_data)
    end
    print "Server shutting down...\n"
    socket.close
    context.terminate
end