# Pull Request Template ## Description Fixes inconsistency by adding a fallback to use `url` instead of `sourceUrl` when Firecrawl returns empty `sourceUrl` in production. We switched to v2 endpoints of Firecrawl in https://github.com/chatwoot/chatwoot/pull/14624 and it worked locally, but seems to fail for some cases in production. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. locally ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
33 lines
864 B
Ruby
33 lines
864 B
Ruby
class Captain::Tools::FirecrawlParserJob < ApplicationJob
|
|
queue_as :low
|
|
|
|
def perform(assistant_id:, payload:)
|
|
assistant = Captain::Assistant.find(assistant_id)
|
|
metadata = payload[:metadata]
|
|
|
|
canonical_url = normalize_link(metadata['sourceURL'].presence || metadata['url'])
|
|
document = assistant.documents.find_or_initialize_by(
|
|
external_link: canonical_url
|
|
)
|
|
|
|
document.update!(
|
|
external_link: canonical_url,
|
|
content: payload[:markdown],
|
|
name: metadata['title'],
|
|
status: :available,
|
|
sync_status: :synced,
|
|
last_synced_at: Time.current,
|
|
last_sync_attempted_at: Time.current,
|
|
last_sync_error_code: nil
|
|
)
|
|
rescue StandardError => e
|
|
raise "Failed to parse FireCrawl data: #{e.message}"
|
|
end
|
|
|
|
private
|
|
|
|
def normalize_link(raw_url)
|
|
raw_url.to_s.delete_suffix('/')
|
|
end
|
|
end
|