Skip to content

Commit

Permalink
Fixed issue on Windows, due to which error on scheduler was implicitl…
Browse files Browse the repository at this point in the history
…y hidden
  • Loading branch information
dolamroth committed Apr 28, 2024
1 parent a71b391 commit 2f69f80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ postgres = ["asyncpg>=0.29,<0.30"]
redis = ["redis>=5.0.1,<5.1"]
scheduler = [
"croniter>=2.0.1,<2.1",
"py-win-task-scheduler==0.2.0; sys_platform == 'win32'",
"py-win-task-scheduler==0.2.1; sys_platform == 'win32'",
]
ssh = ["asyncssh>=2.14.2,<2.15"]
deploy = ["gunicorn>=21.2.0,<22.0"]
Expand Down
17 changes: 8 additions & 9 deletions starlette_web/contrib/scheduler/backends/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ def __init__(self, **kwargs):
self._root_dir = "starlette_web"

def __enter__(self):
if self.needs_write:
if ctypes.windll.shell32.IsUserAnAdmin() == 0:
warnings.warn(
"You may have insufficient privileges to make "
"changes to Task Scheduler as non-administrator"
)
if ctypes.windll.shell32.IsUserAnAdmin() == 0:
warnings.warn(
"You may have insufficient privileges to make or observe "
"changes to Task Scheduler as non-administrator"
)

self._ensure_project_folder_exists()
self._read_jobs()
Expand Down Expand Up @@ -89,7 +88,7 @@ def update_jobs(self):
start_date=start_date,
)

created = create_task(
created, reason = create_task(
name=job_hash,
location=location,
description=f"Periodic job {job_hash}",
Expand Down Expand Up @@ -123,7 +122,7 @@ def update_jobs(self):
**schedule_kwargs,
)
if not created:
raise CommandError(message=f"Could not create task {job}")
raise CommandError(message=f"Could not create task {job}. {reason}")

logger.info(f"Created scheduled task {job}")

Expand Down Expand Up @@ -176,7 +175,7 @@ def show_jobs(self):
if task_name in self._current_jobs:
task_info = get_task_info(task_name, location=location)
logger.info("%s -> %s" % (job, location + task_name))
logger.info(json.dumps(task_info, indent=2))
logger.debug(json.dumps(task_info, indent=2))

def remove_jobs(self):
project_hash = self._get_project_level_hash()
Expand Down

0 comments on commit 2f69f80

Please sign in to comment.