Skip to content
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

[Issue #3520] Add the ability to only process a subset of opportunity attachments #3564

Merged
merged 31 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
33dabef
WIP
chouinar Jan 6, 2025
7c3c111
Merge branch 'main' into chouinar/3271-attachment-transform
chouinar Jan 7, 2025
a442c5e
WIP
chouinar Jan 7, 2025
930ded9
Cleanup
chouinar Jan 7, 2025
e8c9ba1
Merge branch 'main' into chouinar/3271-attachment-transform
chouinar Jan 7, 2025
0919936
Adding metric validation to tests
chouinar Jan 7, 2025
0e6b3e2
WIP
chouinar Jan 7, 2025
b810a12
WIP
chouinar Jan 9, 2025
93f1778
WIP
chouinar Jan 10, 2025
8bb1643
Cleanup
chouinar Jan 10, 2025
b3fa525
Fix something we shouldn't have
chouinar Jan 10, 2025
03b917f
[Issue #3500] Handle opportunity attachments when opp deleted or is p…
chouinar Jan 13, 2025
fa4263f
Fix tests
chouinar Jan 13, 2025
9cee95f
Merge branch 'main' into chouinar/file-attachment-transform
chouinar Jan 15, 2025
d0ac166
Fix
chouinar Jan 15, 2025
9612cdf
Merge branch 'chouinar/file-attachment-transform' into chouinar/3500-…
chouinar Jan 15, 2025
ff9918f
logging message
chouinar Jan 15, 2025
1327f9a
Fix
chouinar Jan 15, 2025
e73f74a
Fix
chouinar Jan 15, 2025
1196dcc
Merge branch 'chouinar/file-attachment-transform' into chouinar/3500-…
chouinar Jan 15, 2025
0246275
[Issue #3520] Make it possible to run partial attachment transform
chouinar Jan 15, 2025
1ffb41c
Fix test bucket to not have same name
chouinar Jan 15, 2025
f7f2044
Merge branch 'chouinar/file-attachment-transform' into chouinar/3500-…
chouinar Jan 15, 2025
51453d6
Merge branch 'chouinar/3500-draft-delete-opp-attachments' into chouin…
chouinar Jan 15, 2025
b1fce6a
WIP
chouinar Jan 15, 2025
9c48c81
Fix bug
chouinar Jan 15, 2025
ba97628
Merge branch 'chouinar/3500-draft-delete-opp-attachments' into chouin…
chouinar Jan 15, 2025
d86aa3f
Merge branch 'main' into chouinar/file-attachment-transform
chouinar Jan 16, 2025
64c8369
Merge branch 'chouinar/file-attachment-transform' into chouinar/3500-…
chouinar Jan 16, 2025
7f4dc74
Merge branch 'chouinar/3500-draft-delete-opp-attachments' into chouin…
chouinar Jan 16, 2025
c2fdac4
Merge branch 'main' into chouinar/3520-attachment-subset
chouinar Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def fetch_with_opportunity(
source_model: Type[transform_constants.S],
destination_model: Type[transform_constants.D],
join_clause: Sequence,
batch_size: int = 5000,
) -> list[Tuple[transform_constants.S, transform_constants.D | None, Opportunity | None]]:
# Similar to the above fetch function, but also grabs an opportunity record
# Note that this requires your source_model to have an opportunity_id field defined.
Expand All @@ -134,7 +135,7 @@ def fetch_with_opportunity(
isouter=True,
)
.where(source_model.transformed_at.is_(None))
.execution_options(yield_per=5000)
.execution_options(yield_per=batch_size)
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
from src.services.opportunity_attachments import attachment_util
from src.task.task import Task
from src.util import file_util
from src.util.env_config import PydanticBaseEnvConfig

logger = logging.getLogger(__name__)


class TransformOpportunityAttachmentConfig(PydanticBaseEnvConfig):
# This is just for testing, we want to be able to only
# import a few attachments when manually testing.
total_attachments_to_process: int | None = None


class TransformOpportunityAttachment(AbstractTransformSubTask):

def __init__(self, task: Task, s3_config: S3Config | None = None):
Expand All @@ -27,13 +34,20 @@ def __init__(self, task: Task, s3_config: S3Config | None = None):

self.s3_config = s3_config

self.attachment_config = TransformOpportunityAttachmentConfig()

def transform_records(self) -> None:

# Fetch staging attachment / our attachment / opportunity groups
records = self.fetch_with_opportunity(
TsynopsisAttachment,
OpportunityAttachment,
[TsynopsisAttachment.syn_att_id == OpportunityAttachment.attachment_id],
batch_size=(
self.attachment_config.total_attachments_to_process
if self.attachment_config.total_attachments_to_process
else 1000
),
)

self.process_opportunity_attachment_group(records)
Expand All @@ -44,8 +58,19 @@ def process_opportunity_attachment_group(
tuple[TsynopsisAttachment, OpportunityAttachment | None, Opportunity | None]
],
) -> None:

records_processed = 0
for source_attachment, target_attachment, opportunity in records:
try:
# Note we increment first in case there are errors, want it to always increment
records_processed += 1
if (
self.attachment_config.total_attachments_to_process is not None
and self.attachment_config.total_attachments_to_process <= records_processed
):
logger.info("Ending processing early due to configuration")
break

self.process_opportunity_attachment(
source_attachment, target_attachment, opportunity
)
Expand Down