def run_with_lock(remove=False): lock = PIDLockFile( getattr( settings, "HYPERKITTY_JOBS_UPDATE_INDEX_LOCKFILE", os.path.join(gettempdir(), "hyperkitty-jobs-update-index.lock"))) try: lock.acquire(timeout=-1) except AlreadyLocked: if check_pid(lock.read_pid()): logger.warning("The job 'update_index' is already running") return else: lock.break_lock() lock.acquire(timeout=-1) except LockFailed as e: logger.warning( "Could not obtain a lock for the 'update_index' " "job (%s)", e) return try: update_index(remove=remove) except Exception as e: logger.exception("Failed to update the fulltext index: %s", e) finally: lock.release()
def test_update_index_one_list(self): self._add_message() self._add_message("msgid2", "*****@*****.**") self.assertEqual(SearchQuerySet().count(), 0) # Update the index for only list2 update_index(listname="*****@*****.**") self.assertEqual(SearchQuerySet().count(), 1)
def test_update_index_with_remove(self): self._add_message() self._add_message("msgid2") self.assertEqual(SearchQuerySet().count(), 0) # Update the index update_index() self.assertEqual(SearchQuerySet().count(), 2) # Delete the second email Email.objects.get(message_id="msgid2").delete() # Update the index with the remove option update_index(remove=True) self.assertEqual(SearchQuerySet().count(), 1)
def execute(self): lock = LockFile(getattr( settings, "HYPERKITTY_JOBS_UPDATE_INDEX_LOCKFILE", os.path.join(gettempdir(), "hyperkitty-jobs-update-index.lock"))) try: lock.acquire(timeout=0) except AlreadyLocked: logger.warning("The job 'update_index' is already running") return except LockFailed as e: logger.warning("Could not obtain a lock for the 'update_index' " "job (%s)", e) return try: update_index() except Exception as e: # pylint: disable-msg=broad-except logger.exception("Failed to update the fulltext index: %s", e) finally: lock.release()
def run_with_lock(remove=False): lock = PIDLockFile(getattr( settings, "HYPERKITTY_JOBS_UPDATE_INDEX_LOCKFILE", os.path.join(gettempdir(), "hyperkitty-jobs-update-index.lock"))) try: lock.acquire(timeout=-1) except AlreadyLocked: if check_pid(lock.read_pid()): logger.warning("The job 'update_index' is already running") return else: lock.break_lock() lock.acquire(timeout=-1) except LockFailed as e: logger.warning("Could not obtain a lock for the 'update_index' " "job (%s)", e) return try: update_index(remove=remove) except Exception as e: # pylint: disable-msg=broad-except logger.exception("Failed to update the fulltext index: %s", e) finally: lock.release()
def test_update_index(self): self._add_message() self.assertEqual(SearchQuerySet().count(), 0) # Update the index update_index() self.assertEqual(SearchQuerySet().count(), 1)
def handle(self, *args, **options): options["verbosity"] = int(options.get("verbosity", "1")) setup_logging(self, options["verbosity"]) update_index(listname=options.get("listname")[0], verbosity=options["verbosity"])