pkieltyka (owner)

Revisions

gist: 207694 Download_button fork
public
Public Clone URL: git://gist.github.com/207694.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
46
# Attempt 1
EventMachine.run do
  beanstalk = EMJack::Connection.new
 
  r = beanstalk.reserve
  r.callback do |job|
    puts job.jobid
    #process(job)
 
    r2 = beanstalk.delete(job)
    r2.callback { puts "Successfully deleted" }
  end
end
 
# Attempt 2 -- blocks forever
EventMachine.run do
  beanstalk = EMJack::Connection.new
 
  loop do
    r = beanstalk.reserve
    r.callback do |job|
      puts job.jobid
      #process(job)
 
      r2 = beanstalk.delete(job)
      r2.callback { puts "Successfully deleted" }
    end
  end
end
 
# Attempt 3 -- seems to work, but is there a better way?
EventMachine.run do
  beanstalk = EMJack::Connection.new
 
  EM.add_periodic_timer(0) do
    r = beanstalk.reserve
    r.callback do |job|
      puts job.jobid
      #process(job)
 
      r2 = beanstalk.delete(job)
      r2.callback { puts "Successfully deleted" }
    end
  end
end