Skip to content

Commit

Permalink
vdk-control-cli: vdk list -mmm to return executions (#1818)
Browse files Browse the repository at this point in the history
Added one more "m" in `vdk list -mmmm` to show execution details It is
aligned somewhat how the UI looks.
Generally this is useful and quick solution if UI is not available.

Testing Done: unit tests

---------

Signed-off-by: Antoni Ivanov <[email protected]>
  • Loading branch information
antoniivanov authored Apr 4, 2023
1 parent 5f30a8a commit 8b058c6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def job_to_dict(job: Dict):
res["deployed_by"] = deployments[0]["lastDeployedBy"]
if "lastDeployedDate" in deployments[0]:
res["deployed_date"] = deployments[0]["lastDeployedDate"]
if "executions" in deployments[0] and len(deployments[0]["executions"]) > 0:
last_execution = deployments[0]["executions"][0]
res["last_execution_status"] = last_execution.get("status")
res["last_execution_date"] = last_execution.get("startTime")
res["last_execution_type"] = last_execution.get("type")
res["last_execution_started_by"] = last_execution.get("startedBy")
else:
res["status"] = "NOT_DEPLOYED"
if "contacts" in job["config"]:
Expand Down Expand Up @@ -157,6 +163,11 @@ def build_jobs_query(
job_contacts.add("notifiedOnJobDeploy").add("notifiedOnJobSuccess").add(
"notifiedOnJobFailurePlatformError"
).add("notifiedOnJobFailureUserError")
if more_details >= 3:
executions = jobs_deployments.add_return_new("executions")
executions.add("id").add("type").add("status").add("startTime").add(
"endTime"
).add("opId").add("startedBy")

query = jobs_builder.build()
log.debug("Jobs list (graphql) query: " + query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,29 @@ def get_example_data_job_query_response():
"description": "test-job description",
"schedule": {"schedule_cron": "11 23 5 8 1"},
},
"deployments": [{"enabled": True}],
"deployments": [
{
"enabled": True,
"executions": [
{
"id": "test-job-1680117000",
"status": "SUCCEEDED",
"startTime": "2021-08-02T23:11:00.000Z",
"endTime": "2021-08-02T23:22:00.000Z",
"startedBy": "manual/test-user",
"type": "MANUAL",
},
{
"id": "test-job-1680113400",
"status": "USER_ERROR",
"startTime": "2021-08-02T22:22:00.000Z",
"endTime": "2021-08-02T22:55:00.000Z",
"startedBy": "scheduled/test-user",
"type": "SCHEDULED",
},
],
}
],
},
{
"jobName": "test-job-2",
Expand All @@ -39,7 +61,21 @@ def get_example_data_job_query_response():
"description": "test-job-2 description",
"schedule": {"schedule_cron": "11 23 5 8 1"},
},
"deployments": [{"enabled": False}],
"deployments": [
{
"enabled": False,
"executions": [
{
"id": "test-job-2-123",
"status": "SUCCEEDED",
"startTime": "2021-08-01T23:11:00.000Z",
"endTime": "2021-08-01T23:22:00.000Z",
"startedBy": "manual/user",
"type": "MANUAL",
}
],
}
],
},
{
"jobName": "test-job-3",
Expand Down Expand Up @@ -70,6 +106,51 @@ def test_list_default_all(httpserver: PluginHTTPServer, tmpdir: LocalPath):
), f"expected data not found in output: {result.output} "


def test_list_default_all_3_mores(httpserver: PluginHTTPServer, tmpdir: LocalPath):
rest_api_url = httpserver.url_for("")

response = get_example_data_job_query_response()

httpserver.expect_request(
uri="/data-jobs/for-team/test-team/jobs"
).respond_with_json(response)

runner = CliRunner()
result = runner.invoke(
list_command, ["-t", "test-team", "-mmm", "-u", rest_api_url, "-o", "json"]
)

assert_click_status(result, 0)

expected_json = [
{
"job_name": "test-job",
"job_team": "test-team",
"status": "ENABLED",
"last_execution_status": "SUCCEEDED",
"last_execution_date": "2021-08-02T23:11:00.000Z",
"last_execution_type": "MANUAL",
"last_execution_started_by": "manual/test-user",
},
{
"job_name": "test-job-2",
"job_team": "test-team",
"status": "DISABLED",
"last_execution_status": "SUCCEEDED",
"last_execution_date": "2021-08-01T23:11:00.000Z",
"last_execution_type": "MANUAL",
"last_execution_started_by": "manual/user",
},
{"job_name": "test-job-3", "job_team": "test-team", "status": "NOT_DEPLOYED"},
]

output_json = json.loads(result.output)

assert (
output_json == expected_json
), f"expected data not found in output: {result.output} "


def test_list_all(httpserver: PluginHTTPServer, tmpdir: LocalPath):
rest_api_url = httpserver.url_for("")
response = get_data_job_query_response(
Expand Down

0 comments on commit 8b058c6

Please sign in to comment.