Skip to content

Commit 15e8054

Browse files
authored
Merge pull request #83 from Integration-Automation/dev
Update doc
2 parents 8fc092c + 686644d commit 15e8054

File tree

6 files changed

+242
-9
lines changed

6 files changed

+242
-9
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Scheduler
2+
----
3+
4+
You can use scheduling to perform repetitive tasks, either by using a simple wrapper for APScheduler or by consulting the API documentation to use it yourself.
5+
6+
.. code-block:: python
7+
8+
from je_load_density import SchedulerManager
9+
10+
11+
def test_scheduler():
12+
print("Test Scheduler")
13+
scheduler.remove_blocking_job(id="test")
14+
scheduler.shutdown_blocking_scheduler()
15+
16+
17+
scheduler = SchedulerManager()
18+
scheduler.add_interval_blocking_secondly(function=test_scheduler, id="test")
19+
scheduler.start_block_scheduler()

docs/source/En/en_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ LoadDensity English Documentation
77
doc/installation/installation_doc.rst
88
doc/getting_started/getting_started_doc.rst
99
doc/cli/cli_doc.rst
10+
doc/scheduler/scheduler_doc.rst
1011
doc/generate_report/generate_report_doc.rst
1112

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Scheduler
2+
----
3+
4+
可以使用排程來執行重複的任務,可以使用對 APScheduler 的簡易包裝或是觀看 API 文件自行使用
5+
6+
.. code-block:: python
7+
8+
from je_load_density import SchedulerManager
9+
10+
11+
def test_scheduler():
12+
print("Test Scheduler")
13+
scheduler.remove_blocking_job(id="test")
14+
scheduler.shutdown_blocking_scheduler()
15+
16+
17+
scheduler = SchedulerManager()
18+
scheduler.add_interval_blocking_secondly(function=test_scheduler, id="test")
19+
scheduler.start_block_scheduler()

docs/source/Zh/zh_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ LoadDensity 繁體中文文件
77
doc/installation/installation_doc.rst
88
doc/getting_started/getting_started_doc.rst
99
doc/cli/cli_doc.rst
10+
doc/scheduler/scheduler_doc.rst
1011
doc/generate_report/generate_report_doc.rst

docs/source/api/api_index.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
LoadDensity API Documentation
2-
=============================================
2+
----
33

44
.. toctree::
5-
:maxdepth: 4
5+
:maxdepth: 4
66

