Commit 4d9cd0c0 authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_ingestion: cleanup in invalidation script

parent b79cb2e9
......@@ -4,50 +4,23 @@ from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
kw_dict = {"portal_type": "Data Set",
"validation_state": "Invalidated"}
# data set
for data_set in portal_catalog(**kw_dict):
if not data_set.getReference().endswith("_invalid"):
context.logEntry("Deleted data set found. Invalidating data set '%s' and dependencies." % data_set.getReference())
reference_query = Query(**{'reference': data_set.getReference()+'/%'})
kw_dict = {"portal_type": "Data Stream",
"query": reference_query}
for data_stream in portal_catalog(**kw_dict):
if data_stream.getReference().startswith(data_set.getReference()+'/'):
portal.ERP5Site_invalidateIngestionObjects(data_stream.getReference())
data_set.setReference(data_set.getReference() + "_invalid")
context.logEntry("Data set '%s' invalidated." % data_set.getReference())
# data streams
kw_dict = {"portal_type": "Data Stream",
"validation_state": "Invalidated"}
for data_stream in portal_catalog(**kw_dict):
if not data_stream.getReference().endswith("_invalid"):
context.logEntry("Deleted data stream found: " + data_stream.getReference())
portal.ERP5Site_invalidateIngestionObjects(data_stream.getReference())
# invalidate old (more than 10 min) pending ingestions (e.g. split ingestions that were canceled/interrumped)
# invalidate old (more than 4 min) pending ingestions (e.g. split ingestions that were canceled/interrumped)
from DateTime import DateTime
now = DateTime()
now_minus_max = now - 1.0/24/60*9999
now_minus_10 = now - 1.0/24/60*10
now_minus_4 = now - 1.0/24/60*4
catalog_kw = {'creation_date': {'query': (now_minus_max, now_minus_10), 'range': 'minmax'}, 'simulation_state': 'planned', 'portal_type': 'Data Ingestion'}
catalog_kw = {'creation_date': {'query': (now_minus_max, now_minus_4), 'range': 'minmax'}, 'simulation_state': 'planned', 'portal_type': 'Data Ingestion'}
for data_ingestion in portal_catalog(**catalog_kw):
# search related data ingestions that are not old yet (less than 10 min)
catalog_kw = {'creation_date': {'query': (now_minus_10, DateTime()), 'range': 'minmax'},
catalog_kw = {'creation_date': {'query': (now_minus_4, DateTime()), 'range': 'minmax'},
'simulation_state': 'planned',
'portal_type': 'Data Ingestion',
'reference': data_ingestion.getReference()}
invalidate = True
if len(portal_catalog(**catalog_kw)) > 0:
context.logEntry("Data Ingestion %s is old, but it has related ingestion that are not. So it won't be invalidated yet." % data_ingestion.getId())
context.logEntry("Data Ingestion %s is old but it has related data ingestions that are not, so ingestion is still in course. It won't be invalidated." % data_ingestion.getId())
invalidate = False
if invalidate:
......
......@@ -22,4 +22,4 @@ for document in portal_catalog(**kw_dict):
try:
document.invalidate()
except:
pass # fails if it's already invalidated or if it doens't allow invalidation (e.g. DI)
pass # fails if it's already invalidated, draft or if it doens't allow invalidation (e.g. DI)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment