Skip to content

Commit

Permalink
Only send Learn webhook requests for live sites to update search index (
Browse files Browse the repository at this point in the history
#2295)

* Only send Learn webhook requests for live sites to update search index

* Add test for draft pipeline webhook

* Add test for draft pipeline webhook for offline pipeline

* Refactor tests
  • Loading branch information
ibrahimjaved12 authored Sep 10, 2024
1 parent c7fc86a commit 6151e6f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def __init__(self, themes_branch: str, projects_branch: str, **kwargs):
SitePipelineOnlineTasks(
pipeline_vars=site_pipeline_vars,
fastly_var="test",
pipeline_name=VERSION_LIVE,
skip_cache_clear=is_dev(),
skip_search_index_update=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(self, config: MassBuildSitesPipelineDefinitionConfig):
)
)
self.append(SlackAlertResource())
if not is_dev():
if not is_dev() and config.version == "live":
self.extend(
[OpenCatalogResource(url) for url in settings.OPEN_CATALOG_URLS]
)
Expand Down Expand Up @@ -315,14 +315,17 @@ def __init__(self, config: MassBuildSitesPipelineDefinitionConfig, **kwargs):
SitePipelineOnlineTasks(
pipeline_vars=site_pipeline_vars,
fastly_var=config.version,
pipeline_name=config.version,
destructive_sync=False,
filter_videos=True,
)
)
else:
site_build_tasks.extend(
SitePipelineOfflineTasks(
pipeline_vars=site_pipeline_vars, fastly_var=config.version
pipeline_vars=site_pipeline_vars,
fastly_var=config.version,
pipeline_name=config.version,
)
)
if batch_number > 1:
Expand Down
46 changes: 28 additions & 18 deletions content_sync/pipelines/definitions/concourse/site_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def __init__(self, config: SitePipelineDefinitionConfig):
SlackAlertResource(),
]
)
if not is_dev():
if not is_dev() and config.values["pipeline_name"] == "live":
self.extend(
[OpenCatalogResource(url) for url in settings.OPEN_CATALOG_URLS]
)
Expand Down Expand Up @@ -459,6 +459,7 @@ class SitePipelineOnlineTasks(list[StepModifierMixin]):
Args:
pipeline_vars(dict): A dictionary of site pipeline variables
fastly_var(str): A string to append to fastly_ and form a var name where Fastly connection info is stored
pipeline_name(str): The name of the pipeline (e.g., "draft" or "live")
destructive_sync(bool): (Optional) A boolean override for the delete flag used in AWS syncs
filter_videos(bool): (Optional) A boolean override for filtering videos out of AWS syncs
skip_cache_clear(bool): (Optional) A boolean override for skipping the CDN cache clear step
Expand All @@ -469,6 +470,7 @@ def __init__( # noqa: PLR0913
self,
pipeline_vars: dict,
fastly_var: str,
pipeline_name: str,
*,
destructive_sync: bool = True,
filter_videos: bool = False,
Expand Down Expand Up @@ -586,7 +588,7 @@ def __init__( # noqa: PLR0913
instance_vars=pipeline_vars["instance_vars"],
)
clear_cdn_cache_online_on_success_steps = []
if not skip_search_index_update:
if not skip_search_index_update and pipeline_name == "live":
clear_cdn_cache_online_on_success_steps.extend(
[
*[
Expand Down Expand Up @@ -626,9 +628,10 @@ class SitePipelineOfflineTasks(list[StepModifierMixin]):
Args:
pipeline_vars(dict): A dictionary of site pipeline variables
fastly_var(str): A string to append to fastly_ and form a var name where Fastly connection info is stored
pipeline_name(str): The name of the pipeline (e.g., "draft" or "live")
""" # noqa: E501

def __init__(self, pipeline_vars: dict, fastly_var: str):
def __init__(self, pipeline_vars: dict, fastly_var: str, pipeline_name: str):
static_resources_task_step = StaticResourcesTaskStep(
pipeline_vars=pipeline_vars
)
Expand Down Expand Up @@ -777,23 +780,27 @@ def __init__(self, pipeline_vars: dict, fastly_var: str):
short_id=pipeline_vars["short_id"],
instance_vars=pipeline_vars["instance_vars"],
)
clear_cdn_cache_offline_step.on_success = TryStep(
try_=DoStep(
do=[
*[
OpenCatalogWebhookStep(
site_url=pipeline_vars["url_path"],
pipeline_name=pipeline_vars["pipeline_name"],
open_catalog_url=open_catalog_url,
)
for open_catalog_url in settings.OPEN_CATALOG_URLS
],
OcwStudioWebhookStep(
clear_cdn_cache_offline_on_success_steps = []

if pipeline_name == "live":
clear_cdn_cache_offline_on_success_steps.extend(
[
OpenCatalogWebhookStep(
site_url=pipeline_vars["url_path"],
pipeline_name=pipeline_vars["pipeline_name"],
status="succeeded",
),
open_catalog_url=open_catalog_url,
)
for open_catalog_url in settings.OPEN_CATALOG_URLS
]
)
clear_cdn_cache_offline_on_success_steps.append(
OcwStudioWebhookStep(
pipeline_name=pipeline_vars["pipeline_name"],
status="succeeded",
)
)
clear_cdn_cache_offline_step.on_success = TryStep(
try_=DoStep(do=clear_cdn_cache_offline_on_success_steps)
)
self.extend(
[
Expand Down Expand Up @@ -916,6 +923,7 @@ def get_online_build_job(self, config: SitePipelineDefinitionConfig):
online_tasks = SitePipelineOnlineTasks(
pipeline_vars=config.vars,
fastly_var=config.pipeline_name,
pipeline_name=config.pipeline_name,
skip_cache_clear=skip_cache_clear,
)
for task in online_tasks:
Expand Down Expand Up @@ -943,7 +951,9 @@ def get_offline_build_job(self, config: SitePipelineDefinitionConfig):
steps.append(FilterWebpackArtifactsStep(web_bucket=config.vars["web_bucket"]))
steps.extend(
SitePipelineOfflineTasks(
pipeline_vars=config.vars, fastly_var=config.pipeline_name
pipeline_vars=config.vars,
fastly_var=config.pipeline_name,
pipeline_name=config.pipeline_name,
)
)
return Job(
Expand Down
56 changes: 31 additions & 25 deletions content_sync/pipelines/definitions/concourse/site_pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def assert_base_build_tasks(tasks: list[dict], offline: bool): # noqa: FBT001
)
assert (
upload_online_build_task["on_success"]["try"]["params"]["text"]
== f'{{"version": "{config.vars['pipeline_name']}", "status": "succeeded"}}'
== f'{{"version": "{config.vars["pipeline_name"]}", "status": "succeeded"}}'
)
if is_dev:
assert set(
Expand All @@ -412,18 +412,21 @@ def assert_base_build_tasks(tasks: list[dict], offline: bool): # noqa: FBT001
open_discussions_webhook_step_online_params = json.loads(
clear_cdn_cache_online_success_steps[0]["try"]["params"]["text"]
)
assert (
open_discussions_webhook_step_online_params["webhook_key"]
== settings.OPEN_CATALOG_WEBHOOK_KEY
)
assert (
open_discussions_webhook_step_online_params["prefix"]
== f"{config.vars['url_path']}/"
)
assert (
open_discussions_webhook_step_online_params["version"]
== config.vars["pipeline_name"]
)
if branch_vars["pipeline_name"] == VERSION_DRAFT:
assert "webhook_key" not in open_discussions_webhook_step_online_params
elif branch_vars["pipeline_name"] == VERSION_LIVE:
assert (
open_discussions_webhook_step_online_params["webhook_key"]
== settings.OPEN_CATALOG_WEBHOOK_KEY
)
assert (
open_discussions_webhook_step_online_params["prefix"]
== f"{config.vars['url_path']}/"
)
assert (
open_discussions_webhook_step_online_params["version"]
== config.vars["pipeline_name"]
)
assert (
online_site_tasks[-1]["put"]
== pipeline_definition._offline_build_gate_identifier # noqa: SLF001
Expand Down Expand Up @@ -583,18 +586,21 @@ def assert_base_build_tasks(tasks: list[dict], offline: bool): # noqa: FBT001
open_discussions_webhook_step_offline_params = json.loads(
clear_cdn_cache_offline_success_steps[0]["try"]["params"]["text"]
)
assert (
open_discussions_webhook_step_offline_params["webhook_key"]
== settings.OPEN_CATALOG_WEBHOOK_KEY
)
assert (
open_discussions_webhook_step_offline_params["prefix"]
== f"{config.vars['url_path']}/"
)
assert (
open_discussions_webhook_step_offline_params["version"]
== config.vars["pipeline_name"]
)
if branch_vars["pipeline_name"] == VERSION_DRAFT:
assert "webhook_key" not in open_discussions_webhook_step_offline_params
elif branch_vars["pipeline_name"] == VERSION_LIVE:
assert (
open_discussions_webhook_step_offline_params["webhook_key"]
== settings.OPEN_CATALOG_WEBHOOK_KEY
)
assert (
open_discussions_webhook_step_offline_params["prefix"]
== f"{config.vars['url_path']}/"
)
assert (
open_discussions_webhook_step_offline_params["version"]
== config.vars["pipeline_name"]
)
expected_prefix = f"{prefix.strip('/')}/" if prefix != "" else prefix
site_dummy_var_source = get_dict_list_item_by_field(
rendered_definition["var_sources"], "name", "site"
Expand Down

0 comments on commit 6151e6f

Please sign in to comment.