Commits

Jacob Söndergaard committed 1cc6b09

changed references to job id from "jid" to a mix of "id" and "job_id"

Comments (0)

Files changed (6)

     
     def put():
       client.put("A job to work on", callback=lambda s: show(
-          "Queued a job with jid %d", s, reserve))
+          "Queued a job with id %d", s, reserve))
     
     def reserve():
       client.reserve(callback=lambda s: show(
-          "Reserved job %s", s, lambda: delete(s["jid"])))
+          "Reserved job %s", s, lambda: delete(s["id"])))
     
-    def delete(jid):
-      client.delete(jid, callback=lambda s: show(
-          "Deleted job with jid %d", jid, stop))
+    def delete(job_id):
+      client.delete(job_id, callback=lambda s: show(
+          "Deleted job with id %d", job_id, stop))
 
     client = beanstalkt.Client()
     client.connect(put)
 
 Executing the script (`python demo.py`) with beanstalkd running produces the following output:
 
-    Queued a job with jid 1
-    Reserved job {"body": "A job to work on", "jid": 1}
-    Deleted job with jid 1
+    Queued a job with id 1
+    Reserved job {"body": "A job to work on", "id": 1}
+    Deleted job with id 1
 
-Where `jid` is the job id that beanstalkd has given the job when putting in on the queue.
+Where `id` is the job id that beanstalkd has given the job when putting in on the queue.
 
 The client will attempt to automatically re-connect if the socket connection to beanstalkd is closed unexpectedly. In other cases where an error occur, an exception will be passed to the callback function.
 
 
 The package also includes a command line client for interacting with beanstalkd directly from the commandline. Here is an example usage corresponding to the code example above:
 
-Put a job in the default tube (program returns the jid of the new job):
+Put a job in the default tube (program returns the id of the new job):
 
     > python -m beanstalkt.cmd put "A job to work on"
     1
     > python -m beanstalkt.cmd reserve delete
     {
       "body": "A job to work on", 
-      "jid": 1
+      "id": 1
     }
 
 The documentation is available using the `-h` option, e.g.:
 
 Once a job is reserved for the client, the client has limited time to run (TTR) the job before the job times out. When the job times out, the server will put the job back into the ready queue. Both the TTR and the actual time left can be found in response to the `stats-job` command.
 
-**`delete(jid, callback=None)`**  
+**`delete(job_id, callback=None)`**  
 Removes a job from the server entirely. It is normally used by the client when the job has successfully run to completion. A client can delete jobs that it has `reserved`, `ready` jobs, `delayed` jobs, and jobs that are `buried`.
 
-**`release(jid, priority=DEFAULT_PRIORITY, delay=0, callback=None)`**  
+**`release(job_id, priority=DEFAULT_PRIORITY, delay=0, callback=None)`**  
 Puts a reserved job back into the ready queue (and marks its state as ready) to be run by any client. It is normally used when the job fails because of a transitory error.
 
-**`bury(jid, priority=DEFAULT_PRIORITY, callback=None)`**  
+**`bury(job_id, priority=DEFAULT_PRIORITY, callback=None)`**  
 The `bury` command puts a job into the "buried" state. Buried jobs are put into a FIFO linked list and will not be touched by the server again until a client kicks them with the `kick` command.
 
-**`touch(jid, callback=None)`**  
+**`touch(job_id, callback=None)`**  
 The `touch` command allows a worker to request more time to work on a job. This is useful for jobs that potentially take a long time, but you still want the benefits of a TTR pulling a job away from an unresponsive worker. A worker may periodically tell the server that it’s still alive and processing a job (e.g. it may do this on `DEADLINE_SOON`).
 
 **`watch(name, callback=None)`**  
 
 ## Other commands
 
-**`peek(jid, callback=None)`**  
+**`peek(job_id, callback=None)`**  
 **`peek_ready(callback=None)`**  
 **`peek_delayed(callback=None)`**  
 **`peek_buried(callback=None)`**  
 **`kick(bound=1, callback=None)`**  
 The `kick` command applies only to the currently used tube. It moves jobs into the ready queue. If there are any buried jobs, it will only kick buried jobs.
 
-**`kick_job(jid, callback=None)`**  
+**`kick_job(job_id, callback=None)`**  
 The `kick_job` command is a variant of kick that operates with a single job identified by its job id. If the given job id exists and is in a buried or delayed state, it will be moved to the ready queue of the the same tube where it currently belongs.
 