7-
utils/callback.rst
8-
utils/executor.rst
9-
utils/file.rst
10-
utils/generate_report.rst
11-
utils/package_manager.rst
12-
utils/socket_server.rst
13-
loaddensity/loaddensity.rst
7+
utils/callback.rst
8+
utils/executor.rst
9+
utils/file.rst
10+
utils/generate_report.rst
11+
utils/package_manager.rst
12+
utils/socket_server.rst
13+
utils/scheduler.rst
14+
loaddensity/loaddensity.rst
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
Scheduler API
2+
----
3+
4+
.. code-block:: python
5+
6+
def add_blocking_job(
7+
self, func: Callable, trigger: str = None, args: Union[list, tuple] = None,
8+
kwargs: dict = None, id: str = None, name: str = None,
9+
misfire_grace_time: int = undefined, coalesce: bool = undefined, max_instances: int = undefined,
10+
next_run_time: datetime = undefined, jobstore: str = 'default', executor: str = 'default',
11+
replace_existing: bool = False, **trigger_args: Any) -> Job:
12+
"""
13+
Just an apscheduler add job wrapper.
14+
:param func: callable (or a textual reference to one) to run at the given time
15+
:param str|apscheduler.triggers.base.BaseTrigger trigger: trigger that determines when
16+
``func`` is called
17+
:param list|tuple args: list of positional arguments to call func with
18+
:param dict kwargs: dict of keyword arguments to call func with
19+
:param str|unicode id: explicit identifier for the job (for modifying it later)
20+
:param str|unicode name: textual description of the job
21+
:param int misfire_grace_time: seconds after the designated runtime that the job is still
22+
allowed to be run (or ``None`` to allow the job to run no matter how late it is)
23+
:param bool coalesce: run once instead of many times if the scheduler determines that the
24+
job should be run more than once in succession
25+
:param int max_instances: maximum number of concurrently running instances allowed for this
26+
job
27+
:param datetime next_run_time: when to first run the job, regardless of the trigger (pass
28+
``None`` to add the job as paused)
29+
:param str|unicode jobstore: alias of the job store to store the job in
30+
:param str|unicode executor: alias of the executor to run the job with
31+
:param bool replace_existing: ``True`` to replace an existing job with the same ``id``
32+
(but retain the number of runs from the existing one)
33+
:return: Job
34+
"""
35+
36+
.. code-block:: python
37+
38+
def add_nonblocking_job(
39+
self, func: Callable, trigger: str = None, args: Union[list, tuple] = None,
40+
kwargs: dict = None, id: str = None, name: str = None,
41+
misfire_grace_time: int = undefined, coalesce: bool = undefined, max_instances: int = undefined,
42+
next_run_time: datetime = undefined, jobstore: str = 'default', executor: str = 'default',
43+
replace_existing: bool = False, **trigger_args: Any) -> Job:
44+
"""
45+
Just an apscheduler add job wrapper.
46+
:param func: callable (or a textual reference to one) to run at the given time
47+
:param str|apscheduler.triggers.base.BaseTrigger trigger: trigger that determines when
48+
``func`` is called
49+
:param list|tuple args: list of positional arguments to call func with
50+
:param dict kwargs: dict of keyword arguments to call func with
51+
:param str|unicode id: explicit identifier for the job (for modifying it later)
52+
:param str|unicode name: textual description of the job
53+
:param int misfire_grace_time: seconds after the designated runtime that the job is still
54+
allowed to be run (or ``None`` to allow the job to run no matter how late it is)
55+
:param bool coalesce: run once instead of many times if the scheduler determines that the
56+
job should be run more than once in succession
57+
:param int max_instances: maximum number of concurrently running instances allowed for this
58+
job
59+
:param datetime next_run_time: when to first run the job, regardless of the trigger (pass
60+
``None`` to add the job as paused)
61+
:param str|unicode jobstore: alias of the job store to store the job in
62+
:param str|unicode executor: alias of the executor to run the job with
63+
:param bool replace_existing: ``True`` to replace an existing job with the same ``id``
64+
(but retain the number of runs from the existing one)
65+
:return: Job
66+
"""
67+
68+
.. code-block:: python
69+
70+
def get_blocking_scheduler(self) -> BlockingScheduler:
71+
"""
72+
Return self blocking scheduler
73+
:return: BlockingScheduler
74+
"""
75+
76+
.. code-block:: python
77+
78+
def get_nonblocking_scheduler(self) -> BackgroundScheduler:
79+
"""
80+
Return self background scheduler
81+
:return: BackgroundScheduler
82+
"""
83+
84+
.. code-block:: python
85+
86+
def start_block_scheduler(self, *args: Any, **kwargs: Any) -> None:
87+
"""
88+
Start blocking scheduler
89+
:return: None
90+
"""
91+
92+
.. code-block:: python
93+
94+
def start_nonblocking_scheduler(self, *args: Any, **kwargs: Any) -> None:
95+
"""
96+
Start background scheduler
97+
:return: None
98+
"""
99+
100+
.. code-block:: python
101+
102+
def start_all_scheduler(self, *args: Any, **kwargs: Any) -> None:
103+
"""
104+
Start background and blocking scheduler
105+
:return: None
106+
"""
107+
108+
.. code-block:: python
109+
110+
def add_interval_blocking_secondly(
111+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
112+
kwargs: dict = None, seconds: int = 1, **trigger_args: Any) -> Job:
113+
114+
.. code-block:: python
115+
116+
def add_interval_blocking_minutely(
117+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
118+
kwargs: dict = None, minutes: int = 1, **trigger_args: Any) -> Job:
119+
120+
.. code-block:: python
121+
122+
def add_interval_blocking_hourly(
123+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
124+
kwargs: dict = None, hours: int = 1, **trigger_args: Any) -> Job:
125+
126+
.. code-block:: python
127+
128+
def add_interval_blocking_daily(
129+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
130+
kwargs: dict = None, days: int = 1, **trigger_args: Any) -> Job:
131+
132+
.. code-block:: python
133+
134+
def add_interval_blocking_weekly(
135+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
136+
kwargs: dict = None, weeks: int = 1, **trigger_args: Any) -> Job:
137+
138+
.. code-block:: python
139+
140+
def add_interval_nonblocking_secondly(
141+
self, function: Callable, id: str = None, args: list = None,
142+
kwargs: dict = None, seconds: int = 1, **trigger_args: Any) -> Job:
143+
144+
.. code-block:: python
145+
146+
def add_interval_nonblocking_minutely(
147+
self, function: Callable, id: str = None, args: list = None,
148+
kwargs: dict = None, minutes: int = 1, **trigger_args: Any) -> Job:
149+
150+
.. code-block:: python
151+
152+
def add_interval_nonblocking_hourly(
153+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
154+
kwargs: dict = None, hours: int = 1, **trigger_args: Any) -> Job:
155+
156+
.. code-block:: python
157+
158+
def add_interval_nonblocking_daily(
159+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
160+
kwargs: dict = None, days: int = 1, **trigger_args: Any) -> Job:
161+
162+
.. code-block:: python
163+
164+
def add_interval_nonblocking_weekly(
165+
self, function: Callable, id: str = None, args: Union[list, tuple] = None,
166+
kwargs: dict = None, weeks: int = 1, **trigger_args: Any) -> Job:
167+
168+
.. code-block:: python
169+
170+
def add_cron_blocking(
171+
self, function: Callable, id: str = None, **trigger_args: Any) -> Job:
172+
173+
.. code-block:: python
174+
175+
def add_cron_nonblocking(
176+
self, function: Callable, id: str = None, **trigger_args: Any) -> Job:
177+
178+
.. code-block:: python
179+
180+
def remove_blocking_job(self, id: str, jobstore: str = 'default') -> Any:
181+
182+
.. code-block:: python
183+
184+
def remove_nonblocking_job(self, id: str, jobstore: str = 'default') -> Any:
185+
186+
.. code-block:: python
187+
188+
def shutdown_blocking_scheduler(self, wait: bool = False) -> None:
189+
190+
.. code-block:: python
191+
192+
def shutdown_nonblocking_scheduler(self, wait: bool = False) -> None:

0 commit comments

Comments
 (0)