Skip to content

Commit

Permalink
Handle facebook posts with multiple videos
Browse files Browse the repository at this point in the history
  • Loading branch information
cguess committed Dec 2, 2024
1 parent c2199d6 commit 7f166f1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ gem "turbo-rails"

gem "sprockets-rails", require: "sprockets/railtie"

# Jard is an improvement on Byebug
gem "ruby_jard"
gem "pry-byebug"

# Add the ability to load `.env` files on launch
Expand Down
6 changes: 0 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,6 @@ GEM
ruby-vips (2.2.2)
ffi (~> 1.12)
logger
ruby_jard (0.3.1)
byebug (>= 9.1, < 12.0)
pry (~> 0.13.0)
tty-screen (~> 0.8.1)
rubyntlm (0.6.3)
rubyzip (2.3.2)
safe_type (1.1.1)
Expand Down Expand Up @@ -686,7 +682,6 @@ GEM
bindata (~> 2.4)
openssl (> 2.0, < 3.1)
openssl-signature_algorithm (~> 1.0)
tty-screen (0.8.1)
turbo-rails (1.3.0)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
Expand Down Expand Up @@ -801,7 +796,6 @@ DEPENDENCIES
rubocop-sorbet
ruby-lsp
ruby-progressbar
ruby_jard
rubyzip
selenium-webdriver
shrine!
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/send_scrape_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SendScrapeEmailJob < ApplicationJob
queue_as :default
retry_on StandardError, wait: 2.minutes, attempts: 5

def perform(scrape)
logger.info "Sending completion email for scrape #{scrape.id}"
scrape.send_completion_email
end
end
4 changes: 2 additions & 2 deletions app/models/scrape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def perform
ssl_verifyhost: 0
)


json_error_response = JSON.parse(response.body)
if response.code != 200
if response.code == 400 && json_error_response.nil? == false && json_error_response["code"] == 10
Expand Down Expand Up @@ -112,6 +111,7 @@ def fulfill(response)
errored = true # For later in case the option for `status` could be something else
end
end
# debugger

# Process everything correctly now that we know it's not removed
media_review_item = self.media_review
Expand All @@ -134,7 +134,7 @@ def fulfill(response)
self.send_notification

# Send the completion email or whatever if necessary
self.send_completion_email
SendScrapeEmailJob.perform_later(self)
rescue StandardError => e
logger.error "Error fulfilling scrape: #{e}"
Honeybadger.notify(e, context: {
Expand Down
5 changes: 5 additions & 0 deletions app/models/sources/facebook_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def self.create_from_forki_hash(forki_posts, user = nil)
if forki_post["aws_image_keys"].present?
downloaded_path = AwsS3Downloader.download_file_in_s3_received_from_hypatia(forki_post["aws_image_keys"])
image_attributes = [ { image: File.open(downloaded_path, binmode: true) } ]
elsif forki_post["aws_video_keys"].present?
video_attributes = forki_post["aws_video_keys"].map do |key|
downloaded_path = AwsS3Downloader.download_file_in_s3_received_from_hypatia(key)
{ video: File.open(downloaded_path, binmode: true) }
end
elsif forki_post["aws_video_key"].present?
downloaded_path = AwsS3Downloader.download_file_in_s3_received_from_hypatia(forki_post["aws_video_key"])
video_attributes = [ { video: File.open(downloaded_path, binmode: true) } ]
Expand Down
7 changes: 7 additions & 0 deletions test/jobs/send_scrape_email_job_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class SendScrapeEmailJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 7f166f1

Please sign in to comment.