Revision 383477e9 lib/jqueue.py
b/lib/jqueue.py | ||
---|---|---|
689 | 689 |
|
690 | 690 |
|
691 | 691 |
class _JobFileChangesWaiter(object): |
692 |
def __init__(self, filename): |
|
692 |
def __init__(self, filename, _inotify_wm_cls=pyinotify.WatchManager):
|
|
693 | 693 |
"""Initializes this class. |
694 | 694 |
|
695 | 695 |
@type filename: string |
... | ... | |
697 | 697 |
@raises errors.InotifyError: if the notifier cannot be setup |
698 | 698 |
|
699 | 699 |
""" |
700 |
self._wm = pyinotify.WatchManager()
|
|
700 |
self._wm = _inotify_wm_cls()
|
|
701 | 701 |
self._inotify_handler = \ |
702 | 702 |
asyncnotifier.SingleFileEventHandler(self._wm, self._OnInotify, filename) |
703 | 703 |
self._notifier = \ |
... | ... | |
739 | 739 |
|
740 | 740 |
|
741 | 741 |
class _JobChangesWaiter(object): |
742 |
def __init__(self, filename): |
|
742 |
def __init__(self, filename, _waiter_cls=_JobFileChangesWaiter):
|
|
743 | 743 |
"""Initializes this class. |
744 | 744 |
|
745 | 745 |
@type filename: string |
... | ... | |
748 | 748 |
""" |
749 | 749 |
self._filewaiter = None |
750 | 750 |
self._filename = filename |
751 |
self._waiter_cls = _waiter_cls |
|
751 | 752 |
|
752 | 753 |
def Wait(self, timeout): |
753 | 754 |
"""Waits for a job to change. |
... | ... | |
764 | 765 |
# If this point is reached, return immediately and let caller check the job |
765 | 766 |
# file again in case there were changes since the last check. This avoids a |
766 | 767 |
# race condition. |
767 |
self._filewaiter = _JobFileChangesWaiter(self._filename)
|
|
768 |
self._filewaiter = self._waiter_cls(self._filename)
|
|
768 | 769 |
|
769 | 770 |
return True |
770 | 771 |
|
... | ... | |
802 | 803 |
return result |
803 | 804 |
|
804 | 805 |
def __call__(self, filename, job_load_fn, |
805 |
fields, prev_job_info, prev_log_serial, timeout): |
|
806 |
fields, prev_job_info, prev_log_serial, timeout, |
|
807 |
_waiter_cls=_JobChangesWaiter): |
|
806 | 808 |
"""Waits for changes on a job. |
807 | 809 |
|
808 | 810 |
@type filename: string |
... | ... | |
822 | 824 |
counter = itertools.count() |
823 | 825 |
try: |
824 | 826 |
check_fn = _JobChangesChecker(fields, prev_job_info, prev_log_serial) |
825 |
waiter = _JobChangesWaiter(filename)
|
|
827 |
waiter = _waiter_cls(filename)
|
|
826 | 828 |
try: |
827 | 829 |
return utils.Retry(compat.partial(self._CheckForChanges, |
828 | 830 |
counter, job_load_fn, check_fn), |
... | ... | |
830 | 832 |
wait_fn=waiter.Wait) |
831 | 833 |
finally: |
832 | 834 |
waiter.Close() |
833 |
except (errors.InotifyError, errors.JobLost):
|
|
835 |
except errors.JobLost:
|
|
834 | 836 |
return None |
835 | 837 |
except utils.RetryTimeout: |
836 | 838 |
return constants.JOB_NOTCHANGED |
Also available in: Unified diff