Skip to content

Commit d860fe3

Browse files
author
Matt George
committed
Merge remote branch 'aezell/pycon_sprint_docs_rewrite' into updated_docs
2 parents aa933fe + ad584f7 commit d860fe3

File tree

14 files changed

+176
-77
lines changed

14 files changed

+176
-77
lines changed

docs/source/class.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ ResQ Classes
44
==========================================
55

66
.. autoclass:: pyres.ResQ
7-
:members:
8-
7+
:members:
98

109
Job Classes
1110
=================
1211

1312
.. autoclass:: pyres.job.Job
14-
:members:
13+
:members:
1514

1615
Worker Classes
1716
=================
1817

1918
.. autoclass:: pyres.worker.Worker
20-
:members:
19+
:members:
20+
21+
Failure Classes
22+
=================
23+
24+
.. autoclass:: pyres.failure.base.BaseBackend
25+
:members:
26+
27+
.. autoclass:: pyres.failure.RedisBackend
28+
:members:

docs/source/conf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# serve to show the default.
1313

1414
import sys, os
15+
from pyres import __version__
1516

1617
# If extensions (or modules to document with autodoc) are in another directory,
1718
# add these directories to sys.path here. If the directory is relative to the
@@ -37,17 +38,17 @@
3738
master_doc = 'index'
3839

3940
# General information about the project.
40-
project = u'PyRes'
41+
project = u'pyres'
4142
copyright = u'2010, Matt George'
4243

4344
# The version info for the project you're documenting, acts as replacement for
4445
# |version| and |release|, also used in various other places throughout the
4546
# built documents.
4647
#
4748
# The short X.Y version.
48-
version = '0.4.1'
49+
version = __version__
4950
# The full version, including alpha/beta/rc tags.
50-
release = '0.4.1'
51+
release = __version__
5152

5253
# The language for content autogenerated by Sphinx. Refer to documentation
5354
# for a list of supported languages.
@@ -158,7 +159,7 @@
158159
#html_file_suffix = ''
159160

160161
# Output file base name for HTML help builder.
161-
htmlhelp_basename = 'PyResdoc'
162+
htmlhelp_basename = 'pyresdoc'
162163

163164

