

@flow.StateHandler()
def Start(self):
    hunts_ttl = config_lib.CONFIG['DataRetention.hunts_ttl']
    if (not hunts_ttl):
        self.Log('TTL not set - nothing to do...')
        return
    exception_label = config_lib.CONFIG['DataRetention.hunts_ttl_exception_label']
    hunts_root = aff4.FACTORY.Open('aff4:/hunts', token=self.token)
    hunts_urns = list(hunts_root.ListChildren())
    deadline = (rdfvalue.RDFDatetime().Now() - hunts_ttl)
    hunts = aff4.FACTORY.MultiOpen(hunts_urns, aff4_type='GRRHunt', token=self.token)
    for hunt in hunts:
        if (exception_label in hunt.GetLabelsNames()):
            continue
        runner = hunt.GetRunner()
        if (runner.context.expires < deadline):
            aff4.FACTORY.Delete(hunt.urn, token=self.token)
            self.HeartBeat()

dataset/ETHPy150Open google/grr/grr/lib/flows/cron/data_retention.py CleanHunts.Start/original