Pārlūkot izejas kodu

Added a deubbing task: task.ping(), to see if the system is responding. (it
should probably have a timeout of some sorts, so it's for debugging only, not
for use in production)

Ask Solem 16 gadi atpakaļ
vecāks
revīzija
21ad451aa9
1 mainītis faili ar 20 papildinājumiem un 0 dzēšanām
  1. 20 0
      celery/task.py

+ 20 - 0
celery/task.py

@@ -578,3 +578,23 @@ class DeleteExpiredTaskMetaTask(PeriodicTask):
 tasks.register(DeleteExpiredTaskMetaTask)
 
 
+class PingTask(Task):
+    """The task used by :func:`ping`."""
+    name = "celery.ping"
+
+    def run(self, **kwargs):
+        """:returns: the string ``"pong"``."""
+        return "pong"
+tasks.register(PingTask)
+
+
+def ping():
+    """Test if the server is alive.
+
+    Example:
+
+        >>> from celery.task import ping
+        >>> ping()
+        'pong'
+    """
+    return PingTask.apply_async().get()