164165
# -- Options for LaTeX output --------------------------------------------------
@@ -172,7 +173,7 @@
172173
# Grouping the document tree into LaTeX files. List of tuples
173174
# (source start file, target name, title, author, documentclass [howto/manual]).
174175
latex_documents = [
175-
('index', 'PyRes.tex', u'PyRes Documentation',
176+
('index', 'pyres.tex', u'pyres Documentation',
176177
u'Matt George', 'manual'),
177178
]
178179

docs/source/example.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
=========
2-
EXAMPLE
1+
Example
32
=========
43

54
Let's take a real wold example of a blog where comments need to be checked for
6-
spam check. When the comment is saved in the database, we create a job in the
7-
queue with comment data. Let's take a django model in this case.
5+
spam. When the comment is saved in the database, we create a job in the
6+
queue with that comment data. Let's take a django model in this case.
87

98
.. code-block:: python
109
:linenos:
@@ -30,14 +29,14 @@ queue with comment data. Let's take a django model in this case.
3029
comment.spam = False
3130
comment.save()
3231
33-
You can convert your existing class to be compatible with Pyres. All you need
34-
to do is add a @queue@ variable and define a @perform@ method on the class.
32+
You can convert your existing class to be compatible with pyres. All you need
33+
to do is add a :attr:`queue` attribute and define a :meth:`perform` method on the class.
3534

36-
To insert a job into the queue you need to do something like this:::
35+
To insert a job into the queue you need to do something like this::
3736

38-
from pyres import ResQ
39-
r = Resq()
40-
r.enqueue(Spam, 23) # Passing the comment id 23
37+
>>> from pyres import ResQ
38+
>>> r = Resq()
39+
>>> r.enqueue(Spam, 23) # Passing the comment id 23
4140

4241
This puts a job into the queue **Spam**. Now we need to fire off our workers.
4342
In the **scripts** folder there is an executable::

docs/source/index.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
.. PyRes documentation master file, created by
1+
.. pyres documentation master file, created by
22
sphinx-quickstart on Wed Jan 6 15:11:19 2010.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to PyRes's documentation!
6+
Welcome to pyres's documentation!
77
=================================
88

99
Contents:
1010

1111
.. toctree::
12-
:maxdepth: 2
12+
:maxdepth: 2
13+
14+
intro
15+
install
16+
example
17+
class
18+
tests
19+
failures
1320

14-
intro
15-
install
16-
example
17-
class
18-
tests
1921

2022
Indices and tables
2123
==================

docs/source/install.rst

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
Installation
22
===============
33

4-
Requirements:
5-
--------------
6-
simplejson>=2.0.9
7-
itty>=0.6.2
8-
redis>=0.6.0
9-
pystache>=0.1.0
4+
Pyres is most easily installed using pip and can be found on PyPI as pyres_.
105

11-
Make sure you install these requirements before proceeding.
6+
Using ``pip install pyres`` will install the required versions of the above packages/modules.
7+
Those requirements are currently:
128

13-
.. todo:: Need to point to notes on redis installation and get python-redis.
9+
::
1410

15-
16-
To install pyres.::
11+
simplejson==2.0.9
12+
itty==0.6.4
13+
redis==1.34.1
14+
pystache==0.2.0
15+
16+
If you'd rather install from the git repository, that's easy too::
1717

1818
$ git clone git://github.com/binarydud/pyres.git
1919
$ cd pyres
2020
$ python setup.py build
2121
$ python setup.py install
2222

23-
Might need to run as sudo to install.
23+
Of course, you'll need to install the Redis server as well. Below is a simple example, but
24+
please read `Redis's own documentation`_ for more details.
25+
26+
::
27+
28+
$ wget http://redis.googlecode.com/files/redis-1.2.2.tar.gz
29+
$ tar -xvf redis-1.2.2.tar.gz
30+
$ cd redis-1.2.2
31+
$ make
32+
$ ./redis-server
33+
34+
This will install and start a Redis server with the default config running on port 6379.
35+
This default config is good enough for you to run the pyres tests.
36+
37+
.. _pyres: http://pypi.python.org/pypi/pyres/
38+
.. _Redis's own documentation: http://code.google.com/p/redis/wiki/index?tm=6
2439

2540

2641

docs/source/intro.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
Introduction
22
============
33

4-
PyRes is a resque_ clone built in python. Resque is used by Github as their
5-
message queue. Read_ the blog post from github about how they use resque in
6-
production.
4+
Pyres is a resque_ clone built in python. Resque is used by Github as their
5+
message queue. Both use Redis_ as the queue backend and provide a web-based
6+
monitoring application.
77

8-
:synopsis: Any job which takes a little while to run can be put on a message
9-
queue. Read our :doc:`Example </example>` implementation of how a PyRes can be used to spam check comments.
8+
Read_ the blog post from github about how they use resque in production.
9+
10+
:synopsis: Put jobs (which can be any kind of class) on a queue and process them while watching the progress via your browser.
11+
12+
Read our :doc:`example implementation </example>` of how pyres can be used to spam check comments.
1013

1114

1215
.. _resque: http://github.com/defunkt/resque#readme
1316
.. _Read: http://github.com/blog/542-introducing-resque
14-
17+
.. _Redis: http://code.google.com/p/redis/

docs/source/tests.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
Tests
22
=======
33

4-
PyRes comes with a test suite which connects to a local redis server and
5-
creates a couple of *Queues* and *jobs*.
4+
Pyres comes with a test suite which connects to a local Redis server and
5+
creates a couple of *queues* and *jobs*.
66

7-
To run tests make sure you have nose_ installed.::
7+
Make sure you have nose_ installed::
88

9-
$ easy_install nose
10-
$ redis-server [PATH_TO_YOUR_REDIS_CONFIG]
11-
$ nosetests
9+
$ pip install nose
10+
11+
Also make sure your Redis server is running::
12+
13+
$ cd path_to_redis_installation
14+
$ ./redis-server [PATH_TO_YOUR_REDIS_CONFIG]
15+
16+
If you don't give the ``./redis-server`` command the config path, it will use a default config, which should run the tests just fine.
17+
18+
Now, we're ready to run the tests. From the pyres install directory::
19+
20+
$ nosetests
21+
............................................
22+
----------------------------------------------------------------------
23+
Ran 44 tests in 0.901s
24+
25+
OK
1226

1327
Add **-v** flag if you want verbose output.
1428

pyres/__init__.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import pyres.json_parser as json
55

66
def 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

1314
def 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

2729
def 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

4144
class 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

200218
class 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

pyres/extensions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from pyres.exceptions import NoQueueError
1010
from pyres.worker import Worker
11+
1112
class JuniorWorker(Worker):
1213
def work(self, interval=5):
1314
self.startup()

pyres/failure/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from pyres import ResQ
33
import sys, traceback
44
from pyres.failure.redis import RedisBackend
5+
56
_backend = RedisBackend
7+
68
def create(*args, **kwargs):
79
return _backend(*args, **kwargs)
810

0 commit comments

Comments
 (0)