Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/usr/bin/ruby -w
  2.  
  3. require 'rubygems'
  4. require 'mongo'
  5. require 'thread'
  6.  
  7. include Mongo
  8.  
  9. db = Connection.new('localhost',27017,:slave_ok => true).db('test')
  10. coll = db['cappedCollection']
  11. start_count = coll.count
  12.  
  13. insertion = Thread.new do
  14. loop do
  15. coll.save({:timestamp => Time.now.to_i})
  16. sleep rand(0.5)
  17. end
  18. end
  19.  
  20. tail = Thread.new do
  21. loop do
  22. puts "Creating the cursor"
  23. cursor = Cursor.new(coll, :tailable => true, :order => [['$natural', 1]]).skip(start_count - 1)
  24. loop do
  25. if not cursor.has_next?
  26. puts "Cursor has nothing more!"
  27. if cursor.closed?
  28. puts "Cursor closed"
  29. break
  30. end
  31. sleep 2
  32. next
  33. end
  34. puts "#{Time.now} -> #{cursor.count} #{cursor.next_document['_id']}"
  35. end
  36. end
  37. end
  38.  
  39. insertion.join
  40. tail.join
Add Comment
Please, Sign In to add comment