Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1063110: Use a global validator instance.
  • Loading branch information
mihneadb committed Aug 10, 2015
1 parent 20f5c74 commit 0793006
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions bin/worker.js
Expand Up @@ -173,6 +173,9 @@ async function main () {
config.scheduler =
new taskcluster.Scheduler({ credentials: config.taskcluster });

config.validator = await base.validator();
config.validator.register(require('../schemas/payload'));

// Only catch these metrics when running on aws host. Running within
// test environment causes numerous issues.
if (host === 'aws') {
Expand Down
9 changes: 5 additions & 4 deletions lib/task.js
Expand Up @@ -14,12 +14,14 @@ import getHostname from './util/hostname';
import { hasPrefixedScopes } from './util/scopes';
import { pullDockerImage, IMAGE_ERROR } from './pull_image_to_stream';
import { scopeMatch } from 'taskcluster-base/utils';
import payloadSchema from '../schemas/payload';
import waitForEvent from './wait_for_event';
import _ from 'lodash';

let debug = new Debug('runTask');

const PAYLOAD_SCHEMA =
'http://schemas.taskcluster.net/docker-worker/v1/payload.json#';

// TODO probably a terrible error message, look at making it better later
const CANCEL_ERROR = 'Error: Task was canceled by another entity. This can happen using ' +
'a taskcluster client or by cancelling a task within Treeherder.';
Expand Down Expand Up @@ -598,9 +600,8 @@ export default class Task {
return await this.abortRun(this.taskState);
}
// Validate the schema!
let payloadErrors = await validator().then((validator) => {
return validator.check(this.task.payload, payloadSchema);
});
let payloadErrors = this.runtime.validator.check(this.task.payload,
PAYLOAD_SCHEMA)

if (payloadErrors) {
// Inform the user that this task has failed due to some configuration
Expand Down

0 comments on commit 0793006

Please sign in to comment.