reykit 1.1.90__py3-none-any.whl → 1.1.92__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
reykit/rschedule.py CHANGED
@@ -17,16 +17,31 @@ from apscheduler.schedulers.background import BackgroundScheduler
17
17
  from apscheduler.schedulers.blocking import BlockingScheduler
18
18
  from apscheduler.job import Job
19
19
  from reydb import rorm
20
- from reydb.rdb import Database, DatabaseAsync
20
+ from reydb.rdb import Database
21
21
 
22
22
  from .rbase import Base, throw
23
23
 
24
24
 
25
25
  __all__ = (
26
- 'Schedule',
26
+ 'TableSchedule',
27
+ 'Schedule'
27
28
  )
28
29
 
29
30
 
31
+ class TableSchedule(rorm.Model, table=True):
32
+ """
33
+ Database `schedule` table model.
34
+ """
35
+
36
+ __comment__ = 'Schedule execute record table.'
37
+ create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
38
+ update_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
39
+ id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='ID.')
40
+ status: str = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), not_null=True, comment='Schedule status, 0 is executing, 1 is completed, 2 is occurred error.')
41
+ task: str = rorm.Field(field_type=rorm.types.VARCHAR(100), not_null=True, comment='Schedule task function name.')
42
+ note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Schedule note.')
43
+
44
+
30
45
  class Schedule(Base):
31
46
  """
32
47
  Schedule type.
@@ -49,7 +64,7 @@ class Schedule(Base):
49
64
  max_instances: int = 1,
50
65
  coalesce: bool = True,
51
66
  block: bool = False,
52
- db: Database | DatabaseAsync | None = None
67
+ db: Database | None = None
53
68
  ) -> None:
54
69
  """
55
70
  Build instance attributes.
@@ -93,6 +108,103 @@ class Schedule(Base):
93
108
  self.db = db
94
109
 
95
110
 
111
+ def handle_build_db(self) -> tuple[list[type[TableSchedule]], list[dict[str, Any]]]:
112
+ """
113
+ Handle method of check and build database tables, by `self.db_names`.
114
+
115
+ Returns
116
+ -------
117
+ Build database parameter.
118
+ """
119
+
120
+ # Check.
121
+ if self.db is None:
122
+ throw(ValueError, self.db)
123
+
124
+ # Set parameter.
125
+ TableSchedule._set_name(self.db_names['schedule'])
126
+
127
+ ## Table.
128
+ tables = [TableSchedule]
129
+
130
+ ## View stats.
131
+ views_stats = [
132
+ {
133
+ 'path': self.db_names['stats_schedule'],
134
+ 'items': [
135
+ {
136
+ 'name': 'count',
137
+ 'select': (
138
+ 'SELECT COUNT(1)\n'
139
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
140
+ ),
141
+ 'comment': 'Schedule count.'
142
+ },
143
+ {
144
+ 'name': 'past_day_count',
145
+ 'select': (
146
+ 'SELECT COUNT(1)\n'
147
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
148
+ 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
149
+ ),
150
+ 'comment': 'Schedule count in the past day.'
151
+ },
152
+ {
153
+ 'name': 'past_week_count',
154
+ 'select': (
155
+ 'SELECT COUNT(1)\n'
156
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
157
+ 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
158
+ ),
159
+ 'comment': 'Schedule count in the past week.'
160
+ },
161
+ {
162
+ 'name': 'past_month_count',
163
+ 'select': (
164
+ 'SELECT COUNT(1)\n'
165
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
166
+ 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
167
+ ),
168
+ 'comment': 'Schedule count in the past month.'
169
+ },
170
+ {
171
+ 'name': 'task_count',
172
+ 'select': (
173
+ 'SELECT COUNT(DISTINCT `task`)\n'
174
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
175
+ ),
176
+ 'comment': 'Task count.'
177
+ },
178
+ {
179
+ 'name': 'last_time',
180
+ 'select': (
181
+ 'SELECT IFNULL(MAX(`update_time`), MAX(`create_time`))\n'
182
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
183
+ ),
184
+ 'comment': 'Schedule last record time.'
185
+ }
186
+ ]
187
+ }
188
+ ]
189
+
190
+ return tables, views_stats
191
+
192
+
193
+ def build_db(self) -> None:
194
+ """
195
+ Check and build database tables, by `self.db_names`.
196
+ """
197
+
198
+ # Get parameter.
199
+ tables, views_stats = self.handle_build_db()
200
+
201
+ # Build.
202
+ self.db.build.build(tables=tables, views_stats=views_stats, skip=True)
203
+
204
+ # ## Error.
205
+ self.db.error.build_db()
206
+
207
+
96
208
  def pause(self) -> None:
