Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 65 lines (45 sloc) 1.717 kB
5c2f8bb @frommww added files, renamed directories
frommww authored
1 #
f6ba87c @frommww Moved SimpleWorker, MongoHQ, and IndexTank keys to a config.yml file …
frommww authored
2 # Sample worker that connects to MongoDB and iterates through a Mongo collection
3 # and puts all of the items into IndexTank for full text awesomeness searching.
6291f2d @treeder Added mongo to indextank example.
treeder authored
4
f098dfd renamed SimpleWorker to IronWorker
rkononov authored
5 require 'iron_worker'
6291f2d @treeder Added mongo to indextank example.
treeder authored
6
f098dfd renamed SimpleWorker to IronWorker
rkononov authored
7 class MongoToIndextankWorker < IronWorker::Base
6291f2d @treeder Added mongo to indextank example.
treeder authored
8
72edea0 @treeder Moved mongo database name to config file.
treeder authored
9 merge_gem 'faraday-stack', :require=>'faraday_stack'
6291f2d @treeder Added mongo to indextank example.
treeder authored
10 merge_gem 'indextank'
e38b067 fixed param names,options,description
rkononov authored
11 merge_gem 'mongoid'
5c2f8bb @frommww added files, renamed directories
frommww authored
12
6291f2d @treeder Added mongo to indextank example.
treeder authored
13 merge 'person'
14
f6ba87c @frommww Moved SimpleWorker, MongoHQ, and IndexTank keys to a config.yml file …
frommww authored
15 # These values are passed in to make it easy to run the example. Some values (such
16 # as index) could be placed in initialize() or directly inline to simplify things
5157b80 @treeder Fixed up the indextank worker.
treeder authored
17 attr_accessor :mongo_host, :mongo_port, :mongo_username, :mongo_password,
18 :mongo_db_name,
f6ba87c @frommww Moved SimpleWorker, MongoHQ, and IndexTank keys to a config.yml file …
frommww authored
19 :indextank_url, :indextank_index
6291f2d @treeder Added mongo to indextank example.
treeder authored
20
21
22 def run
f6ba87c @frommww Moved SimpleWorker, MongoHQ, and IndexTank keys to a config.yml file …
frommww authored
23 init_mongodb
6291f2d @treeder Added mongo to indextank example.
treeder authored
24 init_indextank
25
26 log "saving person..."
27 person = Person.new(:first_name => "Ludwig", :last_name => "Beethoven the #{rand(100)}")
28 person.save!
29 log person.inspect
30
31 sleep 1
32
f6ba87c @frommww Moved SimpleWorker, MongoHQ, and IndexTank keys to a config.yml file …
frommww authored
33 @index = @indextank.indexes(indextank_index)
6291f2d @treeder Added mongo to indextank example.
treeder authored
34
35 log "querying persons..."
36 persons = Person.find(:all, :conditions=>{:first_name=>"Ludwig"})
37 persons.each do |p|
38 log "indexing #{p.first_name} #{p.last_name} #{p.id}"
39 log p.inspect
40 doc_id = "person_#{p.id}"
41 log doc_id
42 @index.document(doc_id).add({:text=>"#{p.first_name} #{p.last_name}"})
43
44 end
45
46
47 end
48
49
f6ba87c @frommww Moved SimpleWorker, MongoHQ, and IndexTank keys to a config.yml file …
frommww authored
50 # Configures the MongoHQ settings using the Mongoid gem.
51 def init_mongodb
6291f2d @treeder Added mongo to indextank example.
treeder authored
52 Mongoid.configure do |config|
5157b80 @treeder Fixed up the indextank worker.
treeder authored
53 config.database = Mongo::Connection.new(mongo_host, mongo_port).db(mongo_db_name)
6291f2d @treeder Added mongo to indextank example.
treeder authored
54 config.database.authenticate(mongo_username, mongo_password)
55 config.persist_in_safe_mode = false
56 end
57 end
58
59
60 def init_indextank
61 @indextank = IndexTank::Client.new(indextank_url)
62 end
63
64 end
Something went wrong with that request. Please try again.