Skip to content

Commit 873bd06

Browse files
committed
fix: add content build run --force flag
Signed-off-by: Lucas Rodriguez <[email protected]>
1 parent 801d8f0 commit 873bd06

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

rsconnect/actions_content.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ def build_add_content(
4949
:param content_guids_with_bundle: Union[tuple[models.ContentGuidWithBundle], list[models.ContentGuidWithBundle]]
5050
"""
5151
build_store = ensure_content_build_store(connect_server)
52-
if build_store.get_build_running():
53-
raise RSConnectException(
54-
"There is already a build running on this server, "
55-
+ "please wait for it to finish before adding new content."
56-
)
57-
5852
with RSConnectClient(connect_server) as client:
5953
if len(content_guids_with_bundle) == 1:
6054
all_content = [client.content_get(content_guids_with_bundle[0].guid)]
@@ -104,10 +98,6 @@ def build_remove_content(
10498
_validate_build_rm_args(guid, all, purge)
10599

106100
build_store = ensure_content_build_store(connect_server)
107-
if build_store.get_build_running():
108-
raise RSConnectException(
109-
"There is a build running on this server, " + "please wait for it to finish before removing content."
110-
)
111101
guids: list[str]
112102
if all:
113103
guids = [c["guid"] for c in build_store.get_content_items()]
@@ -141,10 +131,23 @@ def build_start(
141131
all: bool = False,
142132
poll_wait: int = 1,
143133
debug: bool = False,
134+
force: bool = False,
144135
):
145136
build_store = ensure_content_build_store(connect_server)
146-
if build_store.get_build_running():
147-
raise RSConnectException("There is already a build running on this server: %s" % connect_server.url)
137+
if build_store.get_build_running() and not force:
138+
raise RSConnectException(
139+
"There is already a build running on this server: %s. "
140+
"Use the '--force' flag to override this check." % connect_server.url
141+
)
142+
143+
# prompt the user to confirm that they want to --force a build.
144+
if force:
145+
logger.warning("Please ensure a build is not already running in another terminal before proceeding.")
146+
user_input = input("Are you sure you want to proceed? Type 'yes' to confirm: ").strip().lower()
147+
if user_input != "yes":
148+
logger.warning("Build aborted.")
149+
return
150+
logger.info("Proceeding with the build operation...")
148151

149152
# if we are re-building any already "tracked" content items, then re-add them to be safe
150153
if all:
@@ -154,7 +157,8 @@ def build_start(
154157
build_add_content(connect_server, all_content)
155158
else:
156159
# --retry is shorthand for --aborted --error --running
157-
if retry:
160+
# --force has the same behavior as --retry and also ignores when rsconnect_build_running=true
161+
if retry or force:
158162
aborted = True
159163
error = True
160164
running = True
@@ -277,12 +281,12 @@ def _monitor_build(connect_server: RSConnectServer, content_items: list[ContentI
277281
)
278282

279283
if build_store.aborted():
280-
logger.warn("Build interrupted!")
284+
logger.warning("Build interrupted!")
281285
aborted_builds = [i["guid"] for i in content_items if i["rsconnect_build_status"] == BuildStatus.RUNNING]
282286
if len(aborted_builds) > 0:
283-
logger.warn("Marking %d builds as ABORTED..." % len(aborted_builds))
287+
logger.warning("Marking %d builds as ABORTED..." % len(aborted_builds))
284288
for guid in aborted_builds:
285-
logger.warn("Build aborted: %s" % guid)
289+
logger.warning("Build aborted: %s" % guid)
286290
build_store.set_content_item_build_status(guid, BuildStatus.ABORTED)
287291
return False
288292

rsconnect/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,11 @@ def get_build_logs(
27552755
is_flag=True,
27562756
help="Log stacktraces from exceptions during background operations.",
27572757
)
2758+
@click.option(
2759+
"--force",
2760+
is_flag=True,
2761+
help="Always build content even if a build is already marked as running. Builds the same content as --retry."
2762+
)
27582763
@click.pass_context
27592764
def start_content_build(
27602765
ctx: click.Context,
@@ -2772,6 +2777,7 @@ def start_content_build(
27722777
poll_wait: int,
27732778
format: LogOutputFormat.All,
27742779
debug: bool,
2780+
force: bool,
27752781
verbose: int,
27762782
):
27772783
set_verbosity(verbose)
@@ -2781,7 +2787,7 @@ def start_content_build(
27812787
ce = RSConnectExecutor(ctx, name, server, api_key, insecure, cacert, logger=None).validate_server()
27822788
if not isinstance(ce.remote_server, RSConnectServer):
27832789
raise RSConnectException("rsconnect content build run` requires a Posit Connect server.")
2784-
build_start(ce.remote_server, parallelism, aborted, error, running, retry, all, poll_wait, debug)
2790+
build_start(ce.remote_server, parallelism, aborted, error, running, retry, all, poll_wait, debug, force)
27852791

27862792

27872793
@cli.group(no_args_is_help=True, help="Interact with Posit Connect's system API.")

rsconnect/utils_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def fix_starlette_requirements(
246246
if compare_semvers(starlette_req.specs[0].version, "0.35.0") >= 0:
247247
# starlette is in requirements.txt, but with a version spec that is
248248
# not compatible with this version of Connect.
249-
logger.warn(
249+
logger.warning(
250250
"Starlette version is 0.35.0 or greater, but this version of Connect "
251251
"requires starlette<0.35.0. Setting to <0.35.0."
252252
)

0 commit comments

Comments
 (0)