in lib/core/job_cleanup.rb [21:37]
def process_orphaned_jobs
Utility::Logger.debug('Start cleaning up orphaned jobs...')
all_connectors = ConnectorSettings.fetch_all_connectors
orphaned_jobs = ConnectorJob.orphaned_jobs(all_connectors.map(&:id))
if orphaned_jobs.empty?
Utility::Logger.debug('No orphaned jobs found. Skipping...')
return
end
content_indices = (orphaned_jobs.map(&:index_name) - all_connectors.map(&:index_name)).compact.uniq
ElasticConnectorActions.delete_indices(content_indices) if content_indices.any?
result = ConnectorJob.delete_jobs(orphaned_jobs)
Utility::Logger.error("Error found when deleting jobs: #{result['failures']}") if result['failures']&.any?
Utility::Logger.info("Successfully deleted #{result['deleted']} out of #{result['total']} orphaned jobs.")
end