Permalink
Browse files

add MyDrip.invoke

  • Loading branch information...
1 parent 4d64489 commit 6c6341b3a7a8cdc9265cff77e59a9d2d45fe8afb @seki committed May 31, 2011
Showing with 49 additions and 45 deletions.
  1. +4 −2 install.rb
  2. +2 −40 lib/drip.rb
  3. +37 −2 lib/my_drip.rb
  4. +6 −1 sample/drip_tw.rb
View
@@ -2,7 +2,9 @@
require 'fileutils'
dest = RbConfig::CONFIG['sitelibdir']
-src = 'lib/drip.rb'
+src = ['lib/drip.rb', 'lib/my_drip.rb']
-FileUtils.install(src, dest, {:verbose => true, :mode => 0644})
+src.each do |s|
+ FileUtils.install(s, dest, {:verbose => true, :mode => 0644})
+end
View
@@ -319,44 +319,6 @@ def renew
end
if __FILE__ == $0
- require 'fileutils'
-
- class Drip
- def quit
- Thread.new do
- synchronize do |key|
- exit(0)
- end
- end
- end
- end
-
- unless $DEBUG
- exit!(0) if fork
- Process.setsid
- exit!(0) if fork
- end
-
- dir = File.expand_path('~/.drip')
- uri = 'drbunix:' + File.join(dir, 'port')
- ro = DRbObject.new_with_uri(uri)
- begin
- ro.older(nil) #ping
- exit
- rescue
- end
-
- FileUtils.mkdir_p(dir)
- FileUtils.cd(dir)
-
- drip = Drip.new('drip')
- DRb.start_service(uri, drip)
- File.open('pid', 'w') {|fp| fp.puts($$)}
-
- unless $DEBUG
- STDIN.reopen('/dev/null')
- STDOUT.reopen('/dev/null', 'w')
- STDERR.reopen('/dev/null', 'w')
- end
- DRb.thread.join
+ require 'my_drip'
+ MyDrip.invoke
end
View
@@ -2,7 +2,42 @@
MyDrip = DRbObject.new_with_uri('drbunix:' + File.expand_path('~/.drip/port'))
-class Dripper
+def MyDrip.invoke
+ fork do
+ Process.daemon
+
+ require 'drip'
+ require 'fileutils'
+
+ dir = File.expand_path('~/.drip')
+ uri = 'drbunix:' + File.join(dir, 'port')
+ ro = DRbObject.new_with_uri(uri)
+ begin
+ ro.older(nil) #ping
+ exit
+ rescue
+ end
+
+ FileUtils.mkdir_p(dir)
+ FileUtils.cd(dir)
+
+ drip = Drip.new('drip')
+ def drip.quit
+ Thread.new do
+ synchronize do |key|
+ exit(0)
+ end
+ end
+ end
+
+ DRb.start_service(uri, drip)
+ File.open('pid', 'w') {|fp| fp.puts($$)}
+
+ DRb.thread.join
+ end
+end
+
+class DripCursor
def initialize(drip, bufsiz=10, at_least=10)
@drip = drip
@cur = nil
@@ -15,7 +50,7 @@ def now
@cur ? @drip.key_to_time(@cur) : nil
end
- def now=(time)
+ def seek_at(time)
@cur = @drip.time_to_key(time)
end
View
@@ -195,6 +195,11 @@ def write(event)
key = MyDrip.write(event, 'DripDemo Event')
pp [key, event['id_str'], event['text']]
end
+
+ def test
+ r = oauth.post('http://api.twitter.com/1/statuses/update.xml?status=test')
+ pp r.body
+ end
end
if __FILE__ == $0
@@ -209,7 +214,7 @@ def write(event)
end
unless $DEBUG
- # Process.daemon
+ Process.daemon
end
app.drip_stream
end

0 comments on commit 6c6341b

Please sign in to comment.