This document describes how often and in what order to run the funnel script, as well as the general scheduling strategy.
Main working task:
-
app.mainResponsible for:
- selecting new candidates by tests;
- adding contacts to Brevo lists;
- recording funnel entry in the
funnel_entriestable; - syncing certificate purchases with MODX tables.
Reporting task:
-
app.report_conversionsUsed for periodic conversion reports, run manually as needed.
Recommended logic:
- Frequency: every 10-30 minutes, depending on load and requirements.
- With a small number of tests, you can start with hourly runs.
Reasons:
- tests and purchases don't happen every second;
- too frequent runs create unnecessary database load;
- too infrequent runs reduce "freshness" of funnels and emails.
Before enabling automatic execution:
-
Verify that
.envis configured. -
Run the script several times manually with
APP_DRY_RUN=true:python -m app.main -
Check logs in
logs/app.log. -
Change
APP_DRY_RUNtofalsewhen script behavior is satisfactory. -
Run manually again and verify that:
-
contacts actually appear in Brevo;
-
the
funnel_entriestable is populated; -
there are no errors in logs.
-
Only after this should automatic scheduling be enabled.
A production server can use its own scheduling mechanism:
- cron or similar system on hosting;
- hosting control panel with graphical task scheduler;
- separate task orchestrator if already in use.
General recommendations for any system:
- the startup command should be the Python task from the project root;
- virtual environment should be activated before startup;
- work logs should be written to a file for diagnostics.
Specific schedule implementation depends on infrastructure and can be configured by the server administrator.
Regardless of the system used, the logic can be:
-
Run the main funnel task every 15 minutes.
- If the previous run is still running, don't start a new task copy.
- It's important to avoid parallel runs that work with the same tables.
-
Once a day (e.g., at night) generate a conversion report manually and track dynamics:
python -m app.report_conversions --from-date 2024-01-01
-
Change run frequency if needed when:
- load noticeably increases;
- funnel logic changes;
- closer to real-time synchronization is required.
After enabling automatic scheduling, you should:
- periodically check
logs/app.log; - monitor if new entries appear in
funnel_entries; - compare the number of new tests and the number of new funnel entries.
If something goes wrong:
- temporarily disable automatic execution;
- run the task manually and analyze logs;
- restore scheduling only after eliminating error causes.