Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pkg
.DS_Store
*.*.swp
.idea
test.log
test.log
._*
5 changes: 5 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# *talbright/workling Fork Notes*

* Fixed compatibility to work with Rails 3.1
* Fixed code so that it will load without needing to install unwanted gems if you aren't going to use them (AWS for example)

# *digitalhobbit/workling Fork Notes*

*This particular Workling fork provides an SQS Client. See instructions below.*
Expand Down
19 changes: 10 additions & 9 deletions lib/workling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def require_in_tree(name)
require 'active_support/inflector'
require 'active_support/core_ext/hash/keys'

class Hash #:nodoc:
include ActiveSupport::CoreExtensions::Hash::Keys
end
# class Hash #:nodoc:
# include ActiveSupport::CoreExtensions::Hash::Keys
# end

require 'yaml'

Expand All @@ -36,16 +36,16 @@ def initialize
end

def self.path(*args)
if defined?(RAILS_ROOT)
File.join(RAILS_ROOT, *args)
if defined?(Rails.root)
File.join(Rails.root, *args)
else
File.join(Dir.pwd, *args)
end
end

def self.env
@env ||= if defined?(RAILS_ENV)
RAILS_ENV.to_s
@env ||= if defined?(Rails.env)
Rails.env.to_s
elsif defined?(RACK_ENV)
RACK_ENV.to_s
end
Expand Down Expand Up @@ -95,6 +95,7 @@ def self.clients
def self.select_client
client_class = clients[Workling.config[:client]] || select_default_client
client_class.load
Rails.logger.debug { "workling: using client class #{client_class}" }
client_class
end

Expand Down Expand Up @@ -172,7 +173,7 @@ def self.config
mattr_writer :config_path
def self.config_path
return @@config_path if defined?(@@config_path) && @@config_path
@@config_path = File.join(RAILS_ROOT, 'config', 'workling.yml')
@@config_path = File.join(Rails.root, 'config', 'workling.yml')
end

#
Expand All @@ -182,7 +183,7 @@ def self.config_path
mattr_writer :raise_exceptions
def raise_exceptions
return @@raise_exceptions if defined?(@@raise_exceptions)
@@raise_exceptions = (RAILS_ENV == "test" || RAILS_ENV == "development")
@@raise_exceptions = (Rails.env == "test" || Rails.env == "development")
end

def self.raise_exceptions?
Expand Down
2 changes: 1 addition & 1 deletion lib/workling/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Base

cattr_writer :logger
def self.logger
@@logger ||= defined?(RAILS_DEFAULT_LOGGER) ? ::RAILS_DEFAULT_LOGGER : Logger.new($stdout)
@@logger ||= defined?(Rails.logger) ? Rails.logger : Logger.new($stdout)
end

def logger
Expand Down
2 changes: 1 addition & 1 deletion lib/workling/clients/spawn_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.installed?
cattr_writer :options
def self.options
# use thread for development and test modes. easier to hunt down exceptions that way.
@@options ||= { :method => (RAILS_ENV == "test" || RAILS_ENV == "development" ? :fork : :thread) }
@@options ||= { :method => (Rails.env == "test" || Rails.env == "development" ? :fork : :thread) }
end

include Spawn if installed?
Expand Down
12 changes: 9 additions & 3 deletions lib/workling/clients/sqs_client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'json'
require 'right_aws'

#
# An SQS client
#
Expand Down Expand Up @@ -28,6 +25,15 @@ module Workling
module Clients
class SqsClient < Workling::Clients::BrokerBase

def self.load
begin
require 'json'
require 'right_aws'
rescue Exception => e
Workling::Base.logger.info "WORKLING: couldn't find AWS client. Install: \"gem install right_aws\". "
end
end

unless defined?(AWS_MAX_QUEUE_NAME)
AWS_MAX_QUEUE_NAME = 80

Expand Down
10 changes: 8 additions & 2 deletions lib/workling/invokers/amqp_single_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require 'eventmachine'

#
# TODO - Subscribes a single worker to a single queue
#
module Workling
module Invokers
class AmqpSingleSubscriber < Workling::Invokers::Base

def self.load
begin
require 'eventmachine'
rescue Exception => e
Workling::Base.logger.info "WORKLING: couldn't find eventmachine. Install: \"gem install eventmachine\". "
end
end

def initialize(routing, client_class)
super
end
Expand Down
9 changes: 8 additions & 1 deletion lib/workling/invokers/eventmachine_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'eventmachine'

#
# Subscribes the workers to the correct queues.
Expand All @@ -7,6 +6,14 @@ module Workling
module Invokers
class EventmachineSubscriber < Workling::Invokers::Base

def self.load
begin
require 'eventmachine'
rescue Exception => e
Workling::Base.logger.info "WORKLING: couldn't find eventmachine. Install: \"gem install eventmachine\". "
end
end

def initialize(routing, client_class)
super
end
Expand Down