|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -from typing import Literal |
16 | 15 | from minio import Minio |
17 | 16 | import os |
18 | 17 | import io |
19 | 18 | from datetime import timedelta |
20 | 19 |
|
21 | | -from oqd_cloud.server.database import JobInDB, get_db |
| 20 | +from oqd_cloud.server.database import JobInDB |
22 | 21 |
|
23 | 22 | ######################################################################################## |
24 | 23 |
|
25 | 24 | minio_client = Minio( |
26 | | - f"{os.getenv("MINIO_ENDPOINT")}:9000", |
| 25 | + "localhost:9000", |
27 | 26 | access_key=os.getenv("MINIO_ROOT_USER"), |
28 | 27 | secret_key=os.getenv("MINIO_ROOT_PASSWORD"), |
29 | | - secure=False |
| 28 | + secure=False, |
30 | 29 | ) |
31 | 30 |
|
32 | 31 | DEFAULT_MINIO_BUCKET = os.getenv("MINIO_DEFAULT_BUCKETS") |
33 | 32 | RESULT_FILENAME = "result.json" |
34 | 33 |
|
| 34 | +if not minio_client.bucket_exists(DEFAULT_MINIO_BUCKET): |
| 35 | + minio_client.make_bucket(DEFAULT_MINIO_BUCKET) |
| 36 | + print("Created bucket", DEFAULT_MINIO_BUCKET) |
| 37 | +else: |
| 38 | + print("Bucket", DEFAULT_MINIO_BUCKET, "already exists") |
| 39 | + |
| 40 | + |
35 | 41 | def save_obj(job: JobInDB, result): |
36 | 42 | # if the file is already saved, fput can be used |
37 | 43 | # minio_client.fput_object( |
38 | 44 | # BUCKET, destination_file, source_file, |
39 | 45 | # ) |
40 | | - |
41 | | - # here we dump to json, todo: future version should dump to HDF5 |
42 | | - json_bytes = result.model_dump_json().encode('utf-8') |
| 46 | + |
| 47 | + # here we dump to json, todo: future version should dump to HDF5 |
| 48 | + json_bytes = result.model_dump_json().encode("utf-8") |
43 | 49 | buffer = io.BytesIO(json_bytes) |
44 | 50 |
|
45 | 51 | minio_client.put_object( |
46 | | - DEFAULT_MINIO_BUCKET, |
47 | | - f"{job.id}/{RESULT_FILENAME}", |
48 | | - data=buffer, |
49 | | - length=len(json_bytes), |
50 | | - content_type='application/json' |
| 52 | + DEFAULT_MINIO_BUCKET, |
| 53 | + f"{job.id}/{RESULT_FILENAME}", |
| 54 | + data=buffer, |
| 55 | + length=len(json_bytes), |
| 56 | + content_type="application/json", |
51 | 57 | ) |
52 | 58 |
|
53 | 59 | return |
|
0 commit comments