97
209
  """
98
210
  Pause scheduler.
@@ -126,6 +238,9 @@ class Schedule(Base):
126
238
  return jobs
127
239
 
128
240
 
241
+ __iter__ = tasks
242
+
243
+
129
244
  def wrap_record_db(
130
245
  self,
131
246
  task: Callable,
@@ -374,96 +489,3 @@ class Schedule(Base):
374
489
 
375
490
  # Resume.
376
491
  self.scheduler.resume_job(id_)
377
-
378
-
379
- def build_db(self) -> None:
380
- """
381
- Check and build database tables, by `self.db_names`.
382
- """
383
-
384
- # Check.
385
- if self.db is None:
386
- throw(ValueError, self.db)
387
-
388
- # Set parameter.
389
-
390
- ## Table.
391
- class Schedule(rorm.Model, table=True):
392
- __name__ = self.db_names['schedule']
393
- __comment__ = 'Schedule execute record table.'
394
- create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
395
- update_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
396
- id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='ID.')
397
- status: str = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), not_null=True, comment='Schedule status, 0 is executing, 1 is completed, 2 is occurred error.')
398
- task: str = rorm.Field(field_type=rorm.types.VARCHAR(100), not_null=True, comment='Schedule task function name.')
399
- note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Schedule note.')
400
- tables = [Schedule]
401
-
402
- ## View stats.
403
- views_stats = [
404
- {
405
- 'path': self.db_names['stats_schedule'],
406
- 'items': [
407
- {
408
- 'name': 'count',
409
- 'select': (
410
- 'SELECT COUNT(1)\n'
411
- f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
412
- ),
413
- 'comment': 'Schedule count.'
414
- },
415
- {
416
- 'name': 'past_day_count',
417
- 'select': (
418
- 'SELECT COUNT(1)\n'
419
- f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
420
- 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
421
- ),
422
- 'comment': 'Schedule count in the past day.'
423
- },
424
- {
425
- 'name': 'past_week_count',
426
- 'select': (
427
- 'SELECT COUNT(1)\n'
428
- f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
429
- 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
430
- ),
431
- 'comment': 'Schedule count in the past week.'
432
- },
433
- {
434
- 'name': 'past_month_count',
435
- 'select': (
436
- 'SELECT COUNT(1)\n'
437
- f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
438
- 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
439
- ),
440
- 'comment': 'Schedule count in the past month.'
441
- },
442
- {
443
- 'name': 'task_count',
444
- 'select': (
445
- 'SELECT COUNT(DISTINCT `task`)\n'
446
- f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
447
- ),
448
- 'comment': 'Task count.'
449
- },
450
- {
451
- 'name': 'last_time',
452
- 'select': (
453
- 'SELECT IFNULL(MAX(`update_time`), MAX(`create_time`))\n'
454
- f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
455
- ),
456
- 'comment': 'Schedule last record time.'
457
- }
458
- ]
459
- }
460
- ]
461
-
462
- # Build.
463
- self.db.build.build(tables=tables, views_stats=views_stats, skip=True)
464
-
465
- ## Error.
466
- self.db.error.build_db()
467
-
468
-
469
- __iter__ = tasks
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reykit
3
- Version: 1.1.90
3
+ Version: 1.1.92
4
4
  Summary: Kit method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reykit/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -11,7 +11,7 @@ reykit/rnum.py,sha256=jEhPQatAAaIV6kPx2tVtfjuK0F09UCWU6BjfPRamqBE,3620
11
11
  reykit/ros.py,sha256=n9aqChdRQQFozOn_jXQns_UrKoEstCNRzFTgOBel4wM,47787
12
12
  reykit/rrand.py,sha256=kh9yWOW8zaj8bUU0H0RL_GiOs2K8JDviVzKSoPLEuls,8566
13
13
  reykit/rre.py,sha256=uqqved1_SWrJOQK-o5WYRoJf3JH0YpEktnxwA0x7TPU,6018
14
- reykit/rschedule.py,sha256=qYNmD0lGEysvQtIa6RBRi1xAG1Yv4ry0Hd8E4StYxho,12590
14
+ reykit/rschedule.py,sha256=xQeKlGGKAMsLRIdxIBbd3RHw3O2d9bejq9idK9ZoBzQ,12990
15
15
  reykit/rstdout.py,sha256=bLN_kXsWpgTrCrBJNgaEE27DUk-ojsBV-9YJtWH41b4,8188
16
16
  reykit/rsys.py,sha256=PEXUU_jyglEgIyN-URtnpUcrqKF5PFeAVAljEmaSqOs,24931
17
17
  reykit/rtable.py,sha256=ItsycFuN-gb3gYhHuMx_nbAluGc8tAIMOyD5DHPS-lU,12173
@@ -22,7 +22,7 @@ reykit/rwrap.py,sha256=8MqbOjq56DbDKuTix75wYGXcAykzLiAPKrgl13Gk4xQ,15086
22
22
  reykit/rzip.py,sha256=u-yyEFXY5iOysgzzqEbaaDTFfoHBj0L2sv5m4AQLt1c,3450
23
23
  reykit/rdll/__init__.py,sha256=TEVZjiW9Y1_VxbZgIygcwmRp5xFHM2wLgwZccZ6gjng,698
24
24
  reykit/rdll/rdll_core.py,sha256=o6-rKcTQgxZQe0kD3GnwyNb3KL9IogzgCQNOmYLMm7A,5086
25
- reykit-1.1.90.dist-info/METADATA,sha256=4OArpOMbswgG_c51TvPq5X0iws7jVFrdGC3SWp8P9Po,1872
26
- reykit-1.1.90.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- reykit-1.1.90.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
- reykit-1.1.90.dist-info/RECORD,,
25
+ reykit-1.1.92.dist-info/METADATA,sha256=yInLHMpchvta0ERsIz57idu5qdNOoJWLJzzuekf-WQQ,1872
26
+ reykit-1.1.92.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ reykit-1.1.92.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
+ reykit-1.1.92.dist-info/RECORD,,