|
3 | 3 |
|
4 | 4 | import logging |
5 | 5 | import os |
| 6 | +import threading |
| 7 | + |
| 8 | +from funcy import cached_property, wrap_prop |
6 | 9 |
|
7 | 10 | from dvc.config import Config |
8 | 11 | from dvc.path_info import CloudURLInfo |
@@ -61,30 +64,29 @@ def __init__(self, repo, config): |
61 | 64 | or "defaultSecret" |
62 | 65 | ) |
63 | 66 |
|
64 | | - self._bucket = None |
65 | | - |
66 | | - @property |
| 67 | + @wrap_prop(threading.Lock()) |
| 68 | + @cached_property |
67 | 69 | def oss_service(self): |
68 | 70 | import oss2 |
69 | 71 |
|
70 | | - if self._bucket is None: |
71 | | - logger.debug("URL {}".format(self.path_info)) |
72 | | - logger.debug("key id {}".format(self.key_id)) |
73 | | - logger.debug("key secret {}".format(self.key_secret)) |
74 | | - auth = oss2.Auth(self.key_id, self.key_secret) |
75 | | - self._bucket = oss2.Bucket( |
76 | | - auth, self.endpoint, self.path_info.bucket |
| 72 | + logger.debug("URL {}".format(self.path_info)) |
| 73 | + logger.debug("key id {}".format(self.key_id)) |
| 74 | + logger.debug("key secret {}".format(self.key_secret)) |
| 75 | + |
| 76 | + auth = oss2.Auth(self.key_id, self.key_secret) |
| 77 | + bucket = oss2.Bucket(auth, self.endpoint, self.path_info.bucket) |
| 78 | + |
| 79 | + # Ensure bucket exists |
| 80 | + try: |
| 81 | + bucket.get_bucket_info() |
| 82 | + except oss2.exceptions.NoSuchBucket: |
| 83 | + bucket.create_bucket( |
| 84 | + oss2.BUCKET_ACL_PUBLIC_READ, |
| 85 | + oss2.models.BucketCreateConfig( |
| 86 | + oss2.BUCKET_STORAGE_CLASS_STANDARD |
| 87 | + ), |
77 | 88 | ) |
78 | | - try: # verify that bucket exists |
79 | | - self._bucket.get_bucket_info() |
80 | | - except oss2.exceptions.NoSuchBucket: |
81 | | - self._bucket.create_bucket( |
82 | | - oss2.BUCKET_ACL_PUBLIC_READ, |
83 | | - oss2.models.BucketCreateConfig( |
84 | | - oss2.BUCKET_STORAGE_CLASS_STANDARD |
85 | | - ), |
86 | | - ) |
87 | | - return self._bucket |
| 89 | + return bucket |
88 | 90 |
|
89 | 91 | def remove(self, path_info): |
90 | 92 | if path_info.scheme != self.scheme: |
|
0 commit comments