hypothesis / slack-annotations

Post annotations to Slack.
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Post annotations quicker #1

Open seanh opened 1 week ago

seanh commented 1 week ago

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

I think the script could call the Hypothesis API, post any new annotations to Slack, wait for n seconds (say n=5) then repeat, and keep looping for (say) 4m55s. We'd then have GHA run that every 5 mins. This should result in annotations appearing in Slack within a few seconds.

An challenge with this is that 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 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 hack above I would 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.

seanh commented 1 week ago

According to https://docs.github.com/en/actions/administering-github-actions/usage-limits-billing-and-administration#usage-limits a job can run for up to 6 hours so rather than 5 mins I'd recommend the script runs for 5hrs55mins before exiting and we have GitHub Actions run the script every 6 hours. When you ask GHA to run a workflow every 5 mins it doesn't reliably run it every 5 mins. Sometimes there are much longer gaps between runs. The fewer times GHA runs the script, the fewer opportunities it has for the next run to be late due to scheduling delays.