-**`stats_job(jid, callback=None)`**  
+**`stats_job(job_id, callback=None)`**  
 The `stats_job` command gives statistical information about the specified job if it exists. The callback gets a Python `dict` containing these keys:
 
 * `id` is the job id (mid)

beanstalkt/beanstalkt.py

 limitations under the License.
 """
 
-__version__ = '0.4.0'
+__version__ = '0.5.0'
 
 import socket
 import time
         else:
             # read the body including the terminating two bytes of crlf
             if len(values) == 2:
-                jid, size = int(values[0]), int(values[1])
-                resp.jid = int(jid)
+                job_id, size = int(values[0]), int(values[1])
+                resp.job_id = int(job_id)
             else:
                 size = int(values[0])
             self._stream.read_bytes(size + 2,
         else:
             # don't parse body, it is a job!
             # end the request and callback with results
-            resp.body = {'jid': resp.jid, 'body': data}
+            resp.body = {'id': resp.job_id, 'body': data}
             self._do_callback(cb, resp)
 
     def _parse_yaml(self, data, resp, cb):
         The job is assigned a Time To Run (ttr, in seconds), the mininum is
         1 sec., default is ttr=120 sec.
 
-        Calls back with jid (job id) when job is inserted. If an error occured,
+        Calls back with id when job is inserted. If an error occured,
         the callback gets a Buried or CommandFailed exception. The job is
         buried when either the body is too big, so server ran out of memory,
         or when the server is in draining mode.
         amount of time the client will will hold communication until a job
         becomes available.
 
-        Calls back with a job dict (jid and body). If the request timed out,
+        Calls back with a job dict (keys id and body). If the request timed out,
         the callback gets a TimedOut exception. If a reserved job has deadline
         within the next second, the callback gets a DeadlineSoon exception.
         """
                 'TIMED_OUT'], read_body=True)
         self._interact(request, callback)
 
-    def delete(self, jid, callback=None):
-        """Delete job with given jid.
+    def delete(self, job_id, callback=None):
+        """Delete job with given id.
 
         Calls back when job is deleted. If the job does not exist, or it is not
         neither reserved by the client, ready or buried; the callback gets a
         CommandFailed exception.
         """
-        request = Bunch(cmd='delete {}'.format(jid), ok=['DELETED'],
+        request = Bunch(cmd='delete {}'.format(job_id), ok=['DELETED'],
                 err=['NOT_FOUND'])
         self._interact(request, callback)
 
-    def release(self, jid, priority=DEFAULT_PRIORITY, delay=0, callback=None):
+    def release(self, job_id, priority=DEFAULT_PRIORITY, delay=0,
+            callback=None):
         """Release a reserved job back into the ready queue.
 
         A new priority can be assigned to the job.
         gets a Buried exception. If the job does not exist, or it is not
         reserved by the client, the callback gets a CommandFailed exception.
         """
-        request = Bunch(cmd='release {} {} {}'.format(jid, priority, delay),
+        request = Bunch(cmd='release {} {} {}'.format(job_id, priority, delay),
                 ok=['RELEASED'], err=['BURIED', 'NOT_FOUND'])
         self._interact(request, callback)
 
-    def bury(self, jid, priority=DEFAULT_PRIORITY, callback=None):
-        """Bury job with given jid.
+    def bury(self, job_id, priority=DEFAULT_PRIORITY, callback=None):
+        """Bury job with given id.
 
         A new priority can be assigned to the job.
 
         Calls back when job is burried. If the job does not exist, or it is not
         reserved by the client, the callback gets a CommandFailed exception.
         """
-        request = Bunch(cmd='bury {} {}'.format(jid, priority), ok=['BURIED'],
-                err=['NOT_FOUND'])
+        request = Bunch(cmd='bury {} {}'.format(job_id, priority),
+                ok=['BURIED'], err=['NOT_FOUND'])
         self._interact(request, callback)
 
-    def touch(self, jid, callback=None):
-        """Touch job with given jid.
+    def touch(self, job_id, callback=None):
+        """Touch job with given id.
 
         This is for requesting more time to work on a reserved job before it
         expires.
         Calls back when job is touched. If the job does not exist, or it is not
         reserved by the client, the callback gets a CommandFailed exception.
         """
-        request = Bunch(cmd='touch {}'.format(jid), ok=['TOUCHED'],
+        request = Bunch(cmd='touch {}'.format(job_id), ok=['TOUCHED'],
                 err=['NOT_FOUND'])
         self._interact(request, callback)
 
                 err=['NOT_FOUND'], read_body=True)
         self._interact(request, callback)
 
-    def peek(self, jid, callback=None):
-        """Peek at job with given jid.
+    def peek(self, job_id, callback=None):
+        """Peek at job with given id.
 
-        Calls back with a job dict (jid and body). If no job exists with that
-        jid, the callback gets a CommandFailed exception.
+        Calls back with a job dict (keys id and body). If no job exists with
+        that id, the callback gets a CommandFailed exception.
         """
-        self._peek(' {}'.format(jid), callback)
+        self._peek(' {}'.format(job_id), callback)
 
     def peek_ready(self, callback=None):
         """Peek at next ready job in the current tube.
 
-        Calls back with a job dict (jid and body). If no ready jobs exist,
+        Calls back with a job dict (keys id and body). If no ready jobs exist,
         the callback gets a CommandFailed exception.
         """
         self._peek('-ready', callback)
     def peek_delayed(self, callback=None):
         """Peek at next delayed job in the current tube.
 
-        Calls back with a job dict (jid and body). If no delayed jobs exist,
+        Calls back with a job dict (keys id and body). If no delayed jobs exist,
         the callback gets a CommandFailed exception.
         """
         self._peek('-delayed', callback)
     def peek_buried(self, callback=None):
         """Peek at next buried job in the current tube.
 
-        Calls back with a job dict (jid and body). If no buried jobs exist,
+        Calls back with a job dict (keys id and body). If no buried jobs exist,
         the callback gets a CommandFailed exception.
         """
         self._peek('-buried', callback)
                 read_value=True)
         self._interact(request, callback)
 
-    def kick_job(self, jid, callback=None):
+    def kick_job(self, job_id, callback=None):
         """Kick job with given id into the ready queue.
         (Requires Beanstalkd version >= 1.8)
 
-        Calls back when job is kicked. If no job exists with that jid, or if
+        Calls back when job is kicked. If no job exists with that id, or if
         job is not in a kickable state, the callback gets a CommandFailed
         exception.
         """
