Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit with new naming.

  • Loading branch information...
commit 1ccad48d1a638c5aeb847068c8a455fd94d9249b 0 parents
@benzenwen benzenwen authored
2  .gitignore
@@ -0,0 +1,2 @@
+.env
+.DS_Store
9 Gemfile
@@ -0,0 +1,9 @@
+source 'http://rubygems.org'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+# Mongo
+gem "mongo"
+gem "bson_ext"
+
15 Gemfile.lock
@@ -0,0 +1,15 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ bson (1.5.2)
+ bson_ext (1.5.2)
+ bson (= 1.5.2)
+ mongo (1.5.2)
+ bson (= 1.5.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bson_ext
+ mongo
2  Procfile
@@ -0,0 +1,2 @@
+worker: ruby writer.rb
+
25 README.md
@@ -0,0 +1,25 @@
+# Tractor Push
+This is a demonstration of a socket.io client that accepts two message streams from a server asynchronously. The left box updates on the arrival of the 'all messages' stream: simple, array, or complex. The right box updates from a message stream of only 'complex' type. The streams are independent but draw from the same source.
+
+# Inserter Ruby
+This is a simple app that writes documents into a MongoLab database. It chooses one of three variations randomly.
+
+# Server
+The other half of the demo is the Node.js server. The server project is at https://github.com/mongolab/tractorpush-server
+
+## Legal stuff
+Copyright 2012 ObjectLabs Corporation.
+
+Code licensed under the Apache License, Version 2.0 (the "Apache
+License"); you may not use this file except in compliance with
+the Apache License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the Apache License is distributed on an "AS IS"
+BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+implied. See the Apache License for the specific language governing
+permissions and limitations under the Apache License.
+
+Non-code content licensed under Creative Commons
+Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) at
+http://creativecommons.org/licenses/by-sa/3.0/
68 writer.rb
@@ -0,0 +1,68 @@
+#
+# Tractor Push: Node.js, socket.io, Ruby, MongoDB tailed cursor demo
+# writer.rb - writes documents into MongoDB database. Randomly
+# chooses from three types to demonstrate schema flexibility of
+# MongoDB as a queue.
+#
+
+#
+# Copyright 2012 ObjectLabs Corp. ObjectLabs is the maker of
+# MongoLab.com a cloud, hosted MongoDb service
+#
+
+# Licensed under the Apache License, Version 2.0 (the "Apache License");
+# you may not use this file except in compliance with the Apache License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the Apache License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the Apache License for the specific language governing permissions and
+
+#
+# writer.rb - inserts sample documents into a MongoLab hosted
+# MongoDB. This is the writing half of the demo. The other half,
+# the tractorpush-server, reads from this database and presents to a
+# browser. For use with Heroku's platform as a service.
+#
+
+#
+# Ben Wen, ObjectLabs
+#
+
+require 'rubygems'
+require 'uri'
+require 'mongo'
+require 'pp'
+
+uristring = ENV['MONGOLAB_URI'] || 'mongodb://localhost/testdatabase'
+debug = ENV['WRITER_DEBUG'] || "false"
+rate = ENV['WRITER_RATE'].to_f || 10.0
+
+
+uri = URI.parse(uristring)
+conn = Mongo::Connection.from_uri(uristring)
+db = conn.db(uri.path.gsub(/^\//, ''))
+
+coll = db.collection('messages')
+
+docs = [{'messagetype' => 'simple', 'ordinal' => 0, 'somename' => 'somevalue'},
+ {'messagetype' => 'array', 'ordinal' => 0, 'somearray' => ['a', 'b', 'c', 'd']},
+ {'messagetype' => 'complex', 'ordinal' =>0, 'subdocument' => {'fname' => 'George', 'lname' => 'Washington', 'subproperty' => 'US-president'}}]
+
+
+count = 500
+print("starting insertion of ", count, " documents into ", uri.scheme, "://", uri.host, uri.path, "\n")
+for i in 1..count
+ doc = docs[rand(3)].dup # MongoDB collection.insert mutates document, editing the _id key; we need a deep dup (copy).
+ doc['time'] = Time.now().to_f * 1000 # Switch to Javascript's convention
+ doc['ordinal'] = i
+ coll.insert(doc, :safe => true)
+ if (debug == "true") then pp (doc) end
+ sleep(1.0/rate)
+end
+
+print("Finished. Inserted ", count, " messages.\n")
+
Please sign in to comment.
Something went wrong with that request. Please try again.