ddeutil-workflow 0.0.48__py3-none-any.whl → 0.0.49__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.
@@ -4,7 +4,9 @@
4
4
  # license information.
5
5
  # ------------------------------------------------------------------------------
6
6
  # [x] Use dynamic config
7
- """A Workflow module that is the core model of this package."""
7
+ """A Workflow module that is the core module of this package. It keeps Release
8
+ and Workflow Pydantic models.
9
+ """
8
10
  from __future__ import annotations
9
11
 
10
12
  import copy
@@ -98,8 +100,8 @@ class Release:
98
100
 
99
101
  :param dt: (datetime | str) A datetime object or string that want to
100
102
  construct to the Release object.
101
- :param extras: An extra parameters that want to pass to override
102
- config.
103
+ :param extras: (DictData) An extra parameters that want to pass to
104
+ override config values.
103
105
 
104
106
  :raise TypeError: If the type of the dt argument does not valid with
105
107
  datetime or str object.
@@ -159,7 +161,7 @@ class ReleaseQueue:
159
161
  complete: list[Release] = field(default_factory=list)
160
162
  extras: DictData = Field(
161
163
  default_factory=dict,
162
- description="An extra override config values.",
164
+ description="An extra parameters that want to override config values.",
163
165
  )
164
166
 
165
167
  @classmethod
@@ -172,7 +174,8 @@ class ReleaseQueue:
172
174
  with list of datetime or list of Release.
173
175
 
174
176
  :param queue:
175
- :param extras: An extra parameter that want to override core config.
177
+ :param extras: An extra parameter that want to override core config
178
+ values.
176
179
 
177
180
  :raise TypeError: If the type of input queue does not valid.
178
181
 
@@ -251,7 +254,7 @@ class ReleaseQueue:
251
254
  heappush(self.complete, value)
252
255
 
253
256
  # NOTE: Remove complete queue on workflow that keep more than the
254
- # maximum config.
257
+ # maximum config value.
255
258
  num_complete_delete: int = len(self.complete) - dynamic(
256
259
  "max_queue_complete_hist", extras=self.extras
257
260
  )
@@ -262,6 +265,70 @@ class ReleaseQueue:
262
265
 
263
266
  return self
264
267
 
268
+ def gen(
269
+ self,
270
+ end_date: datetime,
271
+ audit: type[Audit],
272
+ runner: CronRunner,
273
+ name: str,
274
+ *,
275
+ offset: float = 0,
276
+ force_run: bool = False,
277
+ extras: Optional[DictData] = None,
278
+ ) -> Self:
279
+ """Generate Release model to queue.
280
+
281
+ Steps:
282
+ - Create Release object from the current date that not reach the end
283
+ date.
284
+ - Check this release do not store on the release queue object.
285
+ Generate the next date if it exists.
286
+ - Push this release to the release queue
287
+
288
+ :param end_date: (datetime) An end datetime object.
289
+ :param audit: (type[Audit]) An audit class that want to make audit
290
+ instance.
291
+ :param runner: (CronRunner) A CronRunner object.
292
+ :param name: (str) A target name that want to check at pointer of audit.
293
+ :param offset: (float) An offset in second unit for time travel.
294
+ :param force_run: A flag that allow to release workflow if the audit
295
+ with that release was pointed.
296
+ :param extras: An extra parameter that want to override core config.
297
+
298
+ :rtype: ReleaseQueue
299
+
300
+ """
301
+ if runner.date > end_date:
302
+ return self
303
+
304
+ workflow_release = Release(
305
+ date=runner.date,
306
+ offset=offset,
307
+ end_date=end_date,
308
+ runner=runner,
309
+ type=ReleaseType.POKE,
310
+ )
311
+
312
+ while self.check_queue(workflow_release) or (
313
+ audit.is_pointed(
314
+ name=name, release=workflow_release.date, extras=extras
315
+ )
316
+ and not force_run
317
+ ):
318
+ workflow_release = Release(
319
+ date=runner.next,
320
+ offset=offset,
321
+ end_date=end_date,
322
+ runner=runner,
323
+ type=ReleaseType.POKE,
324
+ )
325
+
326
+ if runner.date > end_date:
327
+ return self
328
+
329
+ heappush(self.queue, workflow_release)
330
+ return self
331
+
265
332
 
