Commit Graph

7 Commits

Author SHA1 Message Date
Simon Backx
923c522778
Implemented email analytics retrying (#16273)
fixes https://github.com/TryGhost/Team/issues/2562

New event fetching loops:
- Reworked the analytics fetching algorithm. Instead of starting again
where we stopped during the last fetching minus 30 minutes, we now just
continue where we stopped. But with ms precision (because no longer
database dependent after first fetch), and we stop at NOW - 1 minute to
reduce chance of missing events.
- Apart from that, a missing fetching loop is introduced. This fetches
events that are older than 30 minutes, and just processes all events a
second time to make sure we didn't skip any because of storage delays in
the Mailgun API.
- A new scheduled fetching loop, that allows us to schedule between a
given start/end date (currently only persisted in memory, so stops after
a reboot)

UI and endpoint changes:
- New UI to show the state of the analytics 'loops'
- New endpoint to request the analytics loop status
- New endpoint to schedule analytics
- New endpoint to cancel scheduled analytics
- Some number formatting improvements, and introduction of 'opened'
count in debug screen
- Live reload of data in the debug screen

Other changes:
- This also improves the support for maxEvents. We can now stop a
fetching loop after x events without worrying about lost events. This is
used to reduce the fetched events in the missing and scheduled event
loop (e.g. when the main one is fetching lots of events, we skip the
other loops).
- Prevents fetching the same events over and over again if no new events
come in (because we always started at the same begin timestamp). The
code increases the begin timestamp with 1 second if it is safe to do so,
to prevent the API from returning the same events over and over again.
- Some optimisations in handing the processing results (less merges to
reduce CPU usage in cases we have lots of events).

Testing:
- You can test with lots of events using the new mailgun mocking server
(Toolbox repo `scripts/mailgun-mock-server`). This can also simulate
events that are only returned after x minutes because of storage delays.
2023-02-20 16:44:13 +01:00
Daniel Lockyer
6fc4aa8c4b
Reworked testing and documentation for email-analytics-provider-mailgun
- the tests here were no longer relevant because they were more testing
  things that have been moved to `mailgun-client`
- this commit cleans up the tests to ensure we're passing the correct
  parameters to the mailgun client package
- also adds jsdoc on all the functions and maintains 100% code coverage
2022-08-11 10:30:12 +02:00
Daniel Lockyer
9401d835ce
Moved Mailgun settings test to mailgun-client
- this test checks that the mailgun client respects the changes in
  settings, which is something that we used to ask
  `email-analytics-provider-mailgun` to do when the mailgun client was
  made in that package
- since then, we've pulled it out, so we should move the test to the
  `mailgun-client` library
2022-08-10 18:24:35 +02:00
Daniel Lockyer
bf254b9c6a Extracted Mailgun client to separate package
refs https://github.com/TryGhost/Toolbox/issues/363

- this commit pulls all code involving the Mailgun client SDK into one
  new package called `mailgun-client`
- this means we should be able to replace `mailgun-js` (deprecated) with
  `mailgun.js` (the new, official one) without editing code all over the
  place
- this also lays some groundwork for better testing of smaller
  components
2022-08-10 17:12:37 +02:00
ceecko
a9cce0281d Added support for eu Mailgun domain (#73)
closes: https://github.com/TryGhost/Ghost/issues/14640

- eu mailgun domains have a different structure. 
- we weren't accounting for this when fetching the next page of results, meaning that email stats didn't work on EU domains
2022-05-02 19:08:30 +01:00
Sam Lord
a96cf1a39a Use @tryghost/logging package instead of injected argument
refs: https://github.com/TryGhost/Toolbox/issues/146
2021-12-02 12:26:23 +00:00
Kevin Ansfield
0145c925a0 Added email analytics mailgun provider tests 2021-02-25 20:04:17 +00:00