script to run the daily maintenance tasks

This commit is contained in:
rimu 2024-08-18 12:15:49 +12:00
parent 5fc46e4abe
commit c4ac53e92a
3 changed files with 12 additions and 5 deletions

View file

@ -430,7 +430,13 @@ Once a week or so it's good to run `remove_orphan_files.sh` to save disk space:
5 4 * * 1 rimu cd /home/rimu/pyfedi && /home/rimu/pyfedi/remove_orphan_files.sh 5 4 * * 1 rimu cd /home/rimu/pyfedi && /home/rimu/pyfedi/remove_orphan_files.sh
``` ```
If celery is hanging occasionally (we're looking into it but it's a hard one to solve), put this script in /etc/cron.hourly: One per day there are some maintenance tasks that PieFed needs to do:
```
5 2 * * * rimu cd /home/rimu/pyfedi && /home/rimu/pyfedi/daily.sh
```
If celery is hanging occasionally, put this script in /etc/cron.hourly:
``` ```
#!/bin/bash #!/bin/bash

View file

@ -181,10 +181,6 @@ def register(app):
post_delete_post(community, post, post.user_id, federate_all_communities=False) post_delete_post(community, post, post.user_id, federate_all_communities=False)
community.post_count -= 1 community.post_count -= 1
# Remove activity older than 3 days
db.session.query(ActivityPubLog).filter(ActivityPubLog.created_at < utcnow() - timedelta(days=3)).delete()
db.session.commit()
# Ensure accurate count of posts associated with each hashtag # Ensure accurate count of posts associated with each hashtag
for tag in Tag.query.all(): for tag in Tag.query.all():
post_count = db.session.execute(text('SELECT COUNT(post_id) as c FROM "post_tag" WHERE tag_id = :tag_id'), post_count = db.session.execute(text('SELECT COUNT(post_id) as c FROM "post_tag" WHERE tag_id = :tag_id'),

5
daily.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
source venv/bin/activate
export FLASK_APP=pyfedi.py
flask daily-maintenance