Skip to content

Commit

Permalink
Merge pull request #142 from leouofa/add_invalid_json_to_articles
Browse files Browse the repository at this point in the history
adding invalid json tag to articles and refactoring the rewrite job
  • Loading branch information
leouofa authored Jul 4, 2024
2 parents 01def79 + 83e31dd commit cd5a7e4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/jobs/articles/rewrite_article_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ def perform(article:)

Rails.logger.debug "invalid_json: #{invalid_json} | counter: #{counter}"

sleep(20)
sleep(25)
end

unless response["error"].present? || invalid_json
parsed_response = JSON.parse(extracted_json_response)

article.update(rewritten_text: parsed_response["content"])

else
article.update(invalid_json:)
end

sleep(10)
Expand Down
2 changes: 2 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# embedding :vector(768)
# invalid_json :boolean default(FALSE)
#
class Article < ApplicationRecord
belongs_to :pillar_column
Expand Down Expand Up @@ -42,6 +43,7 @@ class Article < ApplicationRecord
scope :with_three_links_without_rewritten_text, lambda {
with_three_links
.where(rewritten_text: [nil, ''])
.where(invalid_json: false)
}

private
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240703164512_add_invalid_json_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInvalidJsonToArticles < ActiveRecord::Migration[7.0]
def change
add_column :articles, :invalid_json, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/factories/articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# embedding :vector(768)
# invalid_json :boolean default(FALSE)
#
FactoryBot.define do
factory :article do
Expand Down

0 comments on commit cd5a7e4

Please sign in to comment.