def handle(self, *args, **options): """ Update digests. """ update_digests()
def handle(self, *args, **options): """ Update digests. """ try: # before starting the digest updating, make sure to lock the storage # so that any other processes with heavy/frequent operations on the # storage don't get in our way lock = Lock('storage') lock.acquire() update_digests() finally: lock.release()
def test_update(self): # define a maximum age of 4 seconds; this means that a resource is # checked for an update if it's older than 2 seconds settings.MAX_DIGEST_AGE = 6 # import resource _result = test_utils.import_xml(TESTFIXTURE_XML) _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object self.assertIsNone(_so.digest_last_checked) # set status to ingested _so.publication_status = INGESTED _so.update_storage() _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object self.assertIsNotNone(_so.digest_last_checked) # remember 'last_checked' and 'modified' to compare against it later _last_checked = _so.digest_last_checked _modified = _so.digest_modified # check if an update is required; this is not the case update_digests() _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object # check that digest was not updated self.assertEquals(_modified, _so.digest_modified) self.assertEquals(_last_checked, _so.digest_last_checked) # wait 3 seconds and check again time.sleep(3) update_digests() _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object # now an update should have happened, but the underlying data has not # changed, so digest_modified is not changed self.assertEquals(_modified, _so.digest_modified) # but it HAS been checked that the digest is still up-to-date self.assertNotEqual(_last_checked, _so.digest_last_checked) _last_checked = _so.digest_last_checked _modified = _so.digest_modified _checksum = _so.digest_checksum # get digest checksum; since not enough time has passed yet, the # digest is not updated _so.get_digest_checksum() self.assertEquals(_last_checked, _so.digest_last_checked) # again, wait 3 seconds so the digest requires another check time.sleep(3) self.assertEquals(_checksum, _so.get_digest_checksum()) self.assertEquals(_modified, _so.digest_modified) self.assertNotEqual(_last_checked, _so.digest_last_checked)
def test_update(self): # define a maximum age of 4 seconds; this means that a resource is # checked for an update if it's older than 2 seconds settings.MAX_DIGEST_AGE = 6 # import resource _result = test_utils.import_xml(TESTFIXTURE_XML) _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object self.assertIsNone(_so.digest_last_checked) # set status to ingested _so.publication_status = INGESTED _so.update_storage() _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object self.assertIsNotNone(_so.digest_last_checked) # remember 'last_checked' and 'modified' to compare against it later _last_checked = _so.digest_last_checked _modified = _so.digest_modified # check if an update is required; this is not the case update_digests() _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object # check that digest was not updated self.assertEquals(_modified, _so.digest_modified) self.assertEquals(_last_checked, _so.digest_last_checked) # wait 3 seconds and check again time.sleep(3) update_digests() _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object # now an update should have happened, but the underlying data has not # changed, so digest_modified is not changed self.assertEquals(_modified, _so.digest_modified) # but it HAS been checked that the digest is still up-to-date self.assertNotEqual(_last_checked, _so.digest_last_checked) _last_checked = _so.digest_last_checked _modified = _so.digest_modified _checksum = _so.digest_checksum # get digest checksum; since not enough time has passed yet, the # digest is not updated _so.get_digest_checksum() self.assertEquals(_last_checked, _so.digest_last_checked) # again, wait 3 seconds so the digest requires another check time.sleep(3) self.assertEquals(_checksum, _so.get_digest_checksum()) self.assertEquals(_modified, _so.digest_modified) self.assertNotEqual(_last_checked, _so.digest_last_checked)
except ImportError: sys.stderr.write("Error: Can't find the file 'settings.py' in the " \ "directory containing %r. It appears you've customized things.\n" \ "You'll have to run django-admin.py, passing it your settings " \ "module.\n(If the file settings.py does indeed exist, it's causing" \ " an ImportError somehow.)\n" % __file__) sys.exit(1) if __name__ == "__main__": os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' PROJECT_HOME = os.path.normpath(os.getcwd() + "/..") sys.path.append(PROJECT_HOME) # Check that SOLR is running, or else all resources will stay at status INTERNAL: from metashare.repository import verify_at_startup verify_at_startup() # may raise Exception, which we don't want to catch. # Disable verbose debug output for the import process... settings.DEBUG = False os.environ['DISABLE_INDEXING_DURING_IMPORT'] = 'True' from metashare.storage.models import update_digests update_digests() from django.core.management import call_command call_command('rebuild_index', interactive=False)