Skip to content

Commit c6efc7d

Browse files
ppandit-sfdcjoroscoSF
authored andcommitted
Make computeType an input parameter (#33)
* Add argument for computeType
1 parent 428d713 commit c6efc7d

File tree

4 files changed

+86
-12
lines changed

4 files changed

+86
-12
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ datacustomcode run ./payload/entrypoint.py
7171
After modifying the `entrypoint.py` as needed, using any dependencies you add in the `.venv` virtual environment, you can run this script in Data Cloud:
7272
```zsh
7373
datacustomcode scan ./payload/entrypoint.py
74-
datacustomcode deploy --path ./payload --name my_custom_script
74+
datacustomcode deploy --path ./payload --name my_custom_script --compute-type CPU_L
7575
```
7676

7777
> [!TIP]
7878
> The `deploy` process can take several minutes. If you'd like more feedback on the underlying process, you can add `--debug` to the command like `datacustomcode --debug deploy --path ./payload --name my_custom_script`
79+
>
80+
> [!NOTE]
81+
> **Compute Types**: Choose the appropriate compute type based on your workload requirements:
82+
> - **CPU_L/CPU_XL/CPU_2XL/CPU_4XL**: Large, X-Large, 2X-Large and 4X-Large CPU instances for data processing
83+
> - Default is `CPU_2XL` which provides a good balance of performance and cost for most use cases
7984
8085
You can now use the Salesforce Data Cloud UI to find the created Data Transform and use the `Run Now` button to run it.
8186
Once the Data Transform run is successful, check the DLO your script is writing to and verify the correct records were added.
@@ -139,6 +144,7 @@ Options:
139144
- `--name TEXT`: Name of the transformation job [required]
140145
- `--version TEXT`: Version of the transformation job (default: "0.0.1")
141146
- `--description TEXT`: Description of the transformation job (default: "")
147+
- `--compute-type TEXT`: Compute type for the deployment (default: "CPU_XL"). Available options: CPU_L(Large), CPU_XL (Extra Large), CPU_2XL (2X Large), CPU_4XL (4X Large)
142148

143149
#### `datacustomcode init`
144150
Initialize a new development environment with a template.

src/datacustomcode/cli.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,43 @@ def zip(path: str):
8383
@click.option("--name", required=True)
8484
@click.option("--version", default="0.0.1")
8585
@click.option("--description", default="Custom Data Transform Code")
86-
def deploy(path: str, name: str, version: str, description: str):
86+
@click.option(
87+
"--cpu-size",
88+
default="CPU_2XL",
89+
help="""CPU size for deployment. Available options:
90+
91+
\b
92+
CPU_L - Large CPU instance
93+
CPU_XL - X-Large CPU instance
94+
CPU_2XL - 2X-Large CPU instance [DEFAULT]
95+
CPU_4XL - 4X-Large CPU instance
96+
97+
Choose based on your workload requirements.""",
98+
)
99+
def deploy(path: str, name: str, version: str, description: str, cpu_size: str):
87100
from datacustomcode.credentials import Credentials
88101
from datacustomcode.deploy import TransformationJobMetadata, deploy_full
89102

90103
logger.debug("Deploying project")
91104

105+
# Validate compute type
106+
from datacustomcode.deploy import COMPUTE_TYPES
107+
108+
if cpu_size not in COMPUTE_TYPES.keys():
109+
click.secho(
110+
f"Error: Invalid CPU size '{cpu_size}'. "
111+
f"Available options: {', '.join(COMPUTE_TYPES.keys())}",
112+
fg="red",
113+
)
114+
raise click.Abort()
115+
116+
logger.debug(f"Deploying with CPU size: {cpu_size}")
117+
92118
metadata = TransformationJobMetadata(
93119
name=name,
94120
version=version,
95121
description=description,
122+
computeType=COMPUTE_TYPES[cpu_size],
96123
)
97124
try:
98125
credentials = Credentials.from_available()

src/datacustomcode/deploy.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,25 @@
4444
AUTH_PATH = "services/oauth2/token"
4545
WAIT_FOR_DEPLOYMENT_TIMEOUT = 3000
4646

47+
# Available compute types for Data Cloud deployments.
48+
# Nomenclature used by COMPUTE_TYPES keys align with
49+
# compute instances provisioned by Data Cloud.
50+
COMPUTE_TYPES = {
51+
"CPU_L": "CPU_XS", # Large CPU instance
52+
"CPU_XL": "CPU_S", # X-Large CPU instance
53+
"CPU_2XL": "CPU_M", # 2X-Large CPU instance (default)
54+
"CPU_4XL": "CPU_L", # 4X-Large CPU instance
55+
}
56+
4757

4858
class TransformationJobMetadata(BaseModel):
4959
name: str
5060
version: str
5161
description: str
62+
computeType: str
63+
64+
def __init__(self, **data):
65+
super().__init__(**data)
5266

5367

5468
def _join_strip_url(*args: str) -> str:
@@ -123,7 +137,7 @@ def create_deployment(
123137
"name": metadata.name,
124138
"description": metadata.description,
125139
"version": metadata.version,
126-
"computeType": "CPU_M",
140+
"computeType": metadata.computeType,
127141
}
128142
logger.debug(f"Creating deployment {metadata.name}...")
129143
try:

tests/test_deploy.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ def test_create_deployment_success(self, mock_make_api_call):
434434
access_token="test_token", instance_url="https://instance.example.com"
435435
)
436436
metadata = TransformationJobMetadata(
437-
name="test_job", version="1.0.0", description="Test job"
437+
name="test_job",
438+
version="1.0.0",
439+
description="Test job",
440+
computeType="CPU_M",
438441
)
439442