266
333
  class Workflow(BaseModel):
267
334
  """Workflow Pydantic model.
@@ -274,7 +341,7 @@ class Workflow(BaseModel):
274
341
 
275
342
  extras: DictData = Field(
276
343
  default_factory=dict,
277
- description="An extra override config values.",
344
+ description="An extra parameters that want to override config values.",
278
345
  )
279
346
 
280
347
  name: str = Field(description="A workflow name.")
@@ -344,8 +411,8 @@ class Workflow(BaseModel):
344
411
 
345
412
  :param name: (str) A workflow name that want to pass to Loader object.
346
413
  :param path: (Path) A config path that want to search.
347
- :param extras: An extra parameters that want to pass to Loader
348
- object.
414
+ :param extras: (DictData) An extra parameters that want to override core
415
+ config values.
349
416
 
350
417
  :raise ValueError: If the type does not match with current object.
351
418
 
@@ -376,10 +443,10 @@ class Workflow(BaseModel):
376
443
  ) -> DictData:
377
444
  """Bypass the on data to loaded config data.
378
445
 
379
- :param data: A data to construct to this Workflow model.
380
- :param path: A config path.
381
- :param extras: An extra parameters that want to pass to SimLoad
382
- object.
446
+ :param data: (DictData) A data to construct to this Workflow model.
447
+ :param path: (Path) A config path.
448
+ :param extras: (DictData) An extra parameters that want to override core
449
+ config values.
383
450
 
384
451
  :rtype: DictData
385
452
  """
@@ -456,7 +523,7 @@ class Workflow(BaseModel):
456
523
 
457
524
  extras: Optional[DictData] = info.data.get("extras")
458
525
  if len(set_ons) > (
459
- conf := dynamic("max_on_per_workflow", extras=extras)
526
+ conf := dynamic("max_cron_per_workflow", extras=extras)
460
527
  ):
461
528
  raise ValueError(
462
529
  f"The number of the on should not more than {conf} crontabs."
@@ -494,8 +561,9 @@ class Workflow(BaseModel):
494
561
  return self
495
562
 
496
563
  def job(self, name: str) -> Job:
497
- """Return the workflow's job model that searching with an input job's
498
- name or job's ID.
564
+ """Return the workflow's Job model that getting by an input job's name
565
+ or job's ID. This method will pass an extra parameter from this model
566
+ to the returned Job model.
499
567
 
500
568
  :param name: (str) A job name or ID that want to get from a mapping of
501
569
  job models.
@@ -712,14 +780,6 @@ class Workflow(BaseModel):
712
780
  """Generate Release from all on values from the on field and store them
713
781
  to the ReleaseQueue object.
714
782
 
715
- Steps:
716
- - For-loop all the on value in the on field.
717
- - Create Release object from the current date that not reach the end
718
- date.
719
- - Check this release do not store on the release queue object.
720
- Generate the next date if it exists.
721
- - Push this release to the release queue
722
-
723
783
  :param offset: An offset in second unit for time travel.
724
784
  :param end_date: An end datetime object.
725
785
  :param queue: A workflow queue object.
