Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wderocco8
Copy link
Member

@wderocco8 wderocco8 commented May 21, 2025

What does this PR do?

Avoids initializing the web-driver until the get_jobs function is called.

TODO:

  • Create a decorator for calling a function when get_jobs either fails or finishes executing (see Deepseek's suggestion below)
  • Use this decorator on get_jobs to call self._close_driver on exit

Deepseek's suggestion:

def callback_on_exit(callback):
    """Decorator to execute callback when the wrapped function exits."""
    def decorator(func):
        def wrapper(*args, **kwargs):
            try:
                result = func(*args, **kwargs)  # Execute the original function
                callback("success", result)     # Callback on success
                return result
            except Exception as e:
                callback("error", e)            # Callback on error
                raise  # Re-raise the exception
            finally:
                callback("exit", None)          # Callback on exit (always runs)
        return wrapper
    return decorator

Type of change

  • Fix: Bug fix (non-breaking change which fixes an issue)
  • Refactor: Any code refactoring
  • Chore: technical debt, workflow improvements
  • Feature: New feature (non-breaking change which adds functionality)
  • Documentation: This change requires a documentation update
  • Merge: Pushing features to an upper environment

Tests Performed

Screenshots

Additional Comments

@github-actions
Copy link

github-actions bot commented Jun 1, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2676 1991 74% 70% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
chalicelib/api/broadcast.py 50% 🟢
chalicelib/services/JobPostingService.py 78% 🟢
tests/services/test_job_posting_service.py 95% 🟢
TOTAL 74% 🟢

updated for commit: 531e322 by action🐍

@vinli0921 vinli0921 marked this pull request as ready for review June 1, 2025 00:56
Copy link
Contributor

@jinyoungbang jinyoungbang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just see my comments and feel free to make changes or let it be!

import re
import functools

def call_on_exit(method_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO decorator feels unnecessary and over engineered - unless we know we're gonna have more jobs/tasks that use the webdriver, I'd feel like just having a simple exit/kill method would be better. Regardless, if it works, no issues at all too!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might add a "recent news" section where we could scrape articles from the web and provide a summary of what's happening that week. Do you think it's a good idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's leave it for now - we can always iterate to change it later!

try:
self.driver.quit()
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we raise some sort of error here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added RuntimeError

@vinli0921 vinli0921 merged commit b95e1bf into dev/v3.0 Jun 1, 2025
1 check passed
@vinli0921 vinli0921 deleted the fix/web-driver-cpu branch June 1, 2025 02:05
@jinyoungbang jinyoungbang added optimization Enhancements performance Enhancements labels Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization Enhancements performance Enhancements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants