Skip to content

Instantly share code, notes, and snippets.

@jonasfj
Last active November 3, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasfj/db42410281c6034071ea2e742e09acca to your computer and use it in GitHub Desktop.
Save jonasfj/db42410281c6034071ea2e742e09acca to your computer and use it in GitHub Desktop.
# Configuration file for taskcluster-worker with script engine as could be
# used for autophone.
transforms:
- abs
- env
config:
credentials:
clientId: {$env: TASKCLUSTER_CLIENT_ID}
accessToken: {$env: TASKCLUSTER_ACCESS_TOKEN}
engine: script
engines:
script:
command:
- /usr/bin/env
- python
- $abs: 'script.py' # Run script.py relative to working directory of worker
schema:
type: object
properties:
text: {type: string, maxLength: 4096}
grep: {type: string, pattern: '^[a-zA-Z0-9_-]{1,32}$'}
required:
- text
- grep
minimumDiskSpace: 10000000 # 10 GB
minimumMemory: 1000000 # 1 GB
monitor:
logLevel: debug
project: tc-worker-script
plugins:
disabled:
- artifacts
- reboot
- env
- tcproxy
- interactive
livelog: {}
logprefix:
# Key/Value pairs printed at the start of the task log
phoneSerialNumber: '1337'
maxruntime:
# Abort tasks if they take longer than 1 hour and 20 minutes
# And forbid tasks for specifying a maxRunTime on their own.
maxRunTime: '1 hours 20 minutes'
perTaskLimit: forbid
success: {}
watchdog:
# Kill worker if any step other than task execution takes more than
# 35 minutes. Value should be larger than 30 minutes, as plugin hooks
# time out after 30 minutes.
# This is mostly useful for robustness, the worker shouldn't get stuck,
# but this ensure that'll recover, by crashing allowing the wrapper script
# to cleanup/reboot and restart the worker process.
timeout: '35 minutes'
temporaryFolder: /tmp/tc-worker #TODO: Use a more robust folder
webHookServer:
provider: webhooktunnel
worker:
concurrency: 1
minimumReclaimDelay: 30
pollingInterval: 5
reclaimOffset: 300
provisionerId: proj-autophone
workerType: example-worker
workerGroup: machine-1
workerId: process-1
#!/usr/bin/env python
import sys
import json
import os
# Read payload
payload = json.loads(sys.stdin.read())
print('Looking for needle: "{}"'.format(payload['grep']))
print('In:')
print('---')
print(payload['text'])
print('---')
success = payload['grep'] in payload['text']
try:
print('creating artifact with result')
os.mkdir('artifacts/public/')
with open('artifacts/public/result.json', 'w') as f:
f.write(json.dumps({'success': success}))
except Exception as e:
print('internal error: {}'.format(e))
sys.exit(3) # non-fatal internal error, let's hope it works next time
# Exit 0 or 1, depending on success
if success:
sys.exit(0) # task completed
else:
sys.exit(1) # task failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment