Skip to content

Commit e1bfd75

Browse files
authored
Merge pull request mozilla-releng#698 from bhearsum/run-id
feat: expose RUN_ID and TASKCLUSTER_ROOT_URL to scriptworkers
2 parents 89ce7f6 + 3618009 commit e1bfd75

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/scriptworker/task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ async def run_task(context, to_cancellable_process):
657657
"""
658658
env = deepcopy(os.environ)
659659
env["TASK_ID"] = context.task_id or "None"
660+
env["RUN_ID"] = str(get_run_id(context.claim_task))
661+
env["TASKCLUSTER_ROOT_URL"] = context.config["taskcluster_root_url"]
660662
kwargs = {"stdout": PIPE, "stderr": PIPE, "stdin": None, "close_fds": True, "preexec_fn": lambda: os.setsid(), "env": env} # pragma: no branch
661663

662664
subprocess = await asyncio.create_subprocess_exec(*context.config["task_script"], **kwargs)

tests/test_artifacts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def context(rw_context):
3939
"credentials": {"a": "b"},
4040
"status": {"taskId": "taskId"},
4141
"task": {"expires": now.shift(days=2).isoformat(), "dependencies": ["dependency1", "dependency2"], "taskGroupId": "dependency0", "payload": {}},
42-
"runId": "runId",
42+
"runId": 0,
4343
}
4444
yield rw_context
4545

@@ -142,7 +142,7 @@ async def test_create_artifact(context, fake_session, successful_queue):
142142
await create_artifact(context, path, "public/env/one.txt", content_type="text/plain", content_encoding=None, expires=expires)
143143
assert successful_queue.info == [
144144
"createArtifact",
145-
("taskId", "runId", "public/env/one.txt", {"storageType": "s3", "expires": expires, "contentType": "text/plain"}),
145+
("taskId", 0, "public/env/one.txt", {"storageType": "s3", "expires": expires, "contentType": "text/plain"}),
146146
{},
147147
]
148148

tests/test_task.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ def mobile_context(mobile_rw_context):
4141
def _craft_context(rw_context):
4242
rw_context.config["reclaim_interval"] = 0.001
4343
rw_context.config["task_max_timeout"] = 1
44-
rw_context.config["task_script"] = ("bash", "-c", ">&2 echo bar && echo foo && exit 1")
44+
rw_context.config["taskcluster_root_url"] = "https://tc"
45+
rw_context.config["task_script"] = ("bash", "-c", ">&2 echo $TASK_ID && echo $RUN_ID && echo $TASKCLUSTER_ROOT_URL && exit 1")
4546
rw_context.claim_task = {
4647
"credentials": {"a": "b"},
4748
"status": {"taskId": "taskId"},
4849
"task": {"dependencies": ["dependency1", "dependency2"], "taskGroupId": "dependency0"},
49-
"runId": "runId",
50+
"runId": 0,
5051
}
5152
return rw_context
5253

@@ -482,7 +483,7 @@ def test_is_action(task, expected):
482483
def test_prepare_to_run_task(context):
483484
claim_task = context.claim_task
484485
context.claim_task = None
485-
expected = {"taskId": "taskId", "runId": "runId"}
486+
expected = {"taskId": "taskId", "runId": 0}
486487
path = os.path.join(context.config["work_dir"], "current_task_info.json")
487488
assert swtask.prepare_to_run_task(context, claim_task) == expected
488489
assert os.path.exists(path)
@@ -496,7 +497,7 @@ def test_prepare_to_run_task(context):
496497
async def test_run_task(context):
497498
status = await swtask.run_task(context, noop_to_cancellable_process)
498499
log_file = log.get_log_filename(context)
499-
assert read(log_file) in ("bar\nfoo\nexit code: 1\n", "foo\nbar\nexit code: 1\n")
500+
assert read(log_file) in ("taskId\n0\nhttps://tc\nexit code: 1\n", "taskId\n0\nhttps://tc\nexit code: 1\n")
500501
assert status == 1
501502

502503

@@ -570,29 +571,29 @@ async def test_run_task_timeout(context):
570571
async def test_reportCompleted(context, successful_queue):
571572
context.temp_queue = successful_queue
572573
await swtask.complete_task(context, 0)
573-
assert successful_queue.info == ["reportCompleted", ("taskId", "runId"), {}]
574+
assert successful_queue.info == ["reportCompleted", ("taskId", 0), {}]
574575

575576

576577
@pytest.mark.asyncio
577578
async def test_reportFailed(context, successful_queue):
578579
context.temp_queue = successful_queue
579580
await swtask.complete_task(context, 1)
580-
assert successful_queue.info == ["reportFailed", ("taskId", "runId"), {}]
581+
assert successful_queue.info == ["reportFailed", ("taskId", 0), {}]
581582

582583

583584
@pytest.mark.asyncio
584585
async def test_reportException(context, successful_queue):
585586
context.temp_queue = successful_queue
586587
await swtask.complete_task(context, 2)
587-
assert successful_queue.info == ["reportException", ("taskId", "runId", {"reason": "worker-shutdown"}), {}]
588+
assert successful_queue.info == ["reportException", ("taskId", 0, {"reason": "worker-shutdown"}), {}]
588589

589590

590591
@pytest.mark.parametrize("exit_code", (245, 241))
591592
@pytest.mark.asyncio
592593
async def test_reversed_statuses(context, successful_queue, exit_code):
593594
context.temp_queue = successful_queue
594595
await swtask.complete_task(context, exit_code)
595-
assert successful_queue.info == ["reportException", ("taskId", "runId", {"reason": context.config["reversed_statuses"][exit_code]}), {}]
596+
assert successful_queue.info == ["reportException", ("taskId", 0, {"reason": context.config["reversed_statuses"][exit_code]}), {}]
596597

597598

598599
# complete_task {{{1

tests/test_worker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
# constants helpers and fixtures {{{1
2626
@pytest.fixture(scope="function")
2727
def context(rw_context):
28+
rw_context.config["taskcluster_root_url"] = "https://tc"
2829
rw_context.credentials_timestamp = arrow.utcnow().shift(minutes=-10).int_timestamp
30+
rw_context.claim_task = {
31+
"credentials": {"a": "b"},
32+
"status": {"taskId": "taskId"},
33+
"task": {"dependencies": ["dependency1", "dependency2"], "taskGroupId": "dependency0"},
34+
"runId": 0,
35+
}
2936
yield rw_context
3037

3138

0 commit comments

Comments
 (0)