Creates a job, setting it as a child of the specified parent if provided. Args: parent (optional): The parent job, if any. **kwargs: The fields to set on the created job. Returns: The created job.
(self, parent=None, **kwargs)
| 256 | """ |
| 257 | |
| 258 | def create(self, parent=None, **kwargs): |
| 259 | """ |
| 260 | Creates a job, setting it as a child of the specified parent if provided. |
| 261 | |
| 262 | Args: |
| 263 | parent (optional): The parent job, if any. |
| 264 | **kwargs: The fields to set on the created job. |
| 265 | |
| 266 | Returns: |
| 267 | The created job. |
| 268 | """ |
| 269 | if parent: |
| 270 | return parent.add_child(**kwargs) |
| 271 | # try multiple times hoping to for no race conditions |
| 272 | total_attempt_number = 5 |
| 273 | for attempt in range(0, total_attempt_number): |
| 274 | try: |
| 275 | return self.model.add_root(**kwargs) |
| 276 | except IntegrityError: |
| 277 | logger.warning(f"Found race condition for {kwargs['name']}. Trying again to calculate path.") |
| 278 | if attempt == total_attempt_number - 1: |
| 279 | raise |
| 280 | |
| 281 | def delete(self, *args, **kwargs): |
| 282 | """ |
no outgoing calls