-
Notifications
You must be signed in to change notification settings - Fork 918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wagtail/Smartling robustness improvements #15699
Conversation
Ensure the visual context sent to Smartling is always with a fresh sharing link with no expiry By default, these now last 28 days, which might be enough, but we don't want to take the risk, given how fiddly the cleanup is of an expired link causing initial sync to fail
5f58938
to
47eedf9
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15699 +/- ##
==========================================
+ Coverage 79.04% 79.06% +0.01%
==========================================
Files 159 160 +1
Lines 8329 8355 +26
==========================================
+ Hits 6584 6606 +22
- Misses 1745 1749 +4 ☔ View full report in Codecov by Sentry. |
…Sentry It already has SENTRY_DSN available to it
And also make it more robust - preferring to get strings to Smartling without a visual context, rather than fail altogether
This will get us around the File Locked issue we saw in prod
47eedf9
to
c456d65
Compare
# 21 days here because the links are used to send a preview of the source page to | ||
# Smartling translators, and we want to give them plenty of time. In the future | ||
# we can bring this back down to 7 days and set a Smartling-specific one of 21 | ||
WAGTAILDRAFTSHARING_MAX_AGE = 21 * 24 * 60 * 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now defaults to 28 days for our fork of wagtaildraftsharing https://github.com/mozmeao/wagtaildraftsharing/blob/768b989adc304c43476f2ca55b655b7940378999/wagtaildraftsharing/settings.py#L7
...while creating links for using Smartling's visual context now has a max_ttl
of -1
, meaning those links never expire (see the changes in base.py
above)
# VERBOSE_NAME: "Internal Share" | ||
# VERBOSE_NAME_PLURAL: "Internal Shares" | ||
# MENU_ITEM_LABEL: "Create internal sharing link" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change in settings config to a dict is a breaking change introduced in Wagtaildraftsharing 0.8.0
@@ -32,3 +33,4 @@ def handle(self, *args, **kwargs): | |||
sys.stdout.write("Snitch pinged\n") | |||
except Exception as ex: | |||
sys.stderr.write(f"\nsync_smartling did not execute successfully: {ex}\n") | |||
capture_exception(ex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure we get as much info as possible if the sync isn't happy for some reason
key=sharing_link.key, | ||
) | ||
return resp.content.decode("utf-8") | ||
except Exception as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is very broad, but it's important to cast a wide net for the sentry logging
Tagging you @alexgibson just for awareness - I know you're too busy to review, and wanted to keep you in the loop. |
class SmartlingSyncTests(TestCase): | ||
@patch("bedrock.cms.management.commands.run_smartling_sync.call_command") | ||
def test_sentry_logging_for_run_smartling_sync_command(self, mock_call_command): | ||
test_exception = Exception("Boom!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💣
# The only time we'll have a situation like this is when someone is using | ||
# a DB export from dev/stage/prod, which has all of its revision history | ||
# excluded from the export. | ||
capture_message(f"Unable to get a latest_revision for {content_obj} so unable to send visual context.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing where this variable is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean content_obj
, that's the Wagtail Page or Snippet that's being translated - we get it up on line 51 (just above this diff, folded away)
@@ -2325,7 +2325,7 @@ def lazy_wagtail_langs(): | |||
WAGTAIL_CONTENT_LANGUAGES = lazy(lazy_wagtail_langs, list)() | |||
|
|||
# Don't automatically make a page for a non-default locale availble in the default locale | |||
WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE = False | |||
WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE = False # note that WAGTAILLOCALIZE is correct without the _ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this not use the _
but the one below does? Separate libraries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, exactly that. wagtail-localize
uses WAGTAILLOCALIZE_FOO
(and my eyes cross when seeing those LL
together), while wagtail-localize-smartling
uses WAGTAIL_LOCALIZE_SMARTLING
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code level review looks good. I asked a few questions just out of curiosity.
One-line summary
This changeset makes our Smartling interactions more robust and provides more logging to help us diagnose any further teething troubles with its use in production.
Significant changes and points to review
Update wagtaildraftsharing to 0.2.0
This remedies an issue where it was possible to ask for a sharing link for a page, only to be given one that has expired (and which then blows up the code that's suppose to provide a HTML dump of the page to Smartling).
We now use a new method
create_for_revision
, which never gets a duplicate. We also make that sharing link one that never expires, rather than second-guess how long a translator might need to translate a page. (These links can still be deleted, so we could add a cleanup job every few months)Update to wagtail-localize-smartling 0.80
This remedies the other main error in the export run that failed: we got a
File locked
error from the Smartling API because we were trying to make a call related to a file that hadn't completed processing. The solution to this was to refactor the file-upload part ofwagtail-localize-smartling
to use a "Job Batch", which handles file uploads asynchronously and transparently. I've tested this locally against our Smartling Sandbox and it definitely works.Extra logging added
Issue / Bugzilla link
Resolves #15629
Testing
This is tricky to test without local setup. I've tested it a fair amount myself as part of developing the new release of wagtaildraftsharing and wagtail-localize-smartling, and I'll test-drive it again on Dev before we take it to prod. So, code-level eyes and sense checking would be great, but no need to test drive I think.