LPW MIMIC poller on Tencent SCF
This event function checks the UW-Madison MIMIC directory every five minutes and dispatches the GitHub Actions workflow only when a newer source product is available.
The decision sequence is:
- Read the latest
compYYYYMMDD.HH0000.nctimestamp from the newest MIMIC monthly directory. - Read the latest published timestamp from
lpw/data/mimic-archive.jsonon GitHub. - Stop with
action: up_to_dateif the source product is already published. - If the source is newer, check for a queued or running
update-lpw.ymlrun. - Stop with
action: workflow_activeif a matching run is already active; otherwise dispatch one update withforce: true.
The function uses only Python’s standard library. GitHub Actions no longer has its own cron schedule, so this SCF timer is the sole automatic scheduler.
Deploy or update the function
- In Tencent Cloud > Serverless Cloud Function (SCF) > Function Service, open the existing event function.
- Replace its
index.pywith the file in this directory, or upload a ZIP whose root directly containsindex.py. - Keep the handler as
index.main_handler, use a supported Python 3 runtime, and keep public network access enabled. - Keep the environment variable
GITHUB_TOKEN. The fine-grained token must be limited towyhgnss/wyhgnss.github.ioand have Actions: Read and write. -
Change the enabled timer trigger to custom Cron expression:
0 */5 * * * * *Tencent’s seven fields are seconds, minutes, hours, day, month, weekday, and year. This expression runs at second 0 every five minutes.
One invocation normally performs three public reads. It calls the authenticated workflow-runs API, and then the dispatch API, only when the source timestamp is newer than the published timestamp.
Verify
Use Test Function once with:
{"Type":"Timer","TriggerName":"manual-test","Message":""}
Expected outcomes:
action: up_to_date,dispatched: false: no unpublished MIMIC product.action: workflow_active,dispatched: false: a new product exists but the workflow is already queued or running.action: dispatched,dispatched: true: a new GitHub Actions run was created. GitHub may return status 200 with run details or an empty 204.
Do not commit the GitHub token or include it inside the ZIP file.
Run local tests from this directory with:
python -m unittest -v test_index.py