Refactor the code to get rid of global variables. Also improve the docs.
This commit is contained in:
parent
3c1a44c4ee
commit
5575cc9156
3 changed files with 267 additions and 193 deletions
49
README.md
49
README.md
|
|
@ -6,17 +6,25 @@ can be emailed to the author as a backup.
|
|||
## Expiring old notes and revisions
|
||||
|
||||
Hedgedoc keeps notes and revisions (versions) of those notes forever. This might not be desirable, for example because
|
||||
of data protection reasons. With this utility, you can remove old revisions and old notes from the database.
|
||||
of data protection reasons. With this utility, you can remove old revisions and old notes from the
|
||||
database. `hedgedoc-expire` works by talking directly to a Postgres database; no API access to Hedgedoc is required.
|
||||
Currently, it only works with Postgres.
|
||||
|
||||
### Expiring old revisions
|
||||
|
||||
All revisions that have been created before the specified age will be removed. If all revisions are expired, the note remains available, it just won't have any revisions to revert to. Once you continue editing it, new revisions will be added.
|
||||
All revisions that have been created before the specified age will be removed. If all revisions are expired, the note
|
||||
remains available, it just won't have any revisions to revert to. Once you continue editing it, new revisions will be
|
||||
added.
|
||||
|
||||
### Expiring old notes
|
||||
|
||||
Notes that are being expired will be emailed to the account that initially created the note. This allows that user to restore the note, if necessary. Expiring a note will also remove all existing revisions for the note.
|
||||
Notes that are being expired will be emailed to the account that initially created the note. This allows that user to
|
||||
restore the note, if necessary. Expiring a note will also remove all existing revisions for the note.
|
||||
|
||||
You will need to configure your environment for the `hedgedoc-expire` to be able to send mail. If the mail is not accepted by the mail server, the note will not be removed.
|
||||
You will need to configure your environment for `hedgedoc-expire` to be able to send mail. If the mail is not accepted
|
||||
by the mail server, the note will not be removed. Note however that this utility has no idea if the mail server has
|
||||
successfully delivered that mail to the intended recipient; if the mail gets lost somewhere on the way, the note cannot
|
||||
be recovered.
|
||||
|
||||
## Running `hedgedoc-expire.py`
|
||||
|
||||
|
|
@ -38,22 +46,43 @@ From Docker Compose:
|
|||
- database
|
||||
```
|
||||
|
||||
Running against a local setup with one note, with times set to a fraction of a day:
|
||||
|
||||
```shell
|
||||
$ poetry run python ./hedgedoc-expire.py -n .001 -r .001
|
||||
Revisions to be deleted created before 2024-05-20 09:02:46.407671+00:00 (a minute):
|
||||
foo@example.com http://localhost:3000/foo: hedgedoc-expire - remove old notes
|
||||
a day: 328dd778-6914-4a04-be58-940b1fe83e01
|
||||
a day: 5acca085-51da-4463-ad20-74dc03e68255
|
||||
Notes to be deleted not changed since 2024-05-20 09:02:46.416294+00:00 (a minute):
|
||||
foo@example.com (a day) http://localhost:3000/foo: hedgedoc-expire - remove old notes
|
||||
```
|
||||
|
||||
## Arguments and Environment Variables
|
||||
|
||||
There are two main modes to run `hedgedoc-require`: check and expire. With `-c`, a report is generated on standard out.
|
||||
Without it, the expiry action will be taken.
|
||||
|
||||
| Option | Default | Description |
|
||||
|--------|---------|------------------------------------------------------------|
|
||||
| -c | | Create a report which revisions and notes will be expired |
|
||||
| -n | 90 | remove all notes not changed in these many days |
|
||||
| -r | 7 | remove all revisions created more than these many days ago |
|
||||
| Option | Default | Description |
|
||||
|--------|---------|-------------------------------------------------------------------|
|
||||
| -n | 90 | remove all notes not changed in these many days |
|
||||
| -r | 7 | remove all revisions created more than these many days ago |
|
||||
| -v | false | Print info on current action during `cron` and `expire` commandds |
|
||||
|
||||
Command is one of:
|
||||
|
||||
| Command | Description |
|
||||
|---------|------------------------------------------------------------------------------------------------------------|
|
||||
| check | Print a list of revisions and notes that would be expired, based on the given parameters for `-n` and `-r` |
|
||||
| cron | Run `expire` at 2 am local time each day. Will run until killed. |
|
||||
| expire | Expire old revisions and notes. |
|
||||
|
||||
### Environment variables
|
||||
|
||||
To configure the Postgres database connection and the SMTP parameters to send mail, set these variables.
|
||||
|
||||
For the SMTP connection, the code assumes a standard submission protocol setup with enable StartTLS and authentication, so you will need to configure a username and password.
|
||||
For the SMTP connection, the code assumes a standard submission protocol setup with enable StartTLS and authentication,
|
||||
so you will need to configure a username and password.
|
||||
|
||||
| Variable | Default | Description |
|
||||
|-------------------|-----------------------|-------------------------------------|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue