Module: Workling
- Defined in:
- lib/workling/base.rb,
lib/workling.rb,
lib/workling/remote.rb,
lib/workling/discovery.rb,
lib/workling/clients/base.rb,
lib/workling/routing/base.rb,
lib/workling/invokers/base.rb,
lib/workling/return/store/base.rb,
lib/workling/clients/not_client.rb,
lib/workling/clients/sqs_client.rb,
lib/workling/clients/amqp_client.rb,
lib/workling/clients/broker_base.rb,
lib/workling/clients/xmpp_client.rb,
lib/workling/clients/spawn_client.rb,
lib/workling/clients/rude_q_client.rb,
lib/workling/clients/thread_client.rb,
lib/workling/invokers/basic_poller.rb,
lib/workling/return/store/iterator.rb,
lib/workling/routing/static_routing.rb,
lib/workling/invokers/threaded_poller.rb,
lib/workling/clients/not_remote_client.rb,
lib/workling/invokers/looped_subscriber.rb,
lib/workling/clients/memory_queue_client.rb,
lib/workling/invokers/thread_pool_poller.rb,
lib/workling/clients/amqp_exchange_client.rb,
lib/workling/clients/backgroundjob_client.rb,
lib/workling/clients/memcache_queue_client.rb,
lib/workling/invokers/amqp_single_subscriber.rb,
lib/workling/invokers/eventmachine_subscriber.rb,
lib/workling/return/store/memory_return_store.rb,
lib/workling/routing/class_and_method_routing.rb,
lib/workling/return/store/starling_return_store.rb
Overview
Recommended Return Store if you are using the Starling Runner. This
Simply sets and gets values against queues. 'key' is the name of the respective Queue.
Defined Under Namespace
Modules: Clients, Invokers, Remote, Return, Routing Classes: Base, ConfigurationError, Discovery, QueueserverNotFoundError, WorklingConnectionError, WorklingError, WorklingNotFoundError
Constant Summary collapse
- VERSION =
"0.4.9"
- @@load_path =
[ File.(path('app', 'workers')) ]
Class Method Summary collapse
- .clients ⇒ Object
- .config ⇒ Object
- .config_path ⇒ Object
- .env ⇒ Object
-
.find(clazz, method = nil) ⇒ Object
gets the worker instance, given a class.
- .path(*args) ⇒ Object
- .raise_exceptions? ⇒ Boolean
-
.return ⇒ Object
returns Workling::Return::Store.instance.
-
.select_and_build_client ⇒ Object
this will build the client to use for job dispatching and retrieval The look up does the following: 1.
-
.select_and_build_invoker ⇒ Object
this will build the invoker which will run the daemon.
-
.select_and_build_routing ⇒ Object
this will select the routing class.
- .select_client ⇒ Object
-
.select_default_client ⇒ Object
determine the client to use if nothing is specifically set.
Instance Method Summary collapse
Class Method Details
.clients ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/workling.rb', line 76 def self.clients { 'amqp' => Workling::Clients::AmqpClient, 'amqp_exchange' => Workling::Clients::AmqpExchangeClient, 'memcache' => Workling::Clients::MemcacheQueueClient, 'starling' => Workling::Clients::MemcacheQueueClient, 'memory_queue' => Workling::Clients::MemoryQueueClient, 'sqs' => Workling::Clients::SqsClient, 'xmpp' => Workling::Clients::XmppClient, 'backgroundjob' => Workling::Clients::BackgroundjobClient, 'not_remote' => Workling::Clients::NotRemoteClient, 'not' => Workling::Clients::NotClient, 'spawn' => Workling::Clients::SpawnClient, 'thread' => Workling::Clients::ThreadClient, 'rudeq' => Workling::Clients::RudeQClient } end |
.config ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/workling.rb', line 161 def self.config return @@config if defined?(@@config) && @@config return nil unless File.exists?(config_path) @@config ||= YAML.load_file(config_path)[env || 'development'].symbolize_keys @@config[:memcache_options].symbolize_keys! if @@config[:memcache_options] @@config end |
.config_path ⇒ Object
172 173 174 175 |
# File 'lib/workling.rb', line 172 def self.config_path return @@config_path if defined?(@@config_path) && @@config_path @@config_path = File.join(RAILS_ROOT, 'config', 'workling.yml') end |
.env ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/workling.rb', line 46 def self.env @env ||= if defined?(RAILS_ENV) RAILS_ENV.to_s elsif defined?(RACK_ENV) RACK_ENV.to_s end end |
.find(clazz, method = nil) ⇒ Object
gets the worker instance, given a class. the optional method argument will cause an exception to be raised if the worker instance does not respoind to said method.
142 143 144 145 146 147 148 149 150 |
# File 'lib/workling.rb', line 142 def self.find(clazz, method = nil) begin inst = clazz.to_s.camelize.constantize.new rescue NameError raise_not_found(clazz, method) end raise_not_found(clazz, method) if method && !inst.respond_to?(method) inst end |
.path(*args) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/workling.rb', line 38 def self.path(*args) if defined?(RAILS_ROOT) File.join(RAILS_ROOT, *args) else File.join(Dir.pwd, *args) end end |
.raise_exceptions? ⇒ Boolean
187 188 189 |
# File 'lib/workling.rb', line 187 def self.raise_exceptions? @@raise_exceptions end |
.return ⇒ Object
returns Workling::Return::Store.instance.
153 154 155 |
# File 'lib/workling.rb', line 153 def self.return Workling::Return::Store.instance end |
.select_and_build_client ⇒ Object
this will build the client to use for job dispatching and retrieval The look up does the following:
1. if Workling::Remote.client is set explicitly then that client is used
2. if workling.yml (or whatever file is used) contains a client section then that is used
3. otherwise the default client is built using the Workling.select_and_build_default_client method
107 108 109 |
# File 'lib/workling.rb', line 107 def self.select_and_build_client select_client.new end |
.select_and_build_invoker ⇒ Object
this will build the invoker which will run the daemon
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/workling.rb', line 125 def self.select_and_build_invoker invoker_class = { 'basic_poller' => Workling::Invokers::BasicPoller, 'thread_pool_poller' => Workling::Invokers::ThreadPoolPoller, 'threaded_poller' => Workling::Invokers::ThreadedPoller, 'eventmachine_subscriber' => Workling::Invokers::EventmachineSubscriber, 'looped_subscriber' => Workling::Invokers::LoopedSubscriber, 'amqp_single_subscriber' => Workling::Invokers::AmqpSingleSubscriber, }[Workling.config[:invoker]] || Workling::Invokers::BasicPoller invoker_class.new(select_and_build_routing, select_client) end |
.select_and_build_routing ⇒ Object
this will select the routing class
114 115 116 117 118 119 120 |
# File 'lib/workling.rb', line 114 def self.select_and_build_routing routing_class = { 'class_and_method' => Workling::Routing::ClassAndMethodRouting, 'static' => Workling::Routing::StaticRouting }[Workling.config[:routing]] || Workling::Routing::ClassAndMethodRouting routing_class.new end |
.select_client ⇒ Object
94 95 96 97 98 |
# File 'lib/workling.rb', line 94 def self.select_client client_class = clients[Workling.config[:client]] || select_default_client client_class.load client_class end |
.select_default_client ⇒ Object
determine the client to use if nothing is specifically set. workling will try to detect starling, spawn, or bj, in that order. if none of these are found, notremoterunner will be used.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/workling.rb', line 64 def self.select_default_client if env == "test" Workling::Clients::NotRemoteClient elsif Workling::Clients::SpawnClient.installed? Workling::Clients::SpawnClient elsif Workling::Clients::BackgroundjobClient.installed? Workling::Clients::BackgroundjobClient else Workling::Clients::NotRemoteClient end end |
Instance Method Details
#raise_exceptions ⇒ Object
182 183 184 185 |
# File 'lib/workling.rb', line 182 def raise_exceptions return @@raise_exceptions if defined?(@@raise_exceptions) @@raise_exceptions = (RAILS_ENV == "test" || RAILS_ENV == "development") end |