44import pyres .json_parser as json
55
66def my_import (name ):
7+ """Helper function for walking import calls when searching for classes by string names."""
78 mod = __import__ (name )
89 components = name .split ('.' )
910 for comp in components [1 :]:
1011 mod = getattr (mod , comp )
1112 return mod
1213
1314def safe_str_to_class (s ):
15+ """Helper function to map string class names to module classes."""
1416 lst = s .split ("." )
1517 klass = lst [- 1 ]
1618 mod_list = lst [:- 1 ]
@@ -25,6 +27,7 @@ def safe_str_to_class(s):
2527 return None
2628
2729def str_to_class (s ):
30+ """Alternate helper function to map string class names to module classes."""
2831 lst = s .split ("." )
2932 klass = lst [- 1 ]
3033 mod_list = lst [:- 1 ]
@@ -39,8 +42,22 @@ def str_to_class(s):
3942 return None
4043
4144class ResQ (object ):
42- """ResQ class which defines the Queue object to enqueue jobs into various
43- queues.
45+ """The ResQ class defines the Redis server object to which we will
46+ enqueue jobs into various queues.
47+
48+ The ``__init__`` takes these keyword arguments:
49+
50+ ``server`` -- IP address and port of the Redis server to which you want to connect. Default is `localhost:6379`.
51+
52+ ``password`` -- The password, if required, of your Redis server. Default is "None".
53+
54+ ``timeout`` -- The timeout keyword is in the signature, but is unused. Default is "None".
55+
56+ ``retry_connection`` -- This keyword is in the signature but is deprecated. Default is "True".
57+
58+
59+ Both ``timeout`` and ``retry_connection`` will be removed as the python-redis client
60+ no longer uses them.
4461
4562 Example usage::
4663
@@ -52,8 +69,9 @@ class ResQ(object):
5269
5370 >>>> r.enqueue(SomeClass, args)
5471
55- SomeClass can be any python class with *perform* method and a *queue*
72+ SomeClass can be any python class with a *perform* method and a *queue*
5673 attribute on it.
74+
5775 """
5876 def __init__ (self , server = "localhost:6379" , password = None ,
5977 timeout = None , retry_connection = True ):
@@ -110,9 +128,9 @@ def _set_redis(self, server):
110128 redis = property (_get_redis , _set_redis )
111129
112130 def enqueue (self , klass , * args ):
113- """
114- Enqueue a job into a specific queue. Make sure the class you are passing
131+ """Enqueue a job into a specific queue. Make sure the class you are passing
115132 has **queue** attribute and a **perform** method on it.
133+
116134 """
117135 queue = getattr (klass ,'queue' , None )
118136 #print cls._res
@@ -128,9 +146,9 @@ def queues(self):
128146 return self .redis .smembers ("resque:queues" ) or []
129147
130148 def info (self ):
131- """
132- Returns a dictionary of the current status of the pending jobs,
149+ """Returns a dictionary of the current status of the pending jobs,
133150 processed, no. of queues, no. of workers, no. of failed jobs.
151+
134152 """
135153 pending = 0
136154 for q in self .queues ():
@@ -170,8 +188,8 @@ def remove_queue(self, queue):
170188 del self .redis ['resque:queue:%s' % queue ]
171189
172190 def close (self ):
173- """
174- close the underlying redis connection
191+ """Close the underlying redis connection.
192+
175193 """
176194 self .redis .disconnect ()
177195
@@ -198,8 +216,8 @@ def _enqueue(cls, klass, *args):
198216 #Job.create(queue, klass,*args)
199217
200218class Stat (object ):
201- """
202- A Stat class which shows the current status of the queue.
219+ """A Stat class which shows the current status of the queue.
220+
203221 """
204222 def __init__ (self , name , resq ):
205223 self .name = name
0 commit comments