@@ -731,40 +791,19 @@ class Workflow(BaseModel):
731
791
  """
732
792
  for on in self.on:
733
793
 
734
- runner: CronRunner = on.next(
735
- get_dt_now(
736
- tz=dynamic("tz", extras=self.extras), offset=offset
737
- ).replace(microsecond=0)
738
- )
739
-
740
- if runner.date > end_date:
741
- continue
742
-
743
- workflow_release = Release(
744
- date=runner.date,
794
+ queue.gen(
795
+ end_date,
796
+ audit,
797
+ on.next(
798
+ get_dt_now(
799
+ tz=dynamic("tz", extras=self.extras), offset=offset
800
+ ).replace(microsecond=0)
801
+ ),
802
+ self.name,
745
803
  offset=offset,
746
- end_date=end_date,
747
- runner=runner,
748
- type=ReleaseType.POKE,
804
+ force_run=force_run,
749
805
  )
750
806
 
751
- while queue.check_queue(workflow_release) or (
752
- audit.is_pointed(name=self.name, release=workflow_release.date)
753
- and not force_run
754
- ):
755
- workflow_release = Release(
756
- date=runner.next,
757
- offset=offset,
758
- end_date=end_date,
759
- runner=runner,
760
- type=ReleaseType.POKE,
761
- )
762
-
763
- if runner.date > end_date:
764
- continue
765
-
766
- heappush(queue.queue, workflow_release)
767
-
768
807
  return queue
769
808
 
770
809
  def poke(
@@ -803,7 +842,7 @@ class Workflow(BaseModel):
803
842
  :rtype: Result
804
843
  :return: A list of all results that return from `self.release` method.
805
844
  """
806
- audit: type[Audit] = audit or get_audit()
845
+ audit: type[Audit] = audit or get_audit(extras=self.extras)
807
846
  result: Result = Result(
808
847
  run_id=(run_id or gen_id(self.name, unique=True))
809
848
  )
@@ -1315,10 +1354,11 @@ class WorkflowTask:
1315
1354
  arguments before passing to the parent release method.
1316
1355
  """
1317
1356
 
1318
- alias: str = field()
1319
- workflow: Workflow = field()
1320
- runner: CronRunner = field()
1357
+ alias: str
1358
+ workflow: Workflow
1359
+ runner: CronRunner
1321
1360
  values: DictData = field(default_factory=dict)
1361
+ extras: DictData = field(default_factory=dict)
1322
1362
 
1323
1363
  def release(
1324
1364
  self,
@@ -1345,7 +1385,7 @@ class WorkflowTask:
1345
1385
 
1346
1386
  :rtype: Result
1347
1387
  """
1348
- audit: type[Audit] = audit or get_audit()
1388
+ audit: type[Audit] = audit or get_audit(extras=self.extras)
1349
1389
 
1350
1390
  if release is None:
1351
1391
 
@@ -1395,35 +1435,15 @@ class WorkflowTask:
1395
1435
 
1396
1436
  :rtype: ReleaseQueue
1397
1437
  """
1398
- if self.runner.date > end_date:
1399
- return queue
1400
-
1401
- workflow_release = Release(
1402
- date=self.runner.date,
1403
- offset=0,
1404
- end_date=end_date,
1405
- runner=self.runner,
1406
- type=ReleaseType.TASK,
1438
+ return queue.gen(
1439
+ end_date,
1440
+ audit,
1441
+ self.runner,
1442
+ self.alias,
1443
+ force_run=force_run,
1444
+ extras=self.extras,
1407
1445
  )
1408
1446
 
1409
- while queue.check_queue(workflow_release) or (
1410
- audit.is_pointed(name=self.alias, release=workflow_release.date)
1411
- and not force_run
1412
- ):
1413
- workflow_release = Release(
1414
- date=self.runner.next,
1415
- offset=0,
1416
- end_date=end_date,
1417
- runner=self.runner,
1418
- type=ReleaseType.TASK,
1419
- )
1420
-
1421
- if self.runner.date > end_date:
1422
- return queue
1423
-
1424
- heappush(queue.queue, workflow_release)
1425
- return queue
1426
-
1427
1447
  def __repr__(self) -> str:
1428
1448
  """Override the `__repr__` method.
1429
1449
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ddeutil-workflow
3
- Version: 0.0.48
3
+ Version: 0.0.49
4
4
  Summary: Lightweight workflow orchestration
5
5
  Author-email: ddeutils <korawich.anu@gmail.com>
6
6
  License: MIT
@@ -262,14 +262,12 @@ it will use default value and do not raise any error to you.
262
262
 
