Skip to content

Commit

Permalink
Change max delay before crawling links to be configurable from env
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrss committed Jul 7, 2023
1 parent eb77096 commit 4aeffc9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Click below to **learn more** in a video:
| RATE_LIMIT_API_SIGN_UP_PERIOD_MINUTES | The rate limiter period (i.e. how long before the count resets) for sign up attempts via the api |
| RATE_LIMIT_SIGN_UP | Max allowed sign up attempts, via the web UI, within a rate limiter period |
| RATE_LIMIT_SIGN_UP_PERIOD_MINUTES | The rate limiter period (i.e. how long before the count resets) for sign up attempts via the web UI |
| MAX_LINK_CRAWL_DELAY_SECONDS | Maximum delay before crawling links received from other instances. |


## Features
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def process_status

def distribute
# Spread out crawling randomly to avoid DDoSing the link
LinkCrawlWorker.perform_in(rand(1..59).seconds, @status.id)
LinkCrawlWorker.perform_in(rand(1..LinkCrawlWorker::MAX_DELAY).seconds, @status.id)

# Distribute into home and list feeds and notify mentioned accounts
::DistributionWorker.perform_async(@status.id, { 'silenced_account_ids' => @silenced_account_ids }) if @options[:override_timestamps] || @status.within_realtime_window?
Expand Down
2 changes: 1 addition & 1 deletion app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def already_updated_more_recently?

def reset_preview_card!
@status.preview_cards.clear
LinkCrawlWorker.perform_in(rand(1..59).seconds, @status.id)
LinkCrawlWorker.perform_in(rand(1..LinkCrawlWorker::MAX_DELAY).seconds, @status.id)
end

def broadcast_updates!
Expand Down
2 changes: 2 additions & 0 deletions app/workers/link_crawl_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class LinkCrawlWorker
include Sidekiq::Worker

MAX_DELAY = ENV.fetch('MAX_LINK_CRAWL_DELAY_SECONDS', 59).to_i

sidekiq_options queue: 'pull', retry: 0

def perform(status_id)
Expand Down

0 comments on commit 4aeffc9

Please sign in to comment.