Skip to content

Commit

Permalink
worker methods doc
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Aug 8, 2019
1 parent 573d5e1 commit 179d8ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions atasker/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,22 @@ def set_name(self, name):
uuid.uuid4())

def restart(self, *args, **kwargs):
"""
Restart worker, all arguments will be passed to executor function as-is
Args:
wait: if True, wait until worker is stopped
"""
self.stop(wait=kwargs.get('wait'))
self.start(*args, **kwargs)

def is_active(self):
"""
Check if worker is active
Returns:
True if worker is active, otherwise False
"""
return self._active

def is_started(self):
Expand All @@ -94,6 +106,9 @@ def _send_executor_stop_event(self):
self._executor_stop_event.set()

def start(self, *args, **kwargs):
"""
Start worker, all arguments will be passed to executor function as-is
"""
if self._active:
return False
self.start_stop_lock.acquire()
Expand Down Expand Up @@ -182,6 +197,9 @@ def mark_stopped(self):
logger.debug(self.name + ' stopped')

def stop(self, wait=True):
"""
Stop worker
"""
self.start_stop_lock.acquire()
try:
self.before_stop()
Expand Down
7 changes: 7 additions & 0 deletions doc/workers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ All workers support the following initial parameters:

* **poll_delay** worker poll delay (default: task supervisor poll delay)

Methods
-------

.. automodule:: atasker
.. autoclass:: BackgroundWorker
:members:

Overriding parameters at startup
--------------------------------

Expand Down

0 comments on commit 179d8ee

Please sign in to comment.