reykit 1.1.90__py3-none-any.whl → 1.1.91__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,7 +17,7 @@ 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
 
@@ -35,6 +35,7 @@ class Schedule(Base):
35
35
  Attributes
36
36
  ----------
37
37
  db_names : Database table name mapping dictionary.
38
+ Error : Database `schedule` table model.
38
39
  """
39
40
 
40
41
  db_names = {
@@ -43,13 +44,23 @@ class Schedule(Base):
43
44
  }
44
45
 
45
46
 
47
+ class Schedule(rorm.Model, table=True):
48
+ __comment__ = 'Schedule execute record table.'
49
+ create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
50
+ update_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
51
+ id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='ID.')
52
+ 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.')
53
+ task: str = rorm.Field(field_type=rorm.types.VARCHAR(100), not_null=True, comment='Schedule task function name.')
54
+ note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Schedule note.')
55
+
56
+
46
57
  def __init__(
47
58
  self,
48
59
  max_workers: int = 10,
49
60
  max_instances: int = 1,
50
61
  coalesce: bool = True,
51
62
  block: bool = False,
52
- db: Database | DatabaseAsync | None = None
63
+ db: Database | None = None
53
64
  ) -> None:
54
65
  """
55
66
  Build instance attributes.
@@ -93,6 +104,103 @@ class Schedule(Base):
93
104
  self.db = db
94
105
 
95
106
 
107
+ def handle_build_db(self) -> tuple[list[type[Schedule]], list[dict[str, Any]]]:
108
+ """
109
+ Handle method of check and build database tables, by `self.db_names`.
110
+
111
+ Returns
112
+ -------
113
+ Build database parameter.
114
+ """
115
+
116
+ # Check.
117
+ if self.db is None:
118
+ throw(ValueError, self.db)
119
+
120
+ # Set parameter.
121
+ self.Schedule._name(self.db_names['schedule'])
122
+
123
+ ## Table.
124
+ tables = [self.Schedule]
125
+
126
+ ## View stats.
127
+ views_stats = [
128
+ {
129
+ 'path': self.db_names['stats_schedule'],
130
+ 'items': [
131
+ {
132
+ 'name': 'count',
133
+ 'select': (
134
+ 'SELECT COUNT(1)\n'
135
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
136
+ ),
137
+ 'comment': 'Schedule count.'
138
+ },
139
+ {
140
+ 'name': 'past_day_count',
141
+ 'select': (
142
+ 'SELECT COUNT(1)\n'
143
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
144
+ 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
145
+ ),
146
+ 'comment': 'Schedule count in the past day.'
147
+ },
148
+ {
149
+ 'name': 'past_week_count',
150
+ 'select': (
151
+ 'SELECT COUNT(1)\n'
152
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
153
+ 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
154
+ ),
155
+ 'comment': 'Schedule count in the past week.'
156
+ },
157
+ {
158
+ 'name': 'past_month_count',
159
+ 'select': (
160
+ 'SELECT COUNT(1)\n'
161
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`\n'
162
+ 'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
163
+ ),
164
+ 'comment': 'Schedule count in the past month.'
165
+ },
166
+ {
167
+ 'name': 'task_count',
168
+ 'select': (
169
+ 'SELECT COUNT(DISTINCT `task`)\n'
170
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
171
+ ),
172
+ 'comment': 'Task count.'
173
+ },
174
+ {
175
+ 'name': 'last_time',
176
+ 'select': (
177
+ 'SELECT IFNULL(MAX(`update_time`), MAX(`create_time`))\n'
178
+ f'FROM `{self.db.database}`.`{self.db_names['schedule']}`'
179
+ ),
180
+ 'comment': 'Schedule last record time.'
181
+ }
182
+ ]
183
+ }
184
+ ]
185
+
186
+ return tables, views_stats
187
+
188
+
189
+ def build_db(self) -> None:
190
+ """
191
+ Check and build database tables, by `self.db_names`.
192
+ """
193
+
194
+ # Get parameter.
195
+ tables, views_stats = self.handle_build_db()
196
+
197
+ # Build.
198
+ self.db.build.build(tables=tables, views_stats=views_stats, skip=True)
199
+
200
+ # ## Error.
201
+ self.db.error.build_db()
202
+
203
+
96
204
  def pause(self) -> None:
97
205
  """
98
206
  Pause scheduler.
@@ -126,6 +234,9 @@ class Schedule(Base):
126
234
  return jobs
127
235
 
128
236
 
237
+ __iter__ = tasks
238
+
239
+
129
240
  def wrap_record_db(
130
241
  self,
131
242
  task: Callable,
@@ -374,96 +485,3 @@ class Schedule(Base):
374
485
 
375
486
  # Resume.
376
487
  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.91
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=rXECyOjUUpOTO6gMsl5ehdFSLAQdSy7e7d2QPzDyEwY,12975
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.91.dist-info/METADATA,sha256=ZbSn5m-l-_BZPVeGZL2xMsKqoMOMh4zSDBma5FrGscI,1872
26
+ reykit-1.1.91.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ reykit-1.1.91.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
+ reykit-1.1.91.dist-info/RECORD,,