-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Travis Reeder
committed
Jun 18, 2011
1 parent
4f41c21
commit 9c9b694
Showing
13 changed files
with
573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require_relative 'simple_worker_unit_test_base' | ||
require 'active_support/core_ext' | ||
|
||
# bumpasdf | ||
class BasicTests < SimpleWorkerUnitTestBase | ||
|
||
attr_accessor :config | ||
merge_worker 'one_line_worker', 'OneLineWorker' | ||
|
||
def test_for_truth | ||
assert true | ||
end | ||
|
||
def test_fail | ||
assert false, "dang" | ||
end | ||
|
||
def test_exception | ||
raise "dang exception" | ||
end | ||
|
||
def test_queue | ||
worker = OneLineWorker.new | ||
worker.queue | ||
status = worker.wait_until_complete | ||
log status | ||
assert status['status'] == 'complete' | ||
log worker.get_log | ||
|
||
end | ||
|
||
def test_schedule | ||
tr = OneLineWorker.new | ||
start_date = 15.seconds.from_now | ||
response_hash = tr.schedule(:start_at => start_date, :end_at=>start_date + 1.minutes, :priority=>2) | ||
puts 'response_hash=' + response_hash.inspect | ||
assert response_hash, "Couldn't get response" | ||
if response_hash | ||
assert response_hash["schedule_id"], "Wrong response code" | ||
status = wait_for_task(:schedule_id=>response_hash["schedule_id"]) | ||
assert status, "Scheduled task wasn't executed" | ||
assert status["status"] == "complete", "wrong task status" | ||
tasks = SimpleWorker.service.get_schedules.collect { |schedule| schedule["schedule_id"] } | ||
assert tasks.include?(response_hash["schedule_id"]), "Response should contains schedule id" | ||
end | ||
end | ||
|
||
|
||
def wait_for_task(params={}) | ||
tries = 0 | ||
status = nil | ||
sleep 1 | ||
while tries < 60 | ||
status = status_for(params) | ||
puts 'status=' + status.inspect + ' for ' + (params.inspect) | ||
if status["status"] == "complete" || status["status"] == "error" | ||
break | ||
end | ||
sleep 2 | ||
end | ||
status | ||
end | ||
|
||
def status_for(ob) | ||
if ob.is_a?(Hash) | ||
ob[:schedule_id] ? SimpleWorker.service.schedule_status(ob[:schedule_id]) : SimpleWorker.service.status(ob[:task_id]) | ||
else | ||
ob.status | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require_relative 'simple_worker_unit_test_base' | ||
|
||
# bump.. | ||
class DbTests < SimpleWorkerUnitTestBase | ||
|
||
merge_worker 'mysql_worker', "MysqlWorker" | ||
merge_worker 'mysql2_worker', "Mysql2Worker" | ||
merge_worker 'mongo_worker', "MongoWorker" | ||
|
||
|
||
def test_mysql | ||
|
||
mysql_worker = MysqlWorker.new | ||
mysql_worker.config = @config | ||
mysql_worker.queue | ||
|
||
status = mysql_worker.wait_until_complete | ||
log status | ||
assert status['status'] == 'complete' | ||
log "log=" + mysql_worker.get_log.to_s | ||
|
||
end | ||
|
||
def test_mysql2 | ||
|
||
mysql_worker = Mysql2Worker.new | ||
mysql_worker.config = @config | ||
mysql_worker.queue | ||
|
||
status = mysql_worker.wait_until_complete | ||
log status | ||
assert status['status'] == 'complete' | ||
log "log=" + mysql_worker.get_log.to_s | ||
|
||
end | ||
|
||
def test_mongoid | ||
|
||
mw = MongoWorker.new | ||
mw.config = @config | ||
mw.queue | ||
status = mw.wait_until_complete | ||
log status | ||
assert status['status'] == 'complete' | ||
log mw.get_log | ||
|
||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'simple_worker' | ||
require 'yaml' | ||
require_relative 'db_tests' | ||
require_relative 'my_suite_worker' | ||
|
||
@config = YAML.load_file('config.yml') | ||
p @config | ||
|
||
SimpleWorker.configure do |config| | ||
config.access_key = @config["sw_access_key"] | ||
config.secret_key = @config["sw_secret_key"] | ||
end | ||
|
||
#test = DbTest.new(@config) | ||
#test.run_local | ||
|
||
suite_worker = MySuiteWorker.new | ||
suite_worker.config = @config | ||
suite_worker.add('basic_tests', 'BasicTests', @config) | ||
suite_worker.add('db_tests', 'DbTests', @config) | ||
suite_worker.setup | ||
suite_worker.queue | ||
status = suite_worker.wait_until_complete | ||
p status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Sample worker that connects to MongoDB and performs some operations. | ||
|
||
require 'simple_worker' | ||
require 'mongoid' | ||
|
||
class MongoWorker < SimpleWorker::Base | ||
|
||
attr_accessor :config | ||
|
||
merge 'person' | ||
|
||
def run | ||
init_mongodb | ||
|
||
log "saving person..." | ||
person = Person.new(:first_name => "Ludwig", :last_name => "Beethoven the #{rand(100)}") | ||
person.save! | ||
log person.inspect | ||
|
||
sleep 2 | ||
|
||
log "querying persons..." | ||
|
||
persons = Person.find(:all, :conditions=>{:first_name=>"Ludwig"}) | ||
persons.each do |p| | ||
log "found #{p.first_name} #{p.last_name}" | ||
end | ||
|
||
|
||
end | ||
|
||
# Configures settings for MongoDB. Values for mongo_host and mongo_port are passed in | ||
# to make the example easy to understand. Could be placed directly inline to streamline. | ||
def init_mongodb | ||
mconfig = @config['mongo'] | ||
mongo_db_name = mconfig["mongo_db_name"] | ||
mongo_host = mconfig["mongo_host"] | ||
mongo_port = mconfig["mongo_port"] | ||
mongo_username = mconfig['mongo_username'] | ||
mongo_password = mconfig['mongo_password'] | ||
|
||
Mongoid.configure do |config| | ||
config.database = Mongo::Connection.new(mongo_host, mongo_port).db(mongo_db_name) | ||
config.database.authenticate(mongo_username, mongo_password) | ||
# config.slaves = [ | ||
# Mongo::Connection.new(host, 27018, :slave_ok => true).db(name) | ||
# ] | ||
config.persist_in_safe_mode = false | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require_relative 'suite_worker' | ||
|
||
# bump asdf | ||
|
||
class MySuiteWorker < SuiteWorker | ||
|
||
attr_accessor :config | ||
|
||
merge_gem 'hipchat-api' | ||
|
||
def on_complete | ||
|
||
log 'POSTING TO HIPCHAT!' | ||
|
||
client = HipChat::API.new(config['hipchat']['api_key']) | ||
# puts client.rooms_list | ||
notify_users = false | ||
msg = suite_results_output(:format=>'html') | ||
if num_failed == 0 | ||
msg = "LBJ? - We're stylin'!<br/>" + msg | ||
end | ||
log "POSTED: " + client.rooms_message(config['hipchat']['room_name'], 'UnitTestWorker', msg, notify_users).body | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# this one uses the mysql2 gem as it has separate issues from mysql gem. One is that it doesn't work with rails 3.0.x! | ||
|
||
require 'mysql2' | ||
require 'active_record' | ||
|
||
class Mysql2Worker < SimpleWorker::Base | ||
|
||
attr_accessor :config | ||
|
||
def connect(config) | ||
ActiveRecord::Base.establish_connection(config['mysql'].merge!(:adapter=>'mysql2')) | ||
end | ||
|
||
merge "photo" | ||
|
||
def run | ||
|
||
connect(config) | ||
|
||
photo = Photo.create!(:name=>"hi", :url=>"http://www.whatever.com") | ||
photo = Photo.first | ||
log "first photo=" + photo.inspect | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'mysql' | ||
require 'active_record' | ||
|
||
class MysqlWorker < SimpleWorker::Base | ||
|
||
attr_accessor :config | ||
|
||
def connect(config) | ||
ActiveRecord::Base.establish_connection(config['mysql'].merge!(:adapter=>'mysql')) | ||
end | ||
|
||
merge "photo" | ||
|
||
def run | ||
|
||
connect(config) | ||
|
||
photo = Photo.create!(:name=>"hi", :url=>"http://www.whatever.com") | ||
photo = Photo.first | ||
log "first photo=" + photo.inspect | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'simple_worker' | ||
|
||
# bump adsf | ||
class OneLineWorker < SimpleWorker::Base | ||
|
||
def run | ||
log Time.now | ||
log "hello" | ||
log Time.now | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'mongoid' | ||
|
||
class Person | ||
include Mongoid::Document | ||
field :first_name | ||
field :middle_initial | ||
field :last_name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Photo < ActiveRecord::Base | ||
|
||
end |
Oops, something went wrong.