Bug 1111980 - Part 6 Add slugjar to back the as_slugid functionality needed for decision tasks. r=garndt

This commit is contained in:
jlal@mozilla.com 2014-12-11 12:53:10 -08:00
parent eaba4f63d3
commit b2868b9893
3 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,20 @@
from taskcluster_graph.slugid import slugid
class SlugidJar():
'''
Container of seen slugid's used to implement the as_slugid functionality
used in the task graph templates.
'''
def __init__(self):
self._names = {}
def __call__(self, name):
'''
So this object can easily be passed to mustache we allow it to be called
directly...
'''
if name in self._names:
return self._names[name];
self._names[name] = slugid()
return self._names[name]

View File

@ -26,10 +26,10 @@ scopes:
- "docker-worker:cache:sources-gaia" - "docker-worker:cache:sources-gaia"
- "docker-worker:cache:build-emulator-ics-debug" - "docker-worker:cache:build-emulator-ics-debug"
tasks: tasks:
- taskId: '{{ "decision task" | as-slugid }}' - taskId: '{{#as_slugid }}decision task{{/as_slugid}}'
task: task:
created: '{{now}}' created: '{{now}}'
deadline: '{{ "1 day" | from-now }}' deadline: '{{#from_now }}1 day{{#/from_now}}'
metadata: metadata:
source: '{{source}}' source: '{{source}}'
owner: '{{owner}}' owner: '{{owner}}'

View File

@ -0,0 +1,19 @@
import unittest
import mozunit
from datetime import datetime
from taskcluster_graph.slugidjar import SlugidJar
class SlugidJarTest(unittest.TestCase):
def test_slugidjar(self):
subject = Jar()
self.assertEqual(subject('woot'), subject('woot'))
self.assertTrue(type(subject('woot')) is str)
other_jar = Jar()
self.assertNotEqual(subject('woot'), other_jar('woot'))
if __name__ == '__main__':
mozunit.main()