-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* v1 * basic sync * comments * x * ruby 3.2.5 * version * v * v * quip status * unique * status * sync indicator
- Loading branch information
1 parent
dd50040
commit f83793f
Showing
14 changed files
with
137 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,4 +119,4 @@ gem 'bundle-audit' | |
|
||
gem 'brakeman' | ||
|
||
gem 'reverse_markdown' | ||
gem 'reverse_markdown' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,6 +361,7 @@ GEM | |
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
arm64-darwin-23 | ||
x86_64-darwin-22 | ||
x86_64-linux | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class SyncQuipDocJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(_doc_id) | ||
begin | ||
document = Document.find(_doc_id) | ||
rescue ActiveRecord::RecordNotFound => e | ||
# Handle the case where the document is not found | ||
Rails.logger.error("Document with id #{_doc_id} not found: #{e.message}") | ||
return # Exit early since there's nothing to sync | ||
end | ||
|
||
# Log or handle cases where the document has no quip_url | ||
if document.source_url.blank? | ||
Rails.logger.warn("Document with id #{_doc_id} has no source URL.") | ||
return | ||
end | ||
|
||
begin | ||
# Initialize the Quip client | ||
quip_client = Quip::Client.new(access_token: ENV.fetch('QUIP_TOKEN')) | ||
uri = URI.parse(document.source_url) | ||
path = uri.path.sub(%r{^/}, '') # Removes the leading / | ||
quip_thread = quip_client.get_thread(path) | ||
|
||
# Convert Quip HTML content to Markdown | ||
markdown_quip = ReverseMarkdown.convert(quip_thread['html']) | ||
|
||
document.document = markdown_quip | ||
document.synced_at = DateTime.current | ||
document.last_sync_result = 'SUCCESS' | ||
document.save | ||
rescue Quip::Error => e | ||
# Handle Quip-specific errors | ||
Rails.logger.error("Quip API error while fetching document from #{document.source_url}: #{e.message}") | ||
document.last_sync_result = "#{e.message}" | ||
document.save | ||
rescue StandardError => e | ||
# Handle any other unforeseen errors | ||
Rails.logger.error("Unexpected error during sync for document id #{_doc_id}: #{e.message}") | ||
document.last_sync_result = "#{e.message}" | ||
document.save | ||
end | ||
|
||
# Reschedule the job to run again in 24 hours | ||
SyncQuipDocJob.set(wait: 24.hours).perform_later(_doc_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddSourceUrlToDocument < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :documents, :source_url, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddSyncedAtToDocument < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :documents, :synced_at, :datetime | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20241015190422_add_last_sync_result_to_document.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddLastSyncResultToDocument < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :documents, :last_sync_result, :string | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.