Exemplo n.º 1
0
    def _traverse(self, id_):
        """Traverse groups and yield info dicts for jobs"""

        nodes = r_client.smembers(_children_key(id_))
        while nodes:
            current_id = nodes.pop()

            details = self._decode(r_client.get(current_id))
            if details['type'] == 'group':
                children = r_client.smembers(_children_key(details['id']))
                if children is not None:
                    nodes.update(children)

            yield details
Exemplo n.º 2
0
    def _traverse(self, id_):
        """Traverse groups and yield info dicts for jobs"""

        nodes = r_client.smembers(_children_key(id_))
        while nodes:
            current_id = nodes.pop()

            details = self._decode(r_client.get(current_id))
            if details['type'] == 'group':
                children = r_client.smembers(_children_key(details['id']))
                if children is not None:
                    nodes.update(children)

            yield details
Exemplo n.º 3
0
    def test_action_remove(self):
        self.obj._action_add(['d', 'f', 'e'])
        resp = self.obj._action_remove(['a', 'd', 'f', 'c', 'e'])
        self.assertEqual(resp, [{
            u'id': u'a',
            u'name': u'a',
            u'type': u'job'
        }, {
            u'id': u'd',
            u'name': u'other job',
            u'type': u'job'
        }, {
            u'id': u'c',
            u'name': u'c',
            u'type': u'job'
        }, {
            u'id': u'e',
            u'name': u'other job e',
            u'type': u'job'
        }])

        self.assertNotIn('a:pubsub', self.obj._listening_to)
        self.assertNotIn('c:pubsub', self.obj._listening_to)
        self.assertNotIn('d:pubsub', self.obj._listening_to)
        self.assertNotIn('e:pubsub', self.obj._listening_to)
        self.assertNotIn('f:pubsub', self.obj._listening_to)
        self.assertEqual(r_client.smembers('testing:children'), {'b'})
Exemplo n.º 4
0
    def traverse(self, id_=None):
        """Traverse groups and yield info dicts for jobs"""
        if id_ is None:
            id_ = self.group

        nodes = r_client.smembers(_children_key(id_))
        while nodes:
            current_id = nodes.pop()

            details = r_client.get(current_id)
            if details is None:
                # child has expired or been deleted, remove from :children
                r_client.srem(_children_key(id_), current_id)
                continue

            details = self._decode(details)
            if details['type'] == 'group':
                children = r_client.smembers(_children_key(details['id']))
                if children is not None:
                    nodes.update(children)

            yield details
Exemplo n.º 5
0
    def traverse(self, id_=None):
        """Traverse groups and yield info dicts for jobs"""
        if id_ is None:
            id_ = self.group

        nodes = r_client.smembers(_children_key(id_))
        while nodes:
            current_id = nodes.pop()

            details = r_client.get(current_id)
            if details is None:
                # child has expired or been deleted, remove from :children
                r_client.srem(_children_key(id_), current_id)
                continue

            details = self._decode(details)
            if details['type'] == 'group':
                children = r_client.smembers(_children_key(details['id']))
                if children is not None:
                    nodes.update(children)

            yield details
Exemplo n.º 6
0
    def test_action_remove(self):
        self.obj._action_add(['d', 'f', 'e'])
        resp = self.obj._action_remove(['a', 'd', 'f', 'c', 'e'])
        self.assertItemsEqual(resp, [
            {u'id': u'a', u'name': u'a', u'type': u'job'},
            {u'id': u'd', u'name': u'other job', u'type': u'job'},
            {u'id': u'c', u'name': u'c', u'type': u'job'},
            {u'id': u'e', u'name': u'other job e', u'type': u'job'}])

        self.assertNotIn('a:pubsub', self.obj._listening_to)
        self.assertNotIn('c:pubsub', self.obj._listening_to)
        self.assertNotIn('d:pubsub', self.obj._listening_to)
        self.assertNotIn('e:pubsub', self.obj._listening_to)
        self.assertNotIn('f:pubsub', self.obj._listening_to)
        self.assertEqual(r_client.smembers('testing:children'), {'b'})
 def test_traverse_removed_child(self):
     r_client.delete('b')
     exp = {'a', 'c'}
     obs = {obj['id'] for obj in self.obj.traverse('testing')}
     self.assertEqual(obs, exp)
     self.assertEqual(r_client.smembers('testing:children'), exp)
Exemplo n.º 8
0
 def test_traverse_removed_child(self):
     r_client.delete('b')
     exp = {'a', 'c'}
     obs = {obj['id'] for obj in self.obj.traverse('testing')}
     self.assertEqual(obs, exp)
     self.assertEqual(r_client.smembers('testing:children'), exp)