Template of a custom feed generator service for the Bluesky network in Ruby

Compare changes

Choose any two refs to compare.

Changed files
+26 -8
app
bin
+1 -1
README.md
··· 1 - <h1>Bluesky feeds in Ruby &nbsp;<img src="https://raw.githubusercontent.com/mackuba/bluesky-feeds-rb/ebbfc3056129a2c31bf030cb21e4b14a71dea3c9/images/ruby.png" width="26"></h1> 1 + <h1>Bluesky feeds in Ruby &nbsp;<img src="https://raw.githubusercontent.com/mackuba/bluesky-feeds-rb/refs/heads/master/images/ruby.png" width="26"></h1> 2 2 3 3 This repo is an example or template that you can use to create a "feed generator" service for the Bluesky social network which hosts custom feeds. It's a reimplementation of the official TypeScript [feed-generator](https://github.com/bluesky-social/feed-generator) example in Ruby. 4 4
+4
Rakefile
··· 4 4 require 'sinatra/activerecord/rake' 5 5 6 6 Rake.add_rakelib File.join(__dir__, 'lib', 'tasks') 7 + 8 + if ENV['ARLOG'] == '1' 9 + ActiveRecord::Base.logger = Logger.new(STDOUT) 10 + end
+16 -6
app/firehose_stream.rb
··· 57 57 @sky.on_connecting { |u| log "Connecting to #{u}..." } 58 58 59 59 @sky.on_connect { 60 + @message_counter = 0 60 61 @replaying = !!(cursor) 61 62 log "Connected ✓" 62 63 } ··· 122 123 if @replaying 123 124 log "Replaying events since #{msg.time.getlocal} -->" 124 125 @replaying = false 126 + end 127 + 128 + @message_counter += 1 129 + 130 + if @message_counter % 100 == 0 131 + # save current cursor every 100 events 132 + save_cursor(msg.seq) 125 133 end 126 134 127 135 msg.operations.each do |op| ··· 224 232 puts text 225 233 end 226 234 227 - if @save_posts == :all || @save_posts && matched 235 + if @save_posts == :all 236 + # wait until we have 100 posts and then save them all in one insert, if possible 228 237 @post_queue << post 229 - end 230 238 231 - # wait until we have 100 posts and then save them all in one insert, if possible 232 - if @post_queue.length >= POSTS_BATCH_SIZE 233 - save_queued_posts 234 - save_cursor(@sky.cursor) 239 + if @post_queue.length >= POSTS_BATCH_SIZE 240 + save_queued_posts 241 + end 242 + elsif @save_posts == :matching && matched 243 + # save immediately because matched posts might be rare; we've already checked validations 244 + post.save!(validate: false) 235 245 end 236 246 237 247 print '.' if @show_progress && @log_posts != :all
+5 -1
bin/firehose
··· 7 7 8 8 $stdout.sync = true 9 9 10 - ActiveRecord::Base.logger = nil 10 + if ENV['ARLOG'] == '1' 11 + ActiveRecord::Base.logger = Logger.new(STDOUT) 12 + else 13 + ActiveRecord::Base.logger = nil 14 + end 11 15 12 16 def print_help 13 17 puts "Usage: #{$0} [options...]"