Переглянути джерело

[docs] Started writing eventloop reference for the Extending guide

Ask Solem 12 роки тому
батько
коміт
28de1bf1aa
1 змінених файлів з 70 додано та 0 видалено
  1. 70 0
      docs/userguide/extending.rst

+ 70 - 0
docs/userguide/extending.rst

@@ -233,3 +233,73 @@ something like this:
 
         def run(self, port=None, debug=False, **kwargs):
             print('Running our command')
+
+
+Worker API
+==========
+
+
+:class:`~celery.worker.Hub` - The workers async event loop.
+-----------------------------------------------------------
+:supported transports: amqp, redis
+
+.. versionadded:: 3.0
+
+The worker uses asynchronous I/O when the amqp or redis broker transports are
+used.  The eventual goal is for all transports to use the eventloop, but that
+will take some time so other transports still use a threading-based solution.
+
+.. method:: hub.add(fd, callback, flags)
+
+    Add callback for fd with custom flags, which can be any combination of
+    :data:`~kombu.utils.eventio.READ`, :data:`~kombu.utils.eventio.WRITE`,
+    and :data:`~kombu.utils.eventio.ERR`, the callback will then be called
+    whenever the condition specified in flags is true (readable,
+    writeable, or error).
+
+    The callback will stay registered until explictly removed using
+    :meth:`hub.remove(fd) <hub.remove>`, or the fd is automatically discarded
+    because it's no longer valid.
+
+    Note that only one callback can be registered for any given fd at a time,
+    so calling ``add`` a second time will remove any callback that
+    was previously registered for that fd.
+
+    ``fd`` may also be a list of file descriptors, in this case the
+    callback will be registered for all of the fds in this list.
+
+    A file descriptor is any file-like object that supports the ``fileno``
+    method, or it can be the file descriptor number (int).
+
+.. method:: hub.add_reader(fd, callback)
+
+    Shortcut to ``hub.add(fd, callback, READ | ERR)``.
+
+.. method:: hub.add_writer(fd, callback)
+
+    Shortcut to ``hub.add(fd, callback, WRITE)``.
+
+.. method:: hub.remove(fd)
+
+    Remove all callbacks for ``fd`` from the loop.
+
+.. method:: hub.update_readers(fd, mapping)
+
+    Shortcut to add callbacks from a map of ``{fd: callback}`` items.
+
+.. method:: hub.update_writers(fd, mapping)
+
+    Shortcut to add callbacks from a map of ``{fd: callback}`` items.
+
+Timer - Scheduling events
+-------------------------
+
+.. method:: timer.apply_after(msecs, callback, args=(), kwargs=(),
+                              priority=0)
+
+
+.. method:: timer.apply_interval(msecs, callback, args=(), kwargs=(),
+                                priority=0)
+
+.. method:: timer.apply_at(eta, callback, args=(), kwargs=(),
+                           priority=0)