Template of a custom feed generator service for the Bluesky network in Ruby
1#!/usr/bin/env ruby
2
3$LOAD_PATH.unshift(File.expand_path('..', __dir__))
4
5require 'bundler/setup'
6require 'app/firehose_stream'
7
8$stdout.sync = true
9
10ActiveRecord::Base.logger = nil
11
12def print_help
13 puts "Usage: #{$0} [options...]"
14 puts "Options:"
15 puts
16 puts " * Showing progress: [default: show in development]"
17 puts " -p = show progress dots for each received message"
18 puts " -np = don't show progress dots"
19 puts
20 puts " * Logging status changes: [default: log in any mode]"
21 puts " -ns = don't log status changes"
22 puts
23 puts " * Logging post text: [default: -lm in development, -nl in production]"
24 puts " -lm = log text of matching posts"
25 puts " -la = log text of every post"
26 puts " -nl = don't log posts"
27 puts
28 puts " * Saving posts to db: [default: -da in development, -dm in production]"
29 puts " -da = save all posts to database"
30 puts " -dm = save only matching posts to database"
31 puts " -nd = don't save any posts"
32 puts
33 puts " * Replaying missed events: [default: -nr in development, -r in production]"
34 puts " -r = pass a cursor param when connecting to replay any missed events"
35 puts " -nr = don't replay missed events"
36end
37
38firehose = FirehoseStream.new
39
40ARGV.each do |arg|
41 case arg
42 when '-p'
43 firehose.show_progress = true
44 when '-np'
45 firehose.show_progress = false
46 when '-ns'
47 firehose.log_status = false
48 when '-lm'
49 firehose.log_posts = :matching
50 when '-la'
51 firehose.log_posts = :all
52 when '-nl'
53 firehose.log_posts = false
54 when '-dm'
55 firehose.save_posts = :matching
56 when '-da'
57 firehose.save_posts = :all
58 when '-nd'
59 firehose.save_posts = false
60 when '-r'
61 firehose.replay_events = true
62 when '-nr'
63 firehose.replay_events = false
64 when '-h', '--help'
65 print_help
66 exit 0
67 else
68 puts "Unrecognized option: #{arg}"
69 print_help
70 exit 1
71 end
72end
73
74trap("SIGINT") { firehose.stop }
75
76firehose.start