Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if workarena-install is correctly run #60

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/browsergym/workarena/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,16 @@ def db_delete_from_table(instance: SNowInstance, sys_id: str, table: str) -> Non

# Check for HTTP code 200 (fail otherwise)
response.raise_for_status()


def get_instance_sys_property(instance: SNowInstance, property_name: str) -> str:
"""
Get a sys_property from the instance.
"""
property_value = table_api_call(
instance=instance,
table="sys_properties",
params={"sysparm_query": f"name={property_name}", "sysparm_fields": "value"},
)["result"][0]["value"]

return property_value
23 changes: 5 additions & 18 deletions src/browsergym/workarena/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .api.ui_themes import get_workarena_theme_variants
from .api.user import create_user
from .api.utils import table_api_call, table_column_info
from .api.utils import table_api_call, table_column_info, get_instance_sys_property
from .config import (
# for knowledge base setup
KB_FILEPATH,
Expand Down Expand Up @@ -82,22 +82,6 @@ def _set_sys_property(property_name: str, value: str):
assert property["result"]["value"] == value, f"Error setting {property_name}."


def _get_sys_property(property_name: str) -> str:
"""
Get a sys_property from the instance.

"""
instance = SNowInstance()

property_value = table_api_call(
instance=instance,
table="sys_properties",
params={"sysparm_query": f"name={property_name}", "sysparm_fields": "value"},
)["result"][0]["value"]

return property_value


def _install_update_set(path: str, name: str):
"""
Install a ServiceNow update set
Expand Down Expand Up @@ -1054,7 +1038,10 @@ def main():
logging.basicConfig(level=logging.INFO)

try:
past_install_date = _get_sys_property("workarena.installation.date")
instance = SNowInstance()
past_install_date = get_instance_sys_property(
instance=instance, property_name="workarena.installation.date"
)
logging.info(f"Detected previous installation on {past_install_date}. Reinstalling...")
except:
past_install_date = "never"
Expand Down
11 changes: 10 additions & 1 deletion src/browsergym/workarena/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from browsergym.core.task import AbstractBrowserTask
from ..api.user import create_user
from ..api.utils import table_api_call
from ..api.utils import table_api_call, get_instance_sys_property
from ..config import SNOW_BROWSER_TIMEOUT, SNOW_JS_UTILS_FILEPATH
from ..utils import url_login
from ..instance import SNowInstance
Expand Down Expand Up @@ -64,6 +64,15 @@ def __init__(
self.timeout = 10000 # ms

self.instance = instance if instance is not None else SNowInstance()

# Check if workarena-install is done correctly
try:
_ = get_instance_sys_property(self.instance, "workarena.installation.date")
except Exception:
raise RuntimeError(
f"WorkArena installation has not been detected in your instance. Please install WorkArena by running workarena-install"
)

self.start_url = self.instance.snow_url + start_rel_url

if final_rel_url is not None:
Expand Down
Loading