(func)
| 398 | capture_response = kwargs.get("capture_response", False) |
| 399 | |
| 400 | def func_wrapper(func): |
| 401 | task_path = get_func_task_path(func) |
| 402 | |
| 403 | @wraps(func) |
| 404 | def _run_async(*args, **kwargs): |
| 405 | """ |
| 406 | This is the wrapping async function that replaces the function |
| 407 | that is decorated with @task. |
| 408 | Args: |
| 409 | These are just passed through to @task's func |
| 410 | |
| 411 | Assuming a valid service is passed to task() and it is run |
| 412 | inside a Lambda process (i.e. AWS_LAMBDA_FUNCTION_NAME exists), |
| 413 | it dispatches the function to be run through the service variable. |
| 414 | Otherwise, it runs the task synchronously. |
| 415 | |
| 416 | Returns: |
| 417 | In async mode, the object returned includes state of the dispatch. |
| 418 | For instance |
| 419 | |
| 420 | When outside of Lambda, the func passed to @task is run and we |
| 421 | return the actual value. |
| 422 | """ |
| 423 | lambda_function_name = lambda_function_name_arg or os.environ.get("AWS_LAMBDA_FUNCTION_NAME") |
| 424 | aws_region = aws_region_arg or os.environ.get("AWS_REGION") |
| 425 | |
| 426 | if (service in ASYNC_CLASSES) and (lambda_function_name): |
| 427 | send_result = ASYNC_CLASSES[service]( |
| 428 | lambda_function_name=lambda_function_name, |
| 429 | aws_region=aws_region, |
| 430 | capture_response=capture_response, |
| 431 | ).send(task_path, args, kwargs) |
| 432 | return send_result |
| 433 | else: |
| 434 | validate_json_serializable(*args, **kwargs) |
| 435 | return func(*args, **kwargs) |
| 436 | |
| 437 | update_wrapper(_run_async, func) |
| 438 | |
| 439 | _run_async.service = service |
| 440 | _run_async.sync = func |
| 441 | |
| 442 | return _run_async |
| 443 | |
| 444 | return func_wrapper(func) if func else func_wrapper |
| 445 |
no test coverage detected