Skip to content

Commit

Permalink
Update the way we retreive the session recording path in the worker m…
Browse files Browse the repository at this point in the history
…ain process
  • Loading branch information
Ayan-Bandyopadhyay committed Oct 10, 2024
1 parent 8a16818 commit b70a10f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
19 changes: 13 additions & 6 deletions python_library/finic/finic.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,13 @@ def get_session_results(self, session_id: Optional[str] = None) -> Optional[Dict

def launch_browser_sync(self, **kwargs) -> Tuple[Page, BrowserContext]:
video_dir = os.path.join(os.getcwd(), "session_recording")
# Delete all files in the video directory
for file in os.listdir(video_dir):
os.remove(os.path.join(video_dir, file))
# If it doesn't exist, create it
if not os.path.exists(video_dir):
os.makedirs(video_dir)
else:
# Delete all files in the video directory
for file in os.listdir(video_dir):
os.remove(os.path.join(video_dir, file))
playwright = sync_playwright().start()
browser = playwright.chromium.launch(**kwargs)
saved_context = self.get_browser_context()
Expand All @@ -196,9 +200,12 @@ def launch_browser_sync(self, **kwargs) -> Tuple[Page, BrowserContext]:


initial_page = context.new_page()
recording_path = os.getenv("FINIC_SESSION_RECORDING_PATH")
if recording_path:
initial_page.video.save_as(path=recording_path)
recording_path_file = os.getenv("FINIC_SESSION_RECORDING_PATH")
if recording_path_file:
# Save the video path to the file
with open(recording_path_file, "w") as f:
path = initial_page.video.path()
f.write(str(path))

def disable_video(page: Page):
page.on("close", lambda p: p.video.delete())
Expand Down
2 changes: 1 addition & 1 deletion python_library/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "finic-py"
version = "0.1.15"
version = "0.1.17"
description = "Finic.ai is a platform for deploying agents and workflow automations in Python. This is the Python client for Finic"
authors = ["Ayan Bandyopadhyay <[email protected]>", "jasonwcfan <[email protected]>"]
readme = "README.md"
Expand Down
20 changes: 13 additions & 7 deletions worker/run_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def run_worker(agent_id: str, api_key: str, request: Dict):
# Start Xvfb in the background
xvfb_process = subprocess.Popen(["Xvfb", ":99", "-screen", "0", "1024x768x16"])

session_recording_path = os.path.join(os.getcwd(), "session_recording.webm")
os.environ["FINIC_SESSION_RECORDING_PATH"] = session_recording_path
session_recording_path_file = os.path.join(os.getcwd(), "session_recording_path.txt")
os.environ["FINIC_SESSION_RECORDING_PATH"] = session_recording_path_file

# Give Xvfb a moment to start up
# time.sleep(1)
Expand All @@ -112,11 +112,17 @@ def run_worker(agent_id: str, api_key: str, request: Dict):
# Make sure to terminate Xvfb when we're done
xvfb_process.terminate()
xvfb_process.wait()
if os.path.exists(session_recording_path):
upload_url = worker.get_session_recording_upload_url()
with open(session_recording_path, "rb") as f:
file_bytes = f.read()
worker.upload_session_recording(upload_url, file_bytes)
if os.path.exists(session_recording_path_file):
with open(session_recording_path_file, "r") as f:
session_recording_path = f.read()

if os.path.exists(session_recording_path):
with open(session_recording_path, "rb") as f:
file_bytes = f.read()
upload_url = worker.get_session_recording_upload_url()
worker.upload_session_recording(upload_url, file_bytes)
else:
print("Session recording path does not exist")


if __name__ == "__main__":
Expand Down

0 comments on commit b70a10f

Please sign in to comment.