-        request = Bunch(cmd='kick-job {}'.format(jid), ok=['KICKED'],
+        request = Bunch(cmd='kick-job {}'.format(job_id), ok=['KICKED'],
                 err=['NOT_FOUND'])
         self._interact(request, callback)
 
-    def stats_job(self, jid, callback=None):
-        """A dict of stats about the job with given jid.
+    def stats_job(self, job_id, callback=None):
+        """A dict of stats about the job with given id.
 
-        If no job exists with that jid, the callback gets a CommandFailed
+        If no job exists with that id, the callback gets a CommandFailed
         exception.
         """
-        request = Bunch(cmd='stats-job {}'.format(jid), ok=['OK'],
+        request = Bunch(cmd='stats-job {}'.format(job_id), ok=['OK'],
                 err=['NOT_FOUND'], read_body=True, parse_yaml=True)
         self._interact(request, callback)
 

beanstalkt/bt_test.py

         # put the job on the queue
         body = 'test job'
         self.btc.put(body, callback=self.stop)
-        jid = self.wait()
-        self.assertIsInstance(jid, int)
+        job_id = self.wait()
+        self.assertIsInstance(job_id, int)
 
         # reserve the job
         self.btc.reserve(callback=self.stop)
         job = self.wait()
         self.assertIsNotNone(job)
-        self.assertEqual(job['jid'], jid)
+        self.assertEqual(job['id'], job_id)
         self.assertEqual(job['body'], body)
 
         # delete the job
-        self.btc.delete(jid, callback=self.stop)
+        self.btc.delete(job_id, callback=self.stop)
         self.wait()
 
     def test_peek_bury_kick(self):
         # put the job on the queue with 1 sec delay
         body = 'test job'
         self.btc.put(body, delay=1, callback=self.stop)
-        jid = self.wait()
+        job_id = self.wait()
 
         def check(job):
             self.assertNotIsInstance(job, Exception)
-            self.assertEqual(job['jid'], jid)
+            self.assertEqual(job['id'], job_id)
             self.assertEqual(job['body'], body)
 
         # peak the next delayed job
         check(self.wait())
 
         # peak the job
-        self.btc.peek(jid, callback=self.stop)
+        self.btc.peek(job_id, callback=self.stop)
         check(self.wait())
 
         # kick the job to ready
-        self.btc.kick_job(jid, callback=self.stop)
+        self.btc.kick_job(job_id, callback=self.stop)
         try:
             self.wait()
         except beanstalkt.UnexpectedResponse as (_, status, __):
         self.btc.reserve(callback=self.stop)
         job = self.wait()
         check(job)
-        self.btc.bury(jid, callback=self.stop)
+        self.btc.bury(job_id, callback=self.stop)
         self.wait()
 
         # peak the next buried job
         self.assertEqual(self.wait(), 1)
 
         # delete the job
-        self.btc.delete(jid, callback=self.stop)
+        self.btc.delete(job_id, callback=self.stop)
         self.wait()
 
 

beanstalkt/cmd.py

 
     # peek
     parser_peek = subparsers.add_parser('peek',
-            help='peek at job with given jid')
-    parser_peek.add_argument('jid', type=int,
-            help='the jid of the job to peek')
+            help='peek at job with given id')
+    parser_peek.add_argument('job_id', type=int,
+            help='the id of the job to peek')
     parser_peek.set_defaults(func=peek)
 
     # peek-ready
 
     # kick_job
     parser_kick_job = subparsers.add_parser('kick-job',
-            help='kick a job with given jid into the ready queue')
-    parser_kick_job.add_argument('jid', type=int,
-            help='the jid of the job to kick')
+            help='kick a job with given id into the ready queue')
+    parser_kick_job.add_argument('job_id', type=int,
+            help='the id of the job to kick')
     parser_kick_job.set_defaults(func=kick_job)
 
     # stats_job
     parser_stats_job = subparsers.add_parser('stats-job',
-            help='get stats for job with given jid')
-    parser_stats_job.add_argument('jid', type=int,
-            help='the jid of the job')
+            help='get stats for job with given id')
+    parser_stats_job.add_argument('job_id', type=int,
+            help='the id of the job')
     parser_stats_job.set_defaults(func=stats_job)
 
     # stats_tube
 
         cb = success(lambda _: None)
         if action == 'delete':
-            client.delete(data['jid'], cb)
+            client.delete(data['id'], cb)
         elif action == 'release':
-            client.release(data['jid'], priority, delay, cb)
+            client.release(data['id'], priority, delay, cb)
         elif action == 'bury':
-            client.bury(data['jid'], priority, cb)
+            client.bury(data['id'], priority, cb)
 
     start(step1)
 
 
-def peek(jid, func):
+def peek(job_id, func):
     def step2(data):
         print json.dumps(data, indent=2)
-    start(lambda: client.peek(jid, success(step2)))
+    start(lambda: client.peek(job_id, success(step2)))
 
 
 def peek_ready(use, func):
     def step2(data):
         print json.dumps(data, indent=2)
     start(lambda: client.use(use, step1))
-    
+
 
 def peek_buried(use, func):
     def step1(_):
     start(lambda: client.use(use, step1))
 
 
-def kick_job(jid, func):
-    start(lambda: client.kick_job(jid, success(lambda _: None)))
+def kick_job(job_id, func):
+    start(lambda: client.kick_job(job_id, success(lambda _: None)))
 
 
-def stats_job(jid, func):
+def stats_job(job_id, func):
     def step2(data):
         print json.dumps(data, indent=2)
-    start(lambda: client.stats_job(jid, success(step2)))
+    start(lambda: client.stats_job(job_id, success(step2)))
 
 
 def stats_tube(name, func):

beanstalkt/demo.py

 
 def put():
   client.put("A job to work on", callback=lambda s: show(
-      "Queued a job with jid %d", s, reserve))
+      "Queued a job with id %d", s, reserve))
 
 def reserve():
   client.reserve(callback=lambda s: show(
-      "Reserved job %s", s, lambda: delete(s["jid"])))
+      "Reserved job %s", s, lambda: delete(s["id"])))
 
-def delete(jid):
-  client.delete(jid, callback=lambda s: show(
-      "Deleted job with jid %d", jid, stop))
+def delete(job_id):
+  client.delete(job_id, callback=lambda s: show(
+      "Deleted job with id %d", job_id, stop))
 
 client = beanstalkt.Client()
 client.connect(put)
 from setuptools import setup
 
 setup(name='beanstalkt',
-      version='0.4.0',
+      version='0.5.0',
       description='An async beanstalkd client for Tornado',
       author='Jacob Sondergaard',
       author_email='jacob@nephics.com',