PrefectHQ / server

@@ -1,4 +1,5 @@
Loading
1 1
import asyncio
2 +
import os
2 3
import random
3 4
from datetime import timedelta
4 5
from typing import Union
@@ -16,35 +17,35 @@
Loading
16 17
    define the `run_once` coroutine to describe the behavior of the service on each loop.
17 18
    """
18 19
19 -
    # if set, and no `loop_seconds` is provided, the service will attempt to load
20 -
    # `loop_seconds` from this config key
21 -
    loop_seconds_config_key = None
22 -
23 -
    # if no loop_seconds_config_key is provided, this will be the default
20 +
    # The number of seconds the loop should repeat on when in operation
24 21
    loop_seconds_default = 600
25 22
23 +
    # The number of seconds the loop should repeat on when testing
24 +
    loop_seconds_debug = 1
25 +
    debug_environment_key = "PREFECT__LOOP_SERVICE__DEBUG_MODE"
26 +
26 27
    # shutdown flag for gracefully exiting the infinite loop
27 28
    is_running = True
28 29
29 -
    def __init__(self, loop_seconds: Union[float, int] = None):
30 -
        if loop_seconds is None:
31 -
            if self.loop_seconds_config_key:
32 -
33 -
                # split the key on '.' and recurse
34 -
                split_keys = self.loop_seconds_config_key.split(".")
35 -
                cfg = config
36 -
                for key in split_keys[:-1]:
37 -
                    cfg = cfg.get(key, {})
38 -
                loop_seconds = cfg.get(split_keys[-1])
39 -
            else:
40 -
                loop_seconds = self.loop_seconds_default
41 -
        if loop_seconds == 0:
42 -
            raise ValueError("`loop_seconds` must be greater than 0.")
43 -
44 -
        self.loop_seconds = float(loop_seconds)
30 +
    def __init__(self):
31 +
        self.loop_seconds = self.loop_seconds_default
45 32
        self.name = type(self).__name__
46 33
        self.logger = utilities.logging.get_logger(self.name)
47 34
35 +
    @property
36 +
    def loop_seconds(self):
37 +
        return (
38 +
            self.loop_seconds_debug
39 +
            if os.environ.get(self.debug_environment_key) is not None
40 +
            else self._loop_seconds
41 +
        )
42 +
43 +
    @loop_seconds.setter
44 +
    def loop_seconds(self, value):
45 +
        if value == 0:
46 +
            raise ValueError("`loop_seconds` must be greater than 0.")
47 +
        self._loop_seconds = float(value)
48 +
48 49
    async def run(self) -> None:
49 50
        """
50 51
        Run the service forever.

@@ -15,7 +15,6 @@
Loading
15 15
        - the flow is not archived
16 16
    """
17 17
18 -
    loop_seconds_config_key = "services.scheduler.scheduler_loop_seconds"
19 18
    loop_seconds_default = 150
20 19
21 20
    async def run_once(self) -> int:
Files Coverage
src/prefect_server 92.16%
update_changelog.py 0.00%
Project Totals (49 files) 88.94%
Notifications are pending CI completion. Periodically Codecov will check the CI state, when complete notifications will be submitted. Push notifications now.
1
comment:
2
  layout: "header"
3
  behavior: default
4
  require_changes: false # if true: only post the comment if coverage changes
5
  require_base: no # [yes :: must have a base report to post]
6
  require_head: yes # [yes :: must have a head report to post]
7
  branches: null # branch names that can post comment
8

9
coverage:
10
  status:
11
    patch: no
12
    project:
13
      default:
14
        target: 80%
15
        threshold: 1%
16

17
ignore:
18
  - "src/prefect_server/cli"
19
  - "setup.py"
20
  - "versioneer.py"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading