Skip to content

Instantly share code, notes, and snippets.

@RossAllenBell
Created May 9, 2022 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RossAllenBell/1b3ef7771c1a696eb116e468b62e9812 to your computer and use it in GitHub Desktop.
Save RossAllenBell/1b3ef7771c1a696eb116e468b62e9812 to your computer and use it in GitHub Desktop.
Illustrative example of a sync job that matches a third party data structure.
class Sync::ConfluenceCloud
def run_job(job)
case job.task
when nil # Entry point, starts with queue_job (no params)
fetch_spaces.each do |space|
queue_job(task: 'crawl_space', space_id: space.id)
queue_job(task: 'index_document', document: space.to_json)
end
when 'crawl_space'
response = if job.next_page.blank?
fetch_space_contents(job.space_id)
else
fetch_next_page(job.next_page)
end
queue_job(task: 'crawl_space', next_page: response.next_page) if response.next_page.present?
response.each do |content|
queue_job(task: 'index_document', document: content.to_json)
end
when 'index_document'
job.document.raw_body = download_attachment(job.document.id) if job.document.type == 'attachment'
index_to_elasticsearch(job.document)
end
end
# Not illustrated:
# Auth data handling
# Tracking overall sync progress or completion
# Shared sync data cache needed for things like Google Drive document paths
# DLP
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment