Skip to content

Commit b49ef51

Browse files
committed
Add support for synchronous and asynchronous modes in package cache
- Introduced a new command-line argument `--pkg-cache-mode` to specify caching mode. - Allows users to choose between 'sync' and 'async' modes, overriding the default configuration. - Updated `add_variant` function to handle the new caching mode option. - Ensures backward compatibility by maintaining default behavior when no mode is specified. Signed-off-by: Jose Enriquez <[email protected]>
1 parent 491497f commit b49ef51

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/rez/cli/pkg-cache.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def setup_parser(parser, completions=False):
4141
group.add_argument(
4242
"--daemon", action="store_true", help=SUPPRESS
4343
)
44+
parser.add_argument(
45+
"--pkg-cache-mode",
46+
choices=["sync", "async"],
47+
default=None,
48+
help="If provided, override the rezconfig's package_cache_async key. "
49+
"If 'sync', the process will block until packages are cached. "
50+
"If 'async', the process will not block while packages are cached."
51+
)
4452
parser.add_argument(
4553
"-c", "--columns", nargs='+', choices=column_choices,
4654
default=["status", "package", "variant_uri", "cache_path"],
@@ -70,7 +78,15 @@ def add_variant(pkgcache, uri, opts):
7078
print("No such variant: %s" % uri, file=sys.stderr)
7179
sys.exit(1)
7280

73-
destpath, status = pkgcache.add_variant(variant, force=opts.force)
81+
if opts.pkg_cache_mode is not None:
82+
cache_mode = True if opts.pkg_cache_mode == "sync" else False
83+
destpath, status = pkgcache.add_variant(
84+
variant, force=opts.force,
85+
wait_for_copying=cache_mode
86+
)
87+
# If no mode is specified, use the default behavior.
88+
else:
89+
destpath, status = pkgcache.add_variant(variant, force=opts.force)
7490

7591
if status == PackageCache.VARIANT_FOUND:
7692
print_info("Already exists: %s", destpath)

0 commit comments

Comments
 (0)