Esempio n. 1
0
    def _get_instances_using_cache(self, workflow):
        """Get workflow instances, preferably from the cache.

        As a side effect, archived instances that do not exist in the cache
        will be added to the cache.

        Args:
            workflow: The name of the workflow whose instances we are
                interested in.
        Returns:
            List of instances for the given workflow.
        """
        name = Name(workflow=workflow)
        workflow_prefix = name.get_workflow_prefix()
        workflow_token_names = self._store.read_token_names(
            name_prefix=workflow_prefix)
        instances_prefixes = DataBuilder._get_instance_prefixes(
            workflow_token_names)
        result = []
        for prefix in instances_prefixes:
            name = Name.from_instance_prefix(prefix)
            assert name.workflow and name.instance, (
                'Expected instance prefix, found %s' % prefix)
            result.append(self.get_instance(name.workflow, name.instance))
        return result
Esempio n. 2
0
    def _get_instances_using_cache(self, workflow):
        """Get workflow instances, preferably from the cache.

        As a side effect, archived instances that do not exist in the cache
        will be added to the cache.

        Args:
            workflow: The name of the workflow whose instances we are
                interested in.
        Returns:
            List of instances for the given workflow.
        """
        name = Name(workflow=workflow)
        workflow_prefix = name.get_workflow_prefix()
        workflow_token_names = self._store.read_token_names(
            name_prefix=workflow_prefix)
        instances_prefixes = DataBuilder._get_instance_prefixes(
            workflow_token_names)
        result = []
        for prefix in instances_prefixes:
            name = Name.from_instance_prefix(prefix)
            assert name.workflow and name.instance, (
                'Expected instance prefix, found %s' % prefix)
            result.append(self.get_instance(name.workflow, name.instance))
        return result
Esempio n. 3
0
 def get_workflow_instances(self, workflow_name):
     """Return list of instances of a given workflow."""
     request = GroupRequest()
     name = Name()
     name.workflow = workflow_name
     request.namePrefix = name.get_workflow_prefix()
     request.groupSuffix = Name.DELIMITER
     response = self._client.group(request)
     instance_names = []
     if response.counts:
         for prefix in response.counts.keys():
             name = Name.from_instance_prefix(prefix)
             if name.instance:
                 instance_names.append(name.instance)
     return instance_names
Esempio n. 4
0
 def get_workflow_instances(self, workflow_name):
     """Return list of instances of a given workflow."""
     request = GroupRequest()
     name = Name()
     name.workflow = workflow_name
     request.namePrefix = name.get_workflow_prefix()
     request.groupSuffix = Name.DELIMITER
     response = self._client.group(request)
     instance_names = []
     if response.counts:
         for prefix in response.counts.keys():
             name = Name.from_instance_prefix(prefix)
             if name.instance:
                 instance_names.append(name.instance)
     return instance_names
Esempio n. 5
0
    def _get_workflows_using_cache(self):
        """Get workflows, preferably fetching instances from the cache.

        As a side effect, archived instances that do not exist in the cache
        will be added to the cache.

        Returns:
            List of workflows data.
        """
        instances_token_names = self._store.read_token_names(
            name_prefix=Name.WORKFLOW_PREFIX)
        instances_prefixes = DataBuilder._get_instance_prefixes(
            instances_token_names)
        instances = []
        for prefix in instances_prefixes:
            name = Name.from_instance_prefix(prefix)
            assert name.workflow and name.instance, (
                'Expected instance prefix, found %s' % prefix)
            instances.append(self.get_instance(name.workflow, name.instance))
        return self._workflows_data_from_instances_data(instances)
Esempio n. 6
0
    def _get_workflows_using_cache(self):
        """Get workflows, preferably fetching instances from the cache.

        As a side effect, archived instances that do not exist in the cache
        will be added to the cache.

        Returns:
            List of workflows data.
        """
        instances_token_names = self._store.read_token_names(
            name_prefix=Name.WORKFLOW_PREFIX)
        instances_prefixes = DataBuilder._get_instance_prefixes(
            instances_token_names)
        instances = []
        for prefix in instances_prefixes:
            name = Name.from_instance_prefix(prefix)
            assert name.workflow and name.instance, (
                'Expected instance prefix, found %s' % prefix)
            instances.append(self.get_instance(name.workflow, name.instance))
        return self._workflows_data_from_instances_data(instances)
Esempio n. 7
0
 def test_instance_prefix(self):
     PREFIX = '/workflow/some_workflow/some_instance/'
     name = Name.from_instance_prefix(PREFIX)
     self.assertEqual('some_workflow', name.workflow)
     self.assertEqual('some_instance', name.instance)
     self.assertEqual(PREFIX, name.get_instance_prefix())
Esempio n. 8
0
 def test_instance_prefix(self):
     PREFIX = "/workflow/some_workflow/some_instance/"
     name = Name.from_instance_prefix(PREFIX)
     self.assertEqual("some_workflow", name.workflow)
     self.assertEqual("some_instance", name.instance)
     self.assertEqual(PREFIX, name.get_instance_prefix())