hypothesis / hypothesis/slack-annotations

Post annotations quicker

Open
#1 0 comments 0 reactions 1 assignee Claimed by @mtomilov View on GitHub
enhancement
Dominant language
Python
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

#### Problem

Currently the GitHub Actions workflow runs once every five minutes, which is the maximum frequency that GHA can run a scheduled workflow at. Each time the workflow runs it checks the Hypothesis API once for new annotations, posts any new ones to Slack, and then exits.

This means that after creating an annotation in Hypothesis it can take up to five minutes for the annotation to appear in Slack.

We'd like this to be faster.

#### Possible solution

GitHub Actions jobs are [allowed to run for up to 6 hours continuously](https://docs.github.com/en/actions/administering-github-actions/usage-limits-billing-and-administration#usage-limits). Change the `slack-annotations` script to call the Hypothesis API, post any new annotations to Slack, sleep for `n` seconds (say `n=5`) then repeat in a loop for **3 hours** then exit. And change the scheduled GitHub Actions workflows that run the script ([`eng_annotations.yml`](https://github.com/hypothesis/slack-annotations/blob/main/.github/workflows/eng_annotations.yml) and [`pr_website.yml`](https://github.com/hypothesis/slack-annotations/blob/main/.github/workflows/pr_website.yml)) to run the script every 3 hours instead of every 5 minutes.

It won't be perfect, but this hack should mean that, for the most part, annotations get posted into Slack within a few seconds after they're created. This should be more than good enough.

Notes:

* There's a [`test.yml` workflow](https://github.com/hypothesis/slack-annotations/blob/146f7b9d2bcbe621508ade19b71e4eb68fc85fe7/.github/workflows/test.yml) that calls the `slack-annotations` script and posts results into the `#test-slack-annotations` Slack channel. This test workflow isn't run automatically, it's only run manually for testing purposes. When running this test workflow we would _not_ want the script to loop for three hours, we'd want it to loop only once then exit. So the time to loop for will need to be a command line argument to the script.

* Currently the Python script itself doesn't actually post annotations to Slack, it just prints them out in a Slack-compatible format and then after the script exits the GHA workflow [pipes its output to Slack's official GitHub action](https://github.com/hypothesis/slack-annotations/blob/522dfd6d278216e83c39d1ad466220dfbdd7fe91/.github/workflows/notify.yml#L39-L47) to do the actual posting for us. This was just a shortcut to save me time not having to write my own code for posting to Slack. In order to implement the looping hack I think you'll have to change it to have the Python code itself actually do the posting to the Slack API instead of piping to Slack's action, as that'll be necessary in order to post in a loop.
* The script will need to take a Slack API token as a command line argument.
* On GitHub Actions, the `notify.yml` workflow can pass [`${{ secrets.SLACK_BOT_TOKEN }}`](https://github.com/hypothesis/slack-annotations/blob/146f7b9d2bcbe621508ade19b71e4eb68fc85fe7/.github/workflows/notify.yml#L58) as the command line argument.
* It might be convenient to have a `--dry-run` option for testing locally without a Slack API token: just print out some messages about what would have been posted to Slack.
* `eng_annotations.yml` and `pr_website.yml` have [Dead Man's Snitch](https://deadmanssnitch.com/) alerts that expect the scheduled workflows to complete once an hour otherwise an alarm will go off. These should be changed to three hours.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.