Skip to content

Commit 4017254

Browse files
author
Matt George
committed
added new docs
1 parent af85edf commit 4017254

File tree

12 files changed

+45
-233
lines changed

12 files changed

+45
-233
lines changed

_sources/class.txt

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

66
.. autoclass:: pyres.ResQ
7-
:members:
8-
9-
10-
Job Classes
11-
=================
12-
13-
.. autoclass:: pyres.job.Job
14-
:members:
15-
16-
Worker Classes
17-
=================
18-
19-
.. autoclass:: pyres.worker.Worker
20-
:members:

_sources/example.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
Let's take a real wold example of a blog where comments need to be checked for
66
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.
8-
9-
.. code-block:: python
10-
:linenos:
7+
queue with comment data. Let's take a django model in this case.::
118

129
class Comment(models.Model):
1310
name = Model.CharField()

_sources/install.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Installation
33

44
Requirements:
55
--------------
6-
simplejson>=2.0.9
7-
itty>=0.6.2
8-
redis>=0.6.0
9-
pystache>=0.1.0
6+
simplejson>=2.0.9
7+
itty>=0.6.2
8+
redis>=0.6.0
9+
pystache>=0.1.0
1010

1111
Make sure you install these requirements before proceeding.
1212

_sources/intro.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ message queue. Read_ the blog post from github about how they use resque in
66
production.
77

88
: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.
9+
queue. Read our :doc:`Example </example>` implementation of how a PyRes can be used to spam
10+
check comments.
11+
12+
13+
1014

1115

1216
.. _resque: http://github.com/defunkt/resque#readme

_theme/ADCTheme/README.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ <h3>Navigation</h3>
2828
<li class="right" style="margin-right: 10px">
2929
<a href="../../genindex.html" title="General Index"
3030
accesskey="I">index</a></li>
31-
<li class="right" >
32-
<a href="../../modindex.html" title="Global Module Index"
33-
accesskey="M">modules</a> |</li>
3431
<li><a href="../../index.html">PyRes v0.4.1 documentation</a> &raquo;</li>
3532
</ul>
3633
</div>
@@ -122,9 +119,6 @@ <h3>Navigation</h3>
122119
<li class="right" style="margin-right: 10px">
123120
<a href="../../genindex.html" title="General Index"
124121
>index</a></li>
125-
<li class="right" >
126-
<a href="../../modindex.html" title="Global Module Index"
127-
>modules</a> |</li>
128122
<li><a href="../../index.html">PyRes v0.4.1 documentation</a> &raquo;</li>
129123
</ul>
130124
</div>

class.html

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -62,80 +62,6 @@ <h3>Navigation</h3>
6262
<span class="go"> # Assuming redis is running on default port with no password</span>
6363
</pre></div>
6464
</div>
65-
<p><strong>r</strong> is a resque object on which we can enqueue tasks.:</p>
66-
<div class="highlight-python"><div class="highlight"><pre><span class="go">&gt;&gt;&gt;&gt; r.enqueue(SomeClass, args)</span>
67-
</pre></div>
68-
</div>
69-
<p>SomeClass can be any python class with <em>perform</em> method and a <em>queue</em>
70-
attribute on it.</p>
71-
<dl class="method">
72-
<dt id="pyres.ResQ.enqueue">
73-
<tt class="descname">enqueue</tt><big>(</big><em>klass</em>, <em>*args</em><big>)</big><a class="headerlink" href="#pyres.ResQ.enqueue" title="Permalink to this definition"></a></dt>
74-
<dd>Enqueue a job into a specific queue. Make sure the class you are passing
75-
has <strong>queue</strong> attribute and a <strong>perform</strong> method on it.</dd></dl>
76-
77-
<dl class="method">
78-
<dt id="pyres.ResQ.info">
79-
<tt class="descname">info</tt><big>(</big><big>)</big><a class="headerlink" href="#pyres.ResQ.info" title="Permalink to this definition"></a></dt>
80-
<dd>Returns a dictionary of the current status of the pending jobs,
81-
processed, no. of queues, no. of workers, no. of failed jobs.</dd></dl>
82-
83-
</dd></dl>
84-
85-
</div>
86-
<div class="section" id="job-classes">
87-
<h1>Job Classes<a class="headerlink" href="#job-classes" title="Permalink to this headline"></a></h1>
88-
<dl class="class">
89-
<dt id="pyres.job.Job">
90-
<em class="property">
91-
class </em><tt class="descclassname">pyres.job.</tt><tt class="descname">Job</tt><big>(</big><em>queue</em>, <em>payload</em>, <em>resq</em>, <em>worker=None</em><big>)</big><a class="headerlink" href="#pyres.job.Job" title="Permalink to this definition"></a></dt>
92-
<dd><p>Every job on the ResQ is a <em>Job</em> object which has queue and payload(all the
93-
args data and when its created etc).</p>
94-
<dl class="method">
95-
<dt id="pyres.job.Job.perform">
96-
<tt class="descname">perform</tt><big>(</big><big>)</big><a class="headerlink" href="#pyres.job.Job.perform" title="Permalink to this definition"></a></dt>
97-
<dd>This method converts payload into args and calls the <strong>perform</strong> method
98-
on the payload class.</dd></dl>
99-
100-
<dl class="classmethod">
101-
<dt id="pyres.job.Job.reserve">
102-
<em class="property">
103-
classmethod </em><tt class="descname">reserve</tt><big>(</big><em>queue</em>, <em>res</em>, <em>worker=None</em><big>)</big><a class="headerlink" href="#pyres.job.Job.reserve" title="Permalink to this definition"></a></dt>
104-
<dd>Reserve a job on the queue. In simple marking this job so that other worker
105-
will not pick it up</dd></dl>
106-
107-
</dd></dl>
108-
109-
</div>
110-
<div class="section" id="worker-classes">
111-
<h1>Worker Classes<a class="headerlink" href="#worker-classes" title="Permalink to this headline"></a></h1>
112-
<dl class="class">
113-
<dt id="pyres.worker.Worker">
114-
<em class="property">
115-
class </em><tt class="descclassname">pyres.worker.</tt><tt class="descname">Worker</tt><big>(</big><em>queues=</em><span class="optional">[</span><span class="optional">]</span>, <em>server='localhost:6379'</em>, <em>password=None</em><big>)</big><a class="headerlink" href="#pyres.worker.Worker" title="Permalink to this definition"></a></dt>
116-
<dd><p>Defines a worker. The <em>pyres_worker</em> script instantiates this Worker class and
117-
pass a comma seperate list of queues to listen on.:</p>
118-
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pyres.worker</span> <span class="kn">import</span> <span class="n">Worker</span>
119-
<span class="gp">&gt;&gt;&gt; </span><span class="n">Worker</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="n">queue1</span><span class="p">,</span> <span class="n">queue2</span><span class="p">],</span> <span class="n">server</span><span class="o">=</span><span class="s">&quot;localhost:6379&quot;</span><span class="p">)</span>
120-
</pre></div>
121-
</div>
122-
<dl class="method">
123-
<dt id="pyres.worker.Worker.validate_queues">
124-
<tt class="descname">validate_queues</tt><big>(</big><big>)</big><a class="headerlink" href="#pyres.worker.Worker.validate_queues" title="Permalink to this definition"></a></dt>
125-
<dd>Checks if a worker is given atleast one queue to work on.</dd></dl>
126-
127-
<dl class="method">
128-
<dt id="pyres.worker.Worker.work">
129-
<tt class="descname">work</tt><big>(</big><em>interval=5</em><big>)</big><a class="headerlink" href="#pyres.worker.Worker.work" title="Permalink to this definition"></a></dt>
130-
<dd><p>Invoked by run() method. work() listens on a list of queues and sleeps
131-
for <em>interval</em> time.</p>
132-
<p>default &#8211; 5 secs</p>
133-
<p>Whenever a worker finds a job on the queue it first calls <tt class="docutils literal"><span class="pre">reserve</span></tt> on
134-
that job to make sure other worker won&#8217;t run it, then <em>Forks</em> itself to
135-
work on that job.</p>
136-
<p>Finally process() method actually processes the job.</p>
137-
</dd></dl>
138-
13965
</dd></dl>
14066

