summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-08-08 00:58:08 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-08-09 00:02:05 +0300
commitea0ed61cf3bfd24a2e0b9441e090a7be975dea98 (patch)
treedfdaadd09e5568a40be0c02172de2149a0c9449f
parent9ed784d83dbe90fc1ca5ef5e88e8f60c10144aef (diff)
downloadapscheduler-ea0ed61cf3bfd24a2e0b9441e090a7be975dea98.tar.gz
Renamed the job_info contextvar into current_job
-rw-r--r--docs/api.rst2
-rw-r--r--src/apscheduler/__init__.py4
-rw-r--r--src/apscheduler/_context.py4
-rw-r--r--src/apscheduler/workers/async_.py6
-rw-r--r--src/apscheduler/workers/sync.py6
-rw-r--r--tests/test_schedulers.py6
6 files changed, 14 insertions, 14 deletions
diff --git a/docs/api.rst b/docs/api.rst
index de2758f..f6c1fd5 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -94,7 +94,7 @@ Context variables
.. autodata:: apscheduler.current_scheduler
.. autodata:: apscheduler.current_worker
-.. autodata:: apscheduler.job_info
+.. autodata:: apscheduler.current_job
Exceptions
----------
diff --git a/src/apscheduler/__init__.py b/src/apscheduler/__init__.py
index be2f038..6b5828d 100644
--- a/src/apscheduler/__init__.py
+++ b/src/apscheduler/__init__.py
@@ -43,12 +43,12 @@ __all__ = [
"WorkerStopped",
"current_scheduler",
"current_worker",
- "job_info",
+ "current_job",
]
from typing import Any
-from ._context import current_scheduler, current_worker, job_info
+from ._context import current_job, current_scheduler, current_worker
from ._enums import CoalescePolicy, ConflictPolicy, JobOutcome, RunState
from ._events import (
DataStoreEvent,
diff --git a/src/apscheduler/_context.py b/src/apscheduler/_context.py
index 42ccf87..cc5aff2 100644
--- a/src/apscheduler/_context.py
+++ b/src/apscheduler/_context.py
@@ -4,9 +4,9 @@ from contextvars import ContextVar
from typing import TYPE_CHECKING
if TYPE_CHECKING:
+ from ._structures import JobInfo
from .schedulers.async_ import AsyncScheduler
from .schedulers.sync import Scheduler
- from .structures import JobInfo
from .workers.async_ import AsyncWorker
from .workers.sync import Worker
@@ -19,4 +19,4 @@ current_worker: ContextVar[Worker | AsyncWorker | None] = ContextVar(
"current_worker", default=None
)
#: Metadata about the current job
-job_info: ContextVar[JobInfo] = ContextVar("job_info")
+current_job: ContextVar[JobInfo] = ContextVar("job_info")
diff --git a/src/apscheduler/workers/async_.py b/src/apscheduler/workers/async_.py
index 4c965ae..a44c89c 100644
--- a/src/apscheduler/workers/async_.py
+++ b/src/apscheduler/workers/async_.py
@@ -20,7 +20,7 @@ from anyio import (
)
from anyio.abc import CancelScope, TaskGroup
-from .._context import current_worker, job_info
+from .._context import current_job, current_worker
from .._converters import as_async_datastore, as_async_eventbroker
from .._enums import JobOutcome, RunState
from .._events import JobAdded, WorkerStarted, WorkerStopped
@@ -178,7 +178,7 @@ class AsyncWorker:
await self.data_store.release_job(self.identity, job.task_id, result)
return
- token = job_info.set(JobInfo.from_job(job))
+ token = current_job.set(JobInfo.from_job(job))
try:
retval = func(*job.args, **job.kwargs)
if isawaitable(retval):
@@ -202,6 +202,6 @@ class AsyncWorker:
)
await self.data_store.release_job(self.identity, job.task_id, result)
finally:
- job_info.reset(token)
+ current_job.reset(token)
finally:
self._running_jobs.remove(job.id)
diff --git a/src/apscheduler/workers/sync.py b/src/apscheduler/workers/sync.py
index 16265e8..1d8f85a 100644
--- a/src/apscheduler/workers/sync.py
+++ b/src/apscheduler/workers/sync.py
@@ -15,7 +15,7 @@ from uuid import UUID
import attrs
-from .._context import current_worker, job_info
+from .._context import current_job, current_worker
from .._enums import JobOutcome, RunState
from .._events import JobAdded, WorkerStarted, WorkerStopped
from .._structures import Job, JobInfo, JobResult
@@ -206,7 +206,7 @@ class Worker:
self.data_store.release_job(self.identity, job.task_id, result)
return
- token = job_info.set(JobInfo.from_job(job))
+ token = current_job.set(JobInfo.from_job(job))
try:
retval = func(*job.args, **job.kwargs)
except BaseException as exc:
@@ -222,6 +222,6 @@ class Worker:
)
self.data_store.release_job(self.identity, job.task_id, result)
finally:
- job_info.reset(token)
+ current_job.reset(token)
finally:
self._running_jobs.remove(job.id)
diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py
index e25f0ee..7bf0ef0 100644
--- a/tests/test_schedulers.py
+++ b/tests/test_schedulers.py
@@ -24,9 +24,9 @@ from apscheduler import (
SchedulerStopped,
Task,
TaskAdded,
+ current_job,
current_scheduler,
current_worker,
- job_info,
)
from apscheduler.schedulers.async_ import AsyncScheduler
from apscheduler.schedulers.sync import Scheduler
@@ -200,7 +200,7 @@ class TestAsyncScheduler:
def check_contextvars() -> None:
assert current_scheduler.get() is scheduler
assert isinstance(current_worker.get(), AsyncWorker)
- info = job_info.get()
+ info = current_job.get()
assert info.task_id == "task_id"
assert info.schedule_id == "foo"
assert info.scheduled_fire_time == scheduled_fire_time
@@ -375,7 +375,7 @@ class TestSyncScheduler:
def check_contextvars() -> None:
assert current_scheduler.get() is scheduler
assert current_worker.get() is not None
- info = job_info.get()
+ info = current_job.get()
assert info.task_id == "task_id"
assert info.schedule_id == "foo"
assert info.scheduled_fire_time == scheduled_fire_time