Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cron job for anonymous analytics
- triggers every 5 days - respects settings.ANONYMOUS_ANALYTICS setting
- Loading branch information
Showing
8 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tcms.cron.anonymous\_analytics module | ||
===================================== | ||
|
||
.. automodule:: tcms.cron.anonymous_analytics | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tcms.cron package | ||
================= | ||
|
||
.. automodule:: tcms.cron | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Submodules | ||
---------- | ||
|
||
.. toctree:: | ||
:maxdepth: 4 | ||
|
||
tcms.cron.anonymous_analytics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Subpackages | |
|
||
tcms.bugs | ||
tcms.core | ||
tcms.cron | ||
tcms.issuetracker | ||
tcms.kiwi_attachments | ||
tcms.kiwi_auth | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# make sure Python is enabled | ||
export VIRTUAL_ENV=/venv | ||
export PATH=/venv/bin:${PATH} | ||
|
||
# execute the actual Python script | ||
cat /venv/lib64/python3.11/site-packages/tcms/cron/anonymous_analytics.py | /Kiwi/manage.py shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (c) 2024 Alexander Todorov <atodorov@otb.bg> | ||
# | ||
# Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
|
||
""" | ||
Send a custom pageview event to Plausible.io so that we can count | ||
how many/which versions of Kiwi TCMS are out there in the wild! | ||
WARNING: this file is meant to be executed as a wsgi cron job, | ||
see etc/wsgi.conf for more details. | ||
""" | ||
import requests | ||
import sys | ||
from django.conf import settings | ||
|
||
|
||
def post_analytics(): | ||
response = requests.post( | ||
"https://plausible.io/api/event", | ||
json={ | ||
"name": "pageview", | ||
"url": f"app://{settings.PLAUSIBLE_DOMAIN}/deployed-versions", | ||
"domain": settings.PLAUSIBLE_DOMAIN, | ||
"props": { | ||
"version": settings.KIWI_VERSION, | ||
}, | ||
}, | ||
headers={ | ||
"User-Agent": f"kiwi-tcms/{settings.KIWI_VERSION}", | ||
"Content-Type": "application/json", | ||
}, | ||
) | ||
|
||
print(response.status_code) | ||
print(response.headers) | ||
print(response.text) | ||
|
||
|
||
if not settings.ANONYMOUS_ANALYTICS: | ||
print("Anonymous analytics are explicitly disabled. Exiting") | ||
elif "manage.py" in sys.argv and "shell" in sys.argv: | ||
# execute only when piped to `./manage.py shell` | ||
post_analytics() | ||
else: | ||
print( | ||
"WARNING: pipe the content of this file to ./manage.py shell in order to execute it" | ||
) |