summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-09-09 19:24:02 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-09-10 15:56:12 +0900
commit303240abdcd01acad5e5daeeda16e2e9bc5aa28b (patch)
tree55915873fea9d7e4af44a53f49f460b5e1708520
parent67fa96e1489790f0f92ba7660644bb0a72297a37 (diff)
downloadbuildstream-303240abdcd01acad5e5daeeda16e2e9bc5aa28b.tar.gz
element.py: Remove _get_artifact_cache() accessor.
The artifact cache is anyway a singleton, the Element itself has an internal handle on the artifact cache because it is needed very frequently; but an artifact cache is not element specific and should not be looked up by surrounding code on a per element basis. Updated _scheduler/queues/queue.py, _scheduler/queues/buildqueue.py and _scheduler/jobs/elementjob.py to get the artifact cache directly from the Platform
-rw-r--r--buildstream/_scheduler/jobs/elementjob.py8
-rw-r--r--buildstream/_scheduler/queues/buildqueue.py9
-rw-r--r--buildstream/_scheduler/queues/queue.py5
-rw-r--r--buildstream/element.py10
4 files changed, 16 insertions, 16 deletions
diff --git a/buildstream/_scheduler/jobs/elementjob.py b/buildstream/_scheduler/jobs/elementjob.py
index b3318302a..a010a6684 100644
--- a/buildstream/_scheduler/jobs/elementjob.py
+++ b/buildstream/_scheduler/jobs/elementjob.py
@@ -18,6 +18,7 @@
#
from ruamel import yaml
+from ..._platform import Platform
from ..._message import Message, MessageType
from .job import Job
@@ -72,6 +73,10 @@ class ElementJob(Job):
self._action_cb = action_cb # The action callable function
self._complete_cb = complete_cb # The complete callable function
+ # Hold on to the artifact cache
+ platform = Platform.get_platform()
+ self._artifacts = platform.artifactcache
+
# Set the task wide ID for logging purposes
self.set_task_id(element._get_unique_id())
@@ -109,8 +114,7 @@ class ElementJob(Job):
data = {}
workspace = self._element._get_workspace()
- artifacts = self._element._get_artifact_cache()
- cache_size = artifacts.compute_cache_size()
+ cache_size = self._artifacts.compute_cache_size()
if workspace is not None:
data['workspace'] = workspace.to_dict()
diff --git a/buildstream/_scheduler/queues/buildqueue.py b/buildstream/_scheduler/queues/buildqueue.py
index 2a07fdd6c..83ab49fe7 100644
--- a/buildstream/_scheduler/queues/buildqueue.py
+++ b/buildstream/_scheduler/queues/buildqueue.py
@@ -20,6 +20,7 @@
from . import Queue, QueueStatus
from ..resources import ResourceType
+from ..._platform import Platform
# A queue which assembles elements
@@ -56,13 +57,15 @@ class BuildQueue(Queue):
# as returned from Element._assemble() to the estimated
# artifact cache size
#
- cache = element._get_artifact_cache()
- cache.add_artifact_size(artifact_size)
+ platform = Platform.get_platform()
+ artifacts = platform.artifactcache
+
+ artifacts.add_artifact_size(artifact_size)
# If the estimated size outgrows the quota, ask the scheduler
# to queue a job to actually check the real cache size.
#
- if cache.get_approximate_cache_size() > cache.cache_quota:
+ if artifacts.get_approximate_cache_size() > artifacts.cache_quota:
self._scheduler.check_cache_size()
def done(self, job, element, result, success):
diff --git a/buildstream/_scheduler/queues/queue.py b/buildstream/_scheduler/queues/queue.py
index 6c1583495..c8e4457ec 100644
--- a/buildstream/_scheduler/queues/queue.py
+++ b/buildstream/_scheduler/queues/queue.py
@@ -31,6 +31,7 @@ from ..resources import ResourceType
# BuildStream toplevel imports
from ..._exceptions import BstError, set_last_task_error
from ..._message import Message, MessageType
+from ..._platform import Platform
# Queue status for a given element
@@ -301,7 +302,9 @@ class Queue():
# before calling any queue implementation
self._update_workspaces(element, job)
if job.child_data:
- element._get_artifact_cache().cache_size = job.child_data.get('cache_size')
+ platform = Platform.get_platform()
+ artifacts = platform.artifactcache
+ artifacts.cache_size = job.child_data.get('cache_size')
# Give the result of the job to the Queue implementor,
# and determine if it should be considered as processed
diff --git a/buildstream/element.py b/buildstream/element.py
index 3093bc5e0..e6b330492 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1821,16 +1821,6 @@ class Element(Plugin):
workspaces = self._get_context().get_workspaces()
return workspaces.get_workspace(self._get_full_name())
- # _get_artifact_cache()
- #
- # Accessor for the artifact cache
- #
- # Returns:
- # (ArtifactCache): The artifact cache
- #
- def _get_artifact_cache(self):
- return self.__artifacts
-
# _write_script():
#
# Writes a script to the given directory.