263
263
  | Name | Component | Default | Description |
264
264
  |:-----------------------------|:---------:|:--------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------|
265
- | **ROOT_PATH** | Core | `.` | Root path or the project path for this workflow engine. |
266
265
  | **REGISTRY_CALLER** | Core | `.` | List of importable string for the call stage. |
267
266
  | **REGISTRY_FILTER** | Core | `ddeutil.workflow.templates` | List of importable string for the filter template. |
268
- | **CONF_PATH** | Core | `conf` | The config path that keep all template `.yaml` files. |
267
+ | **CONF_PATH** | Core | `./conf` | The config path that keep all template `.yaml` files. |
269
268
  | **TIMEZONE** | Core | `Asia/Bangkok` | A Timezone string value that will pass to `ZoneInfo` object. |
270
- | **STAGE_DEFAULT_ID** | Core | `true` | A flag that enable default stage ID that use for catch an execution output. |
269
+ | **STAGE_DEFAULT_ID** | Core | `false` | A flag that enable default stage ID that use for catch an execution output. |
271
270
  | **STAGE_RAISE_ERROR** | Core | `false` | A flag that all stage raise StageException from stage execution. |
272
- | **JOB_DEFAULT_ID** | Core | `false` | A flag that enable default job ID that use for catch an execution output. The ID that use will be sequence number. |
273
271
  | **JOB_RAISE_ERROR** | Core | `true` | A flag that all job raise JobException from job strategy execution. |
274
272
  | **MAX_CRON_PER_WORKFLOW** | Core | `5` | |
275
273
  | **MAX_QUEUE_COMPLETE_HIST** | Core | `16` | |
