-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import contextlib | ||
import multiprocessing | ||
from functools import wraps | ||
from multiprocessing.pool import IMapIterator | ||
|
||
|
||
@contextlib.contextmanager | ||
def multimap(cores=None): | ||
""" | ||
Provide multiprocessing imap like function. | ||
The context manager handles setting up the pool, worked around interrupt issues | ||
and terminating the pool on completion. | ||
""" | ||
if cores is None: | ||
cores = max(multiprocessing.cpu_count() - 1, 1) | ||
|
||
def wrapper(func): | ||
def wrap(self, timeout=None): | ||
return func(self, timeout=timeout if timeout is not None else 1e100) | ||
|
||
return wrap | ||
|
||
IMapIterator.next = wrapper(IMapIterator.next) | ||
pool = multiprocessing.Pool(cores) | ||
yield pool.imap | ||
pool.terminate() | ||
|
||
|
||
def map_wrap(f): | ||
@wraps(f) | ||
def wrapper(*args, **kwargs): | ||
return f(*args, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import requests | ||
from outpostkit.repository.lfs.logger import create_lfs_logger | ||
|
||
from outpostcli.lfs.file_slice import FileSlice | ||
from outpostcli.lfs.types import UploadedPartObject | ||
|
||
_log = create_lfs_logger(__name__) | ||
|
||
|
||
def transfer_part(filepath: str, part_number: int, chunk_size: int, presigned_url: str): | ||
with FileSlice( | ||
filepath, seek_from=(part_number - 1) * chunk_size, read_limit=chunk_size | ||
) as data: | ||
try: | ||
r = requests.put(presigned_url, data=data) | ||
r.raise_for_status() | ||
|
||
return UploadedPartObject( | ||
{ | ||
"etag": str(r.headers.get("etag")), | ||
"part_number": part_number, | ||
} | ||
) | ||
except Exception as e: | ||
_log.error(e) | ||
raise |