440443
mock_make_api_call.return_value = {
@@ -454,7 +457,10 @@ def test_create_deployment_conflict(self, mock_make_api_call):
454457
access_token="test_token", instance_url="https://instance.example.com"
455458
)
456459
metadata = TransformationJobMetadata(
457-
name="test_job", version="1.0.0", description="Test job"
460+
name="test_job",
461+
version="1.0.0",
462+
description="Test job",
463+
computeType="CPU_M",
458464
)
459465

460466
# Mock HTTP error with 409 Conflict
@@ -571,7 +577,10 @@ def test_get_deployments(self, mock_make_api_call):
571577
access_token="test_token", instance_url="https://instance.example.com"
572578
)
573579
metadata = TransformationJobMetadata(
574-
name="test_job", version="1.0.0", description="Test job"
580+
name="test_job",
581+
version="1.0.0",
582+
description="Test job",
583+
computeType="CPU_M",
575584
)
576585

577586
mock_make_api_call.return_value = {"deploymentStatus": "Deployed"}
@@ -595,7 +604,10 @@ def test_wait_for_deployment_success(
595604
access_token="test_token", instance_url="https://instance.example.com"
596605
)
597606
metadata = TransformationJobMetadata(
598-
name="test_job", version="1.0.0", description="Test job"
607+
name="test_job",
608+
version="1.0.0",
609+
description="Test job",
610+
computeType="CPU_M",
599611
)
600612
callback = MagicMock()
601613

@@ -622,7 +634,10 @@ def test_wait_for_deployment_timeout(
622634
access_token="test_token", instance_url="https://instance.example.com"
623635
)
624636
metadata = TransformationJobMetadata(
625-
name="test_job", version="1.0.0", description="Test job"
637+
name="test_job",
638+
version="1.0.0",
639+
description="Test job",
640+
computeType="CPU_M",
626641
)
627642

628643
# Mock time to simulate timeout
@@ -699,7 +714,10 @@ def test_create_data_transform(self, mock_make_api_call, mock_get_config):
699714
access_token="test_token", instance_url="https://instance.example.com"
700715
)
701716
metadata = TransformationJobMetadata(
702-
name="test_job", version="1.0.0", description="Test job"
717+
name="test_job",
718+
version="1.0.0",
719+
description="Test job",
720+
computeType="CPU_M",
703721
)
704722

705723
mock_get_config.return_value = DataTransformConfig(
@@ -762,7 +780,10 @@ def test_deploy_full(
762780
login_url="https://example.com",
763781
)
764782
metadata = TransformationJobMetadata(
765-
name="test_job", version="1.0.0", description="Test job"
783+
name="test_job",
784+
version="1.0.0",
785+
description="Test job",
786+
computeType="CPU_M",
766787
)
767788
callback = MagicMock()
768789

@@ -799,7 +820,10 @@ def test_run_data_transform(self, mock_make_api_call):
799820
access_token="test_token", instance_url="https://instance.example.com"
800821
)
801822
metadata = TransformationJobMetadata(
802-
name="test_job", version="1.0.0", description="Test job"
823+
name="test_job",
824+
version="1.0.0",
825+
description="Test job",
826+
computeType="CPU_M",
803827
)
804828

805829
mock_make_api_call.return_value = {"status": "Running"}
@@ -839,7 +863,10 @@ def test_deploy_full_happy_path(
839863
login_url="https://example.com",
840864
)
841865
metadata = TransformationJobMetadata(
842-
name="test_job", version="1.0.0", description="Test job"
866+
name="test_job",
867+
version="1.0.0",
868+
description="Test job",
869+
computeType="CPU_M",
843870
)
844871
callback = MagicMock()
845872

0 commit comments

Comments
 (0)