Skip to content

Commit

Permalink
Merge pull request #141 from escapewindow/tweaks
Browse files Browse the repository at this point in the history
add `work_dir/current_task_info.json`. also upload `.diff` files as text/plain
  • Loading branch information
escapewindow committed Aug 21, 2017
2 parents 76b7aec + 5011329 commit 9fa05aa
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.2.0] - 2017-08-21
### Added
- added `prepare_to_run_task` to create a new `current_task_info.json` in `work_dir` for easier debugging.

### Changed
- `.diff` files now upload as `text/plain`.

## [4.1.4] - 2017-08-16
### Changed
- updated the decision + docker-image `workerType`s
Expand Down
2 changes: 1 addition & 1 deletion scriptworker/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


_GZIP_SUPPORTED_CONTENT_TYPE = ('text/plain', 'application/json', 'text/html', 'application/xml')
_EXTENSIONS_TO_FORCE_TO_PLAIN_TEXT = ('.asc', '.log')
_EXTENSIONS_TO_FORCE_TO_PLAIN_TEXT = ('.asc', '.diff', '.log')


def _force_mimetypes_to_plain_text():
Expand Down
29 changes: 29 additions & 0 deletions scriptworker/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def get_decision_task_id(task):
return task['taskGroupId']


# get_worker_type {{{1
def get_worker_type(task):
"""Given a task dict, return the workerType.
Expand All @@ -93,6 +94,34 @@ def get_worker_type(task):
return task['workerType']


# prepare_to_run_task {{{1
def prepare_to_run_task(context, claim_task):
"""Given a `claim_task` json dict, prepare the `context` and `work_dir`.
Set `context.claim_task`, and write a `work_dir/current_task_info.json`
Args:
context (scriptworker.context.Context): the scriptworker context.
claim_task (dict): the claim_task dict.
Returns:
dict: the contents of `current_task_info.json`
"""
current_task_info = {}
context.claim_task = claim_task
current_task_info['taskId'] = get_task_id(claim_task)
current_task_info['runId'] = get_run_id(claim_task)
log.info("Going to run taskId {taskId} runId {runId}!".format(
**current_task_info
))
context.write_json(
os.path.join(context.config['work_dir'], 'current_task_info.json'),
current_task_info, "Writing current task info to {path}..."
)
return current_task_info


# run_task {{{1
async def run_task(context):
"""Run the task, sending stdout+stderr to files.
Expand Down
14 changes: 14 additions & 0 deletions scriptworker/test/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import aiohttp
import asyncio
import glob
import json
import mock
import os
import pprint
Expand Down Expand Up @@ -59,6 +60,19 @@ def test_get_worker_type(defn, result):
assert task.get_worker_type(defn) == result


# prepare_to_run_task {{{1
def test_prepare_to_run_task(context):
claim_task = context.claim_task
context.claim_task = None
expected = {'taskId': 'taskId', 'runId': 'runId'}
path = os.path.join(context.config['work_dir'], 'current_task_info.json')
assert task.prepare_to_run_task(context, claim_task) == expected
assert os.path.exists(path)
with open(path) as fh:
contents = json.load(fh)
assert contents == expected


# run_task {{{1
def test_run_task(context, event_loop):
status = event_loop.run_until_complete(
Expand Down
3 changes: 3 additions & 0 deletions scriptworker/test/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def run_task(*args, **kwargs):
context.queue = successful_queue
mocker.patch.object(worker, "claim_work", new=claim_work)
mocker.patch.object(worker, "reclaim_task", new=noop_async)
mocker.patch.object(worker, "prepare_to_run_task", new=noop_sync)
mocker.patch.object(worker, "run_task", new=run_task)
mocker.patch.object(worker, "ChainOfTrust", new=fake_cot)
mocker.patch.object(worker, "verify_chain_of_trust", new=noop_async)
Expand All @@ -125,6 +126,7 @@ def test_mocker_run_loop_noop(context, successful_queue, event_loop, mocker):
context.queue = successful_queue
mocker.patch.object(worker, "claim_work", new=noop_async)
mocker.patch.object(worker, "reclaim_task", new=noop_async)
mocker.patch.object(worker, "prepare_to_run_task", new=noop_sync)
mocker.patch.object(worker, "run_task", new=noop_async)
mocker.patch.object(worker, "generate_cot", new=noop_sync)
mocker.patch.object(worker, "upload_artifacts", new=noop_async)
Expand Down Expand Up @@ -160,6 +162,7 @@ async def run_task(*args, **kwargs):
context.queue = successful_queue
mocker.patch.object(worker, "claim_work", new=claim_work)
mocker.patch.object(worker, "reclaim_task", new=noop_async)
mocker.patch.object(worker, "prepare_to_run_task", new=noop_sync)
if func_to_raise == "run_task":
mocker.patch.object(worker, "run_task", new=fail)
else:
Expand Down
2 changes: 1 addition & 1 deletion scriptworker/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_version_string(version):

# 1}}}
# Semantic versioning 2.0.0 http://semver.org/
__version__ = (4, 1, 4)
__version__ = (4, 2, 0)
__version_string__ = get_version_string(__version__)


Expand Down
6 changes: 3 additions & 3 deletions scriptworker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from scriptworker.cot.verify import ChainOfTrust, verify_chain_of_trust
from scriptworker.gpg import get_tmp_base_gpg_home_dir, is_lockfile_present, rm_lockfile
from scriptworker.exceptions import ScriptWorkerException
from scriptworker.task import claim_work, complete_task, reclaim_task, run_task, worst_level
from scriptworker.task import claim_work, complete_task, prepare_to_run_task, \
reclaim_task, run_task, worst_level
from scriptworker.utils import cleanup, rm

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,9 +48,8 @@ async def run_loop(context, creds_key="credentials"):
# run them sequentially. A side effect is our return status will
# be the status of the final task run.
for task_defn in tasks.get('tasks', []):
context.claim_task = task_defn
log.info("Going to run task!")
status = 0
prepare_to_run_task(context, task_defn)
loop.create_task(reclaim_task(context, context.task))
try:
if context.config['verify_chain_of_trust']:
Expand Down
10 changes: 5 additions & 5 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": [
4,
1,
4
],
"version_string": "4.1.4"
4,
2,
0
],
"version_string": "4.2.0"
}

0 comments on commit 9fa05aa

Please sign in to comment.