Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MYSQL CLIENT:
- create database rbtest;
- create user 'rbtest'@'%' identified by 'pdpmetgaic';
- grant all on rbtest.* to 'rbtest'@'%';
- flush privileges;
- use rbtest;
- CREATE TABLE `prot` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `sound` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
- LOCK TABLES `prot` WRITE;
- INSERT INTO `prot` VALUES (1,'prrrrrrrr','renza'),(2,'pfffff','loffa'),(3,'prot!','peto'),(4,'BBRAAAMMPP','tuono'),(5,'pruttt','scureggia');
- UNLOCK TABLES;
- -----
- airbot.rb
- -----
- #!/usr/bin/ruby
- puts 'loading libraries...'
- require 'rubygems'
- require 'active_record'
- class MyDB < ::ActiveRecord::Base
- DB_TYPE = 'mysql2'
- DB_HOST = 'MYHOSTNAMEHERE <----'
- DB_USERNAME = 'rbtest'
- DB_PASSWORD = 'pdpmetgaic'
- DB_SCHEMA = 'rbtest'
- establish_connection(:adapter => DB_TYPE, :host => DB_HOST, :username => DB_USERNAME, :password => DB_PASSWORD, :database => DB_SCHEMA, :reconnect => true, :pool => 5, :wait_timeout => 5)
- set_table_name 'prot'
- end
- puts 'starting!'
- i = 0
- loop do
- i += 1
- Thread.new do
- begin
- t = i
- s = Time.now
- a = MyDB.find((rand * 5).to_i + 1)
- puts t.to_s + ': ' + a.sound + ' [' + ( "%.2f" % (Time.now - s) ) + 's]'
- rescue Exception => exc
- puts "KABOOM! (#{exc.inspect})"
- end
- end
- sleep 1
- end
- -----
- Output:
- -----
- loading libraries...
- starting!
- 1: prot! [0.16s]
- 2: prrrrrrrr [0.00s]
- 3: BBRAAAMMPP [0.00s]
- 4: pruttt [0.00s]
- 5: pfffff [0.00s]
- KABOOM! (#<ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it.>)
- 9: BBRAAAMMPP [2.01s]
- 11: prot! [0.01s]
- 7: prrrrrrrr [4.02s]
- 6: prrrrrrrr [5.02s]
- 8: prot! [3.02s]
- 14: BBRAAAMMPP [3.01s]
- 12: pfffff [5.01s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement