23
23
from sentry .tasks .base import instrumented_task
24
24
from sentry .taskworker .config import TaskworkerConfig
25
25
from sentry .taskworker .namespaces import attachments_tasks
26
+ from sentry .taskworker .retry import Retry
26
27
from sentry .utils .sdk import bind_organization_context
27
28
28
29
logger = logging .getLogger (__name__ )
32
33
name = "sentry.preprod.tasks.assemble_preprod_artifact" ,
33
34
queue = "assemble" ,
34
35
silo_mode = SiloMode .REGION ,
36
+ retry = Retry (times = 3 ),
35
37
taskworker_config = TaskworkerConfig (
36
38
namespace = attachments_tasks ,
37
39
processing_deadline_duration = 30 ,
@@ -62,6 +64,7 @@ def assemble_preprod_artifact(
62
64
},
63
65
)
64
66
67
+ preprod_artifact = None
65
68
try :
66
69
organization = Organization .objects .get_from_cache (pk = org_id )
67
70
project = Project .objects .get (id = project_id , organization = organization )
@@ -81,67 +84,64 @@ def assemble_preprod_artifact(
81
84
82
85
if existing_artifact :
83
86
logger .info (
84
- "PreprodArtifact already exists for this checksum, skipping assembly " ,
87
+ "PreprodArtifact already exists for this checksum, using existing artifact " ,
85
88
extra = {
86
89
"preprod_artifact_id" : existing_artifact .id ,
87
90
"project_id" : project_id ,
88
91
"organization_id" : org_id ,
89
92
"checksum" : checksum ,
90
93
},
91
94
)
95
+ preprod_artifact = existing_artifact
96
+ else :
92
97
set_assemble_status (
93
- AssembleTask .PREPROD_ARTIFACT , project_id , checksum , ChunkFileState .OK
94
- )
95
- return
96
-
97
- set_assemble_status (
98
- AssembleTask .PREPROD_ARTIFACT , project_id , checksum , ChunkFileState .ASSEMBLING
99
- )
100
-
101
- assemble_result = assemble_file (
102
- task = AssembleTask .PREPROD_ARTIFACT ,
103
- org_or_project = project ,
104
- name = f"preprod-artifact-{ uuid .uuid4 ().hex } " ,
105
- checksum = checksum ,
106
- chunks = chunks ,
107
- file_type = "preprod.artifact" ,
108
- )
109
-
110
- if assemble_result is None :
111
- return
112
-
113
- build_config = None
114
- if build_configuration :
115
- build_config , _ = PreprodBuildConfiguration .objects .get_or_create (
116
- project = project ,
117
- name = build_configuration ,
98
+ AssembleTask .PREPROD_ARTIFACT , project_id , checksum , ChunkFileState .ASSEMBLING
118
99
)
119
100
120
- # Create PreprodArtifact record
121
- preprod_artifact = PreprodArtifact .objects .create (
122
- project = project ,
123
- file_id = assemble_result .bundle .id ,
124
- build_configuration = build_config ,
125
- state = PreprodArtifact .ArtifactState .UPLOADED ,
126
- )
101
+ assemble_result = assemble_file (
102
+ task = AssembleTask .PREPROD_ARTIFACT ,
103
+ org_or_project = project ,
104
+ name = f"preprod-artifact-{ uuid .uuid4 ().hex } " ,
105
+ checksum = checksum ,
106
+ chunks = chunks ,
107
+ file_type = "preprod.artifact" ,
108
+ )
127
109
128
- logger .info (
129
- "Created preprod artifact" ,
130
- extra = {
131
- "preprod_artifact_id" : preprod_artifact .id ,
132
- "project_id" : project_id ,
133
- "organization_id" : org_id ,
134
- "checksum" : checksum ,
135
- },
136
- )
110
+ if assemble_result is None :
111
+ logger .warning (
112
+ "Assemble result is None, returning early" ,
113
+ extra = {
114
+ "project_id" : project_id ,
115
+ "organization_id" : org_id ,
116
+ "checksum" : checksum ,
117
+ },
118
+ )
119
+ return
120
+
121
+ build_config = None
122
+ if build_configuration :
123
+ build_config , _ = PreprodBuildConfiguration .objects .get_or_create (
124
+ project = project ,
125
+ name = build_configuration ,
126
+ )
127
+
128
+ # Create PreprodArtifact record
129
+ preprod_artifact , _ = PreprodArtifact .objects .get_or_create (
130
+ project = project ,
131
+ file_id = assemble_result .bundle .id ,
132
+ build_configuration = build_config ,
133
+ state = PreprodArtifact .ArtifactState .UPLOADED ,
134
+ )
137
135
138
- # where next set of changes will happen
139
- # TODO: Trigger artifact processing (size analysis, etc.)
140
- # This is where you'd add logic to:
141
- # 1. create_or_update a new row in the Commit table as well (once base_sha is added as a column to it)
142
- # 2. Detect artifact type (iOS/Android/etc.)
143
- # 3. Queue processing tasks
144
- # 4. Update state to PROCESSED when done (also update the date_built value to reflect when the artifact was built, among other fields)
136
+ logger .info (
137
+ "Created preprod artifact" ,
138
+ extra = {
139
+ "preprod_artifact_id" : preprod_artifact .id ,
140
+ "project_id" : project_id ,
141
+ "organization_id" : org_id ,
142
+ "checksum" : checksum ,
143
+ },
144
+ )
145
145
146
146
except Exception as e :
147
147
sentry_sdk .capture_exception (e )
@@ -165,27 +165,25 @@ def assemble_preprod_artifact(
165
165
# Mark assembly as successful since the artifact was created successfully
166
166
set_assemble_status (AssembleTask .PREPROD_ARTIFACT , project_id , checksum , ChunkFileState .OK )
167
167
168
- produce_preprod_artifact_to_kafka (
169
- project_id = project_id ,
170
- organization_id = org_id ,
171
- artifact_id = preprod_artifact .id ,
172
- checksum = checksum ,
173
- git_sha = git_sha ,
174
- build_configuration = build_configuration ,
175
- )
168
+ if preprod_artifact :
169
+ produce_preprod_artifact_to_kafka (
170
+ project_id = project_id ,
171
+ organization_id = org_id ,
172
+ artifact_id = preprod_artifact .id ,
173
+ )
176
174
177
- logger .info (
178
- "Finished preprod artifact assembly and Kafka dispatch" ,
179
- extra = {
180
- "preprod_artifact_id" : preprod_artifact .id ,
181
- "project_id" : project_id ,
182
- "organization_id" : org_id ,
183
- "checksum" : checksum ,
184
- },
185
- )
175
+ logger .info (
176
+ "Finished preprod artifact assembly and Kafka dispatch" ,
177
+ extra = {
178
+ "preprod_artifact_id" : preprod_artifact .id ,
179
+ "project_id" : project_id ,
180
+ "organization_id" : org_id ,
181
+ "checksum" : checksum ,
182
+ },
183
+ )
186
184
187
185
188
- def _assemble_preprod_artifact (
186
+ def _assemble_preprod_artifact_file (
189
187
assemble_task : str ,
190
188
project_id : int ,
191
189
org_id : int ,
@@ -194,7 +192,7 @@ def _assemble_preprod_artifact(
194
192
callback : Callable [[AssembleResult , Any ], None ],
195
193
):
196
194
logger .info (
197
- "Starting preprod artifact assembly" ,
195
+ "Starting preprod file assembly" ,
198
196
extra = {
199
197
"timestamp" : datetime .datetime .now ().isoformat (),
200
198
"project_id" : project_id ,
@@ -229,7 +227,7 @@ def _assemble_preprod_artifact(
229
227
callback (assemble_result , project )
230
228
except Exception as e :
231
229
logger .exception (
232
- "Failed to assemble preprod artifact " ,
230
+ "Failed to assemble preprod file " ,
233
231
extra = {
234
232
"project_id" : project_id ,
235
233
"organization_id" : org_id ,
@@ -322,7 +320,7 @@ def assemble_preprod_artifact_size_analysis(
322
320
"""
323
321
Creates a size analysis file for a preprod artifact from uploaded chunks.
324
322
"""
325
- _assemble_preprod_artifact (
323
+ _assemble_preprod_artifact_file (
326
324
AssembleTask .PREPROD_ARTIFACT_SIZE_ANALYSIS ,
327
325
project_id ,
328
326
org_id ,
0 commit comments