nodes: 0, module; 1, function_definition; 2, function_name:retain_identities; 3, parameters; 4, block; 5, identifier:retention_time; 6, identifier:es_enrichment_url; 7, identifier:sortinghat_db; 8, identifier:data_source; 9, identifier:active_data_sources; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, comment:# delete the unique identities which have not been seen after `before_date`; 15, expression_statement; 16, comment:# delete the unique identities for a given data source which are not in the IDENTITIES_INDEX; 17, expression_statement; 18, comment:"""Select the unique identities not seen before `retention_time` and
      delete them from SortingHat. Furthermore, it deletes also the orphan unique identities,
      those ones stored in SortingHat but not in IDENTITIES_INDEX.
  
      :param retention_time: maximum number of minutes wrt the current date to retain the identities
      :param es_enrichment_url: URL of the ElasticSearch where the enriched data is stored
      :param sortinghat_db: instance of the SortingHat database
      :param data_source: target data source (e.g., git, github, slack)
      :param active_data_sources: list of active data sources
      """; 19, assignment; 20, assignment; 21, assignment; 22, call; 23, call; 24, identifier:before_date; 25, call; 26, identifier:before_date_str; 27, call; 28, identifier:es; 29, call; 30, identifier:delete_inactive_unique_identities; 31, argument_list; 32, identifier:delete_orphan_unique_identities; 33, argument_list; 34, identifier:get_diff_current_date; 35, argument_list; 36, attribute; 37, argument_list; 38, identifier:Elasticsearch; 39, argument_list; 40, identifier:es; 41, identifier:sortinghat_db; 42, identifier:before_date_str; 43, identifier:es; 44, identifier:sortinghat_db; 45, identifier:data_source; 46, identifier:active_data_sources; 47, keyword_argument; 48, identifier:before_date; 49, identifier:isoformat; 50, list; 51, keyword_argument; 52, keyword_argument; 53, keyword_argument; 54, keyword_argument; 55, identifier:minutes; 56, identifier:retention_time; 57, identifier:es_enrichment_url; 58, identifier:timeout; 59, integer:120; 60, identifier:max_retries; 61, integer:20; 62, identifier:retry_on_timeout; 63, True; 64, identifier:verify_certs; 65, False
code: def retain_identities(retention_time, es_enrichment_url, sortinghat_db, data_source, active_data_sources):
      """Select the unique identities not seen before `retention_time` and
      delete them from SortingHat. Furthermore, it deletes also the orphan unique identities,
      those ones stored in SortingHat but not in IDENTITIES_INDEX.
  
      :param retention_time: maximum number of minutes wrt the current date to retain the identities
      :param es_enrichment_url: URL of the ElasticSearch where the enriched data is stored
      :param sortinghat_db: instance of the SortingHat database
      :param data_source: target data source (e.g., git, github, slack)
      :param active_data_sources: list of active data sources
      """
      before_date = get_diff_current_date(minutes=retention_time)
      before_date_str = before_date.isoformat()
  
      es = Elasticsearch([es_enrichment_url], timeout=120, max_retries=20, retry_on_timeout=True, verify_certs=False)
  
      # delete the unique identities which have not been seen after `before_date`
      delete_inactive_unique_identities(es, sortinghat_db, before_date_str)
      # delete the unique identities for a given data source which are not in the IDENTITIES_INDEX
      delete_orphan_unique_identities(es, sortinghat_db, data_source, active_data_sources)