So, I’m apparently running v4.4.0-alpha.1+chuckya
(src) on my fedi instance, which means I have access to the “amazing” (/s) wrapstodon feature which I of course had to de-Mastodon a little ;3
It broke my instance for a bit, but here’s a recreation of what I did to make it work.
- SSH’d to the instance, changed to the
mastodon
user, cd’d to thelive
directory - Ran:
RAILS_ENV=production bundle exec rails console
- Then once loaded (i.e.
mastodon(prod)>
prompt is visible), ran:
AnnualReport.prepare(2024) # replace with whichever year you want to run the report for
User.joins(account: :account_stat)
.confirmed
.merge(Account.without_suspended)
.includes(:account)
.where(current_sign_in_at: (Date.new(2024, 1, 1)..)) # replace year here, too, if you want to run it for a different year
.where(account_stats: { followers_count: (1..) }).find_each do |user|
annual_report = AnnualReport.new(user.account, 2024).generate # replace year here, too, if you want to run it for a different year
next if annual_report.nil? || annual_report.data['top_statuses'].values.all?(&:nil?) || annual_report.data['top_hashtags'].empty?
NotifyService.new.call(user.account, :annual_report, annual_report)
end
- Wait for the script to finish running (it’ll return
nil
)
This initially didn’t work for me (or at least, I didn’t get the notification) — I logged into the db (sudo -u postgres psql
) and checked the tables (\dt
) to see if the generated_annual_reports
table was created (it had been).
I then checked to see if any notifications had been sent
mastodon_production=# select * from notifications order by created_at desc limit 20;
and did not see any with the activity_type
of GeneratedAnnualReport
.
Going back to the command I ran in the rails console, I assumed that
next if annual_report.nil? || annual_report.data['top_statuses'].values.all?(&:nil?) || annual_report.data['top_hashtags'].empty?
had prevented the notification from being sent. With all the confidence of someone who doesn’t know ruby, I commented out the line and ran the script again.
Ooops.
Opening the web UI gave an error, something to do with notification_annual_report.tsx
… nothing would load until I checked for and deleted the notification in the database
mastodon_production=# delete from notifications where activity_type = 'GeneratedAnnualReport';
Fuck it, I’ll clear the generated_annual_reports
mastodon_production=# delete from generated_annual_reports;
and try again.
This time it worked (whyyy??) and checking for relevant notifications in the table
mastodon_production=# select * from notifications where activity_type = 'GeneratedAnnualReport';
returned some results. Refreshing the web UI showed the weird lil’ notification and everything worked — yay :D
(content taken heavily from https://blog.thms.uk/2024/12/how-to-run-wrapstodon :3)