14167
</div>
@@ -146,13 +72,6 @@ <h1>Worker Classes<a class="headerlink" href="#worker-classes" title="Permalink
14672
</div>
14773
<div class="sphinxsidebar">
14874
<div class="sphinxsidebarwrapper">
149-
<h3><a href="index.html">Table Of Contents</a></h3>
150-
<ul>
151-
<li><a class="reference external" href="">ResQ Classes</a></li>
152-
<li><a class="reference external" href="#job-classes">Job Classes</a></li>
153-
<li><a class="reference external" href="#worker-classes">Worker Classes</a></li>
154-
</ul>
155-
15675
<h4>Previous topic</h4>
15776
<p class="topless"><a href="example.html"
15877
title="previous chapter">EXAMPLE</a></p>

example.html

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
<script type="text/javascript" src="_static/jquery.js"></script>
2121
<script type="text/javascript" src="_static/doctools.js"></script>
2222
<link rel="top" title="PyRes v0.4.1 documentation" href="index.html" />
23-
<link rel="next" title="ResQ Classes" href="class.html" />
24-
<link rel="prev" title="Installation" href="install.html" />
23+
<link rel="prev" title="Introduction" href="intro.html" />
2524
</head>
2625
<body>
2726
<div class="related">
@@ -31,13 +30,7 @@ <h3>Navigation</h3>
3130
<a href="genindex.html" title="General Index"
3231
accesskey="I">index</a></li>
3332
<li class="right" >
34-
<a href="modindex.html" title="Global Module Index"
35-
accesskey="M">modules</a> |</li>
36-
<li class="right" >
37-
<a href="class.html" title="ResQ Classes"
38-
accesskey="N">next</a> |</li>
39-
<li class="right" >
40-
<a href="install.html" title="Installation"
33+
<a href="intro.html" title="Introduction"
4134
accesskey="P">previous</a> |</li>
4235
<li><a href="index.html">PyRes v0.4.1 documentation</a> &raquo;</li>
4336
</ul>
@@ -52,48 +45,29 @@ <h3>Navigation</h3>
5245
<h1>EXAMPLE<a class="headerlink" href="#example" title="Permalink to this headline"></a></h1>
5346
<p>Let&#8217;s take a real wold example of a blog where comments need to be checked for
5447
spam check. When the comment is saved in the database, we create a job in the
55-
queue with comment data. Let&#8217;s take a django model in this case.</p>
56-
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
57-
2
58-
3
59-
4
60-
5
61-
6
62-
7
63-
8
64-
9
65-
10
66-
11
67-
12
68-
13
69-
14
70-
15
71-
16
72-
17
73-
18
74-
19
75-
20</pre></td><td class="code"><div class="highlight"><pre> <span class="k">class</span> <span class="nc">Comment</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
76-
<span class="n">name</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
77-
<span class="n">email</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>
78-
<span class="n">body</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">TextField</span><span class="p">()</span>
79-
<span class="n">spam</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">BooleanField</span><span class="p">()</span>
80-
<span class="n">queue</span> <span class="o">=</span> <span class="s">&quot;Spam&quot;</span>
48+
queue with comment data. Let&#8217;s take a django model in this case.:</p>
49+
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Comment</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
50+
<span class="n">name</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
51+
<span class="n">email</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>
52+
<span class="n">body</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">TextField</span><span class="p">()</span>
53+
<span class="n">spam</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="n">BooleanField</span><span class="p">()</span>
54+
<span class="n">queue</span> <span class="o">=</span> <span class="s">&quot;Spam&quot;</span>
8155