@@ -0,0 +1,31 @@
1
+ ddeutil/workflow/__about__.py,sha256=8c8KBEXeEOskazR5AlLYEjCpyi54xsoTaaqRY8pXUJY,28
2
+ ddeutil/workflow/__cron.py,sha256=h8rLeIUAAEB2SdZ4Jhch7LU1Yl3bbJ-iNNJ3tQ0eYVM,28095
3
+ ddeutil/workflow/__init__.py,sha256=EpqROKwAX76Wea-37hi0R_oVQ2jm2cc9ML9USxRAsak,1971
4
+ ddeutil/workflow/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ ddeutil/workflow/__types.py,sha256=8jBdbfb3aZSetjz0mvNrpGHwwxJff7mK8_4v41cLqlc,4316
6
+ ddeutil/workflow/conf.py,sha256=lviP7bFsOCJtD8S1VyJK6aaSL9Nj_vfC2Kkpe1z2Zec,12444
7
+ ddeutil/workflow/cron.py,sha256=80SijzMdDOBxTWRsiF-Fmuz7Ym7leY0XT2lzRAPGdXc,8781
8
+ ddeutil/workflow/exceptions.py,sha256=uLNxzav3HRcr4vaZnvbUIF_eTR6UXXZNaxroMWFOUL4,1418
9
+ ddeutil/workflow/job.py,sha256=y2q_md2nUp1jfgjaQdjDZqrHR541ENrWB__S1-Eoyss,30830
10
+ ddeutil/workflow/logs.py,sha256=JghQawGd16ysf-5y7ZFtSGFY82uwgb9oMKNYy9eGI-o,26468
11
+ ddeutil/workflow/params.py,sha256=xCtFEh0-G-G-f8y_SXxyf31bU6Ox5p5Z-WbBFXrjy8M,9960
12
+ ddeutil/workflow/result.py,sha256=kizTEP6DY9ewDQQR17YgfrtMXRW-wF8vRzG26wzAqUM,5439
13
+ ddeutil/workflow/reusables.py,sha256=hIpehea6J4OWeXX55kjYzo-c9-_Cc0YRwLRRbcaUkZs,17539
14
+ ddeutil/workflow/scheduler.py,sha256=F783QaJfPg8tvYyvJvkwl8Sa42vsJzj6BzzROZFvm9I,28153
15
+ ddeutil/workflow/stages.py,sha256=2vO5pdUgKHeGsS762fdYrBkWfvby_Q3Z71ptHajEp8k,55904
16
+ ddeutil/workflow/utils.py,sha256=CtFUrP_4m6xaJooc9RbE4ulTBE-OkICg-MPHqzCuJ0I,7392
17
+ ddeutil/workflow/workflow.py,sha256=mCpsAY0Su-pMJ_xZ-qF6lDEXn-Ih7myUODZ0ZEuyVew,50804
18
+ ddeutil/workflow/api/__init__.py,sha256=F53NMBWtb9IKaDWkPU5KvybGGfKAcbehgn6TLBwHuuM,21
19
+ ddeutil/workflow/api/api.py,sha256=CWtPLgOv2Jus9E7nzG5mG2Z32ZEkUK3JWQ2htZyMRpA,5244
20
+ ddeutil/workflow/api/log.py,sha256=NMTnOnsBrDB5129329xF2myLdrb-z9k1MQrmrP7qXJw,1818
21
+ ddeutil/workflow/api/repeat.py,sha256=uTtUFVLpiYYahXvCVx8sueRQ03K2Xw1id_gW3IMmX1U,5295
22
+ ddeutil/workflow/api/routes/__init__.py,sha256=qoGtOMyVgQ5nTUc8J8wH27A8isaxl3IFCX8qoyibeCY,484
23
+ ddeutil/workflow/api/routes/job.py,sha256=oPwBVP0Mxwxv-bGPlfmxQQ9PcVl0ev9HoPzndpYDCCQ,1954
24
+ ddeutil/workflow/api/routes/logs.py,sha256=U6vOni3wd-ZTOwd3yVdSOpgyRmNdcgfngU5KlLM3Cww,5383
25
+ ddeutil/workflow/api/routes/schedules.py,sha256=EgUjyRGhsm6UNaMj5luh6TcY6l571sCHcla-BL1iOfY,4829
26
+ ddeutil/workflow/api/routes/workflows.py,sha256=JcDOrn1deK8ztFRcMTNATQejG6KMA7JxZLVc4QeBsP4,4527
27
+ ddeutil_workflow-0.0.49.dist-info/licenses/LICENSE,sha256=nGFZ1QEhhhWeMHf9n99_fdt4vQaXS29xWKxt-OcLywk,1085
28
+ ddeutil_workflow-0.0.49.dist-info/METADATA,sha256=U847vy3oZ6ZEvngEe-9W3wA1vkKGr15UQa73v9Dsy7k,18257
29
+ ddeutil_workflow-0.0.49.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
30
+ ddeutil_workflow-0.0.49.dist-info/top_level.txt,sha256=m9M6XeSWDwt_yMsmH6gcOjHZVK5O0-vgtNBuncHjzW4,8
31
+ ddeutil_workflow-0.0.49.dist-info/RECORD,,
@@ -1,31 +0,0 @@
1
- ddeutil/workflow/__about__.py,sha256=OFynARvYDKZ4fFNVea1bykjJJKDpblDyUNtdv9rywxE,28
2
- ddeutil/workflow/__cron.py,sha256=h8rLeIUAAEB2SdZ4Jhch7LU1Yl3bbJ-iNNJ3tQ0eYVM,28095
3
- ddeutil/workflow/__init__.py,sha256=t7AaJ3gY7E8i2WeL3_8dYz-F5mzskUxsSAx7-Ny4Fhw,1927
4
- ddeutil/workflow/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- ddeutil/workflow/__types.py,sha256=8jBdbfb3aZSetjz0mvNrpGHwwxJff7mK8_4v41cLqlc,4316
6
- ddeutil/workflow/conf.py,sha256=sXN7epudr90I1gUAjwJqvWTQV39mhO6cJhuuOuoYCw0,12153
7
- ddeutil/workflow/cron.py,sha256=80SijzMdDOBxTWRsiF-Fmuz7Ym7leY0XT2lzRAPGdXc,8781
8
- ddeutil/workflow/exceptions.py,sha256=uLNxzav3HRcr4vaZnvbUIF_eTR6UXXZNaxroMWFOUL4,1418
9
- ddeutil/workflow/job.py,sha256=nvcSH1vxQrq8tGDrOs-8wHifaOLrfZdTAUk1vD-QtRA,30762
10
- ddeutil/workflow/logs.py,sha256=o_EziK1MgP-7fJIl6bwE58BZHt8FBTrsmrEBhu1XGTo,24670
11
- ddeutil/workflow/params.py,sha256=xCtFEh0-G-G-f8y_SXxyf31bU6Ox5p5Z-WbBFXrjy8M,9960
12
- ddeutil/workflow/result.py,sha256=6yqWXFE__xMr8VY8xchBhBd3lyU-XX1nHOpx_2V5VGU,5390
13
- ddeutil/workflow/reusables.py,sha256=7uamdx0nnBnDHcc0xXqwucItFYHUXI4_O-SHdFHIZCo,17528
14
- ddeutil/workflow/scheduler.py,sha256=jyTLML8ppwdCrcuVw9ZMcZ1JwJ1SW6wDrJg5soHDFAw,27681
15
- ddeutil/workflow/stages.py,sha256=mnP07SLvGRfggOV1i9bZ7_j5K_ksHlorCYb2crU1pus,49170
16
- ddeutil/workflow/utils.py,sha256=sblje9qOtejCHVt8EVrbC0KY98vKqvxccaR5HIkRiTA,7363
17
- ddeutil/workflow/workflow.py,sha256=V8uJw16gtjTd8T5aCpvSUr9z_oGQrV-ycybvUjA8NHI,50073
18
- ddeutil/workflow/api/__init__.py,sha256=F53NMBWtb9IKaDWkPU5KvybGGfKAcbehgn6TLBwHuuM,21
19
- ddeutil/workflow/api/api.py,sha256=CWtPLgOv2Jus9E7nzG5mG2Z32ZEkUK3JWQ2htZyMRpA,5244
20
- ddeutil/workflow/api/log.py,sha256=NMTnOnsBrDB5129329xF2myLdrb-z9k1MQrmrP7qXJw,1818
21
- ddeutil/workflow/api/repeat.py,sha256=uTtUFVLpiYYahXvCVx8sueRQ03K2Xw1id_gW3IMmX1U,5295
22
- ddeutil/workflow/api/routes/__init__.py,sha256=qoGtOMyVgQ5nTUc8J8wH27A8isaxl3IFCX8qoyibeCY,484
23
- ddeutil/workflow/api/routes/job.py,sha256=oPwBVP0Mxwxv-bGPlfmxQQ9PcVl0ev9HoPzndpYDCCQ,1954
24
- ddeutil/workflow/api/routes/logs.py,sha256=TeRDrEelbKS2Hu_EovgLh0bOdmSv9mfnrIZsrE7uPD4,5353
25
- ddeutil/workflow/api/routes/schedules.py,sha256=EgUjyRGhsm6UNaMj5luh6TcY6l571sCHcla-BL1iOfY,4829
26
- ddeutil/workflow/api/routes/workflows.py,sha256=JcDOrn1deK8ztFRcMTNATQejG6KMA7JxZLVc4QeBsP4,4527
27
- ddeutil_workflow-0.0.48.dist-info/licenses/LICENSE,sha256=nGFZ1QEhhhWeMHf9n99_fdt4vQaXS29xWKxt-OcLywk,1085
28
- ddeutil_workflow-0.0.48.dist-info/METADATA,sha256=wv_dQPbCSS_1TuKmZ2jl1cWTRu0sM2eGtV3pBHHdWmQ,18841
29
- ddeutil_workflow-0.0.48.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
30
- ddeutil_workflow-0.0.48.dist-info/top_level.txt,sha256=m9M6XeSWDwt_yMsmH6gcOjHZVK5O0-vgtNBuncHjzW4,8
31
- ddeutil_workflow-0.0.48.dist-info/RECORD,,