@@ -76,6 +76,17 @@ class JobQueue(Generic[CCT]):
76
76
Attributes:
77
77
scheduler (:class:`apscheduler.schedulers.asyncio.AsyncIOScheduler`): The scheduler.
78
78
79
+ Warning:
80
+ This scheduler is configured by :meth:`set_application`. Additional configuration
81
+ settings can be made by users. However, calling
82
+ :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` will delete any
83
+ previous configuration settings. Therefore, please make sure to pass the values
84
+ returned by :attr:`scheduler_configuration` to the method call in addition to your
85
+ custom values.
86
+ Alternatively, you can also use methods like
87
+ :meth:`~apscheduler.schedulers.base.BaseScheduler.add_jobstore` to avoid using
88
+ :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` altogether.
89
+
79
90
.. versionchanged:: 20.0
80
91
Uses :class:`~apscheduler.schedulers.asyncio.AsyncIOScheduler` instead of
81
92
:class:`~apscheduler.schedulers.background.BackgroundScheduler`
@@ -94,9 +105,7 @@ def __init__(self) -> None:
94
105
95
106
self ._application : Optional [weakref .ReferenceType [Application ]] = None
96
107
self ._executor = AsyncIOExecutor ()
97
- self .scheduler : AsyncIOScheduler = AsyncIOScheduler (
98
- timezone = pytz .utc , executors = {"default" : self ._executor }
99
- )
108
+ self .scheduler : AsyncIOScheduler = AsyncIOScheduler (** self .scheduler_configuration )
100
109
101
110
def __repr__ (self ) -> str :
102
111
"""Give a string representation of the JobQueue in the form ``JobQueue[application=...]``.
@@ -119,6 +128,43 @@ def application(self) -> "Application[Any, CCT, Any, Any, Any, JobQueue[CCT]]":
119
128
return application
120
129
raise RuntimeError ("The application instance is no longer alive." )
121
130
131
+ @property
132
+ def scheduler_configuration (self ) -> JSONDict :
133
+ """Provides configuration values that are used by :class:`JobQueue` for :attr:`scheduler`.
134
+
135
+ Tip:
136
+ Since calling
137
+ :meth:`scheduler.configure() <apscheduler.schedulers.base.BaseScheduler.configure>`
138
+ deletes any previous setting, please make sure to pass these values to the method call
139
+ in addition to your custom values:
140
+
141
+ .. code-block:: python
142
+
143
+ scheduler.configure(..., **job_queue.scheduler_configuration)
144
+
145
+ Alternatively, you can also use methods like
146
+ :meth:`~apscheduler.schedulers.base.BaseScheduler.add_jobstore` to avoid using
147
+ :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` altogether.
148
+
149
+ .. versionadded:: NEXT.VERSION
150
+
151
+ Returns:
152
+ Dict[:obj:`str`, :obj:`object`]: The configuration values as dictionary.
153
+
154
+ """
155
+ timezone : object = pytz .utc
156
+ if (
157
+ self ._application
158
+ and isinstance (self .application .bot , ExtBot )
159
+ and self .application .bot .defaults
160
+ ):
161
+ timezone = self .application .bot .defaults .tzinfo or pytz .utc
162
+
163
+ return {
164
+ "timezone" : timezone ,
165
+ "executors" : {"default" : self ._executor },
166
+ }
167
+
122
168
def _tz_now (self ) -> datetime .datetime :
123
169
return datetime .datetime .now (self .scheduler .timezone )
124
170
@@ -166,11 +212,7 @@ def set_application(
166
212
167
213
"""
168
214
self ._application = weakref .ref (application )
169
- if isinstance (application .bot , ExtBot ) and application .bot .defaults :
170
- self .scheduler .configure (
171
- timezone = application .bot .defaults .tzinfo or pytz .utc ,
172
- executors = {"default" : self ._executor },
173
- )
215
+ self .scheduler .configure (** self .scheduler_configuration )
174
216
175
217
@staticmethod
176
218
async def job_callback (job_queue : "JobQueue[CCT]" , job : "Job[CCT]" ) -> None :
0 commit comments