App-bsky
view release on metacpan or search on metacpan
lib/App/bsky.pm view on Meta::CPAN
}
method cmd_tl (@args) { $self->cmd_timeline(@args); }
method cmd_stream(@args) {
GetOptionsFromArray( \@args, 'json|j' => \my $json );
require Mojo::IOLoop; # Ensure Mojo is available for the event loop
require Archive::CAR::CID;
require Archive::CAR;
require Codec::CBOR;
# Keep the loop alive even if the connection drops briefly
my $keepalive = Mojo::IOLoop->recurring( 60 => sub { $self->say("[DEBUG] Firehose loop keepalive...") if $ENV{DEBUG}; } );
my %profile_cache;
my @profile_lru;
my $MAX_CACHE = 1000;
my $cache_profile = sub ($p) {
my $did = $p->{did};
if ( exists $profile_cache{$did} ) {
@profile_lru = grep { $_ ne $did } @profile_lru;
}
push @profile_lru, $did;
$profile_cache{$did} = $p;
lib/App/bsky.pm view on Meta::CPAN
if ( defined $err ) {
warn 'Firehose error: ' . $err;
# Always try to reconnect if not explicitly fatal
if ( !$err->fatal ) {
$self->say('[DEBUG] Attempting to reconnect in 5 seconds...') if $ENV{DEBUG} || 1;
Mojo::IOLoop->timer( 5 => sub { $start_stream->() } );
}
else {
$self->say('[DEBUG] Fatal firehose error. Exiting.') if $ENV{DEBUG} || 1;
Mojo::IOLoop->remove($keepalive);
Mojo::IOLoop->stop;
}
return;
}
if ($json) {
$self->say( JSON::Tiny::to_json( { header => $header, body => $body } ) );
return;
}
# Only process commit events for now
( run in 0.770 second using v1.01-cache-2.11-cpan-df04353d9ac )