82-
<span class="nd">@staticmethod</span>
83-
<span class="k">def</span> <span class="nf">perform</span><span class="p">(</span><span class="n">comment_id</span><span class="p">):</span>
84-
<span class="n">comment</span> <span class="o">=</span> <span class="n">Comment</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">comment_id</span><span class="p">)</span>
85-
<span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;comment_author_email&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">email</span><span class="p">,</span>
86-
<span class="s">&quot;comment_content&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">body</span><span class="p">,</span>
87-
<span class="s">&quot;comment_author_name&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
88-
<span class="s">&quot;request_ip&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">author_ip</span><span class="p">}</span>
89-
<span class="n">x</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s">&quot;http://apikey.rest.akismet.com/1.1/comment-check&quot;</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span>
90-
<span class="k">if</span> <span class="n">x</span> <span class="o">==</span> <span class="s">&quot;true&quot;</span><span class="p">:</span>
91-
<span class="n">comment</span><span class="o">.</span><span class="n">spam</span> <span class="o">=</span> <span class="bp">True</span>
92-
<span class="k">else</span><span class="p">:</span>
93-
<span class="n">comment</span><span class="o">.</span><span class="n">spam</span> <span class="o">=</span> <span class="bp">False</span>
94-
<span class="n">comment</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
56+
<span class="nd">@staticmethod</span>
57+
<span class="k">def</span> <span class="nf">perform</span><span class="p">(</span><span class="n">comment_id</span><span class="p">):</span>
58+
<span class="n">comment</span> <span class="o">=</span> <span class="n">Comment</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">comment_id</span><span class="p">)</span>
59+
<span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;comment_author_email&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">email</span><span class="p">,</span>
60+
<span class="s">&quot;comment_content&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">body</span><span class="p">,</span>
61+
<span class="s">&quot;comment_author_name&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
62+
<span class="s">&quot;request_ip&quot;</span><span class="p">:</span> <span class="n">comment</span><span class="o">.</span><span class="n">author_ip</span><span class="p">}</span>
63+
<span class="n">x</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s">&quot;http://apikey.rest.akismet.com/1.1/comment-check&quot;</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span>
64+
<span class="k">if</span> <span class="n">x</span> <span class="o">==</span> <span class="s">&quot;true&quot;</span><span class="p">:</span>
65+
<span class="n">comment</span><span class="o">.</span><span class="n">spam</span> <span class="o">=</span> <span class="bp">True</span>
66+
<span class="k">else</span><span class="p">:</span>
67+
<span class="n">comment</span><span class="o">.</span><span class="n">spam</span> <span class="o">=</span> <span class="bp">False</span>
68+
<span class="n">comment</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
9569
</pre></div>
96-
</td></tr></table></div>
70+
</div>
9771
<p>You can convert your existing class to be compatible with Pyres. All you need
9872
to do is add a &#64;queue&#64; variable and define a &#64;perform&#64; method on the class.</p>
9973
<p>To insert a job into the queue you need to do something like this::</p>
@@ -116,11 +90,8 @@ <h1>EXAMPLE<a class="headerlink" href="#example" title="Permalink to this headli
11690
<div class="sphinxsidebar">
11791
<div class="sphinxsidebarwrapper">
11892
<h4>Previous topic</h4>
119-
<p class="topless"><a href="install.html"
120-
title="previous chapter">Installation</a></p>
121-
<h4>Next topic</h4>
122-
<p class="topless"><a href="class.html"
123-
title="next chapter">ResQ Classes</a></p>
93+
<p class="topless"><a href="intro.html"
94+
title="previous chapter">Introduction</a></p>
12495
<h3>This Page</h3>
12596
<ul class="this-page-menu">
12697
<li><a href="_sources/example.txt"
@@ -150,13 +121,7 @@ <h3>Navigation</h3>
150121
<a href="genindex.html" title="General Index"
151122
>index</a></li>
152123
<li class="right" >
153-
<a href="modindex.html" title="Global Module Index"
154-
>modules</a> |</li>
155-
<li class="right" >
156-
<a href="class.html" title="ResQ Classes"
157-
>next</a> |</li>
158-
<li class="right" >
159-
<a href="install.html" title="Installation"
124+
<a href="intro.html" title="Introduction"
160125
>previous</a> |</li>
161126
<li><a href="index.html">PyRes v0.4.1 documentation</a> &raquo;</li>
162127
</ul>

0 commit comments

Comments
 (0)