kaal 0.4.0 → 0.6.0
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.
- checksums.yaml +4 -4
- data/README.md +60 -25
- data/config/kaal.yml +12 -0
- data/lib/kaal/active_record_support.rb +2 -2
- data/lib/kaal/backend/adapter.rb +8 -0
- data/lib/kaal/backend/memory_adapter.rb +5 -0
- data/lib/kaal/backend/mysql.rb +25 -3
- data/lib/kaal/backend/postgres.rb +6 -2
- data/lib/kaal/backend/redis_adapter.rb +5 -0
- data/lib/kaal/backend/sqlite.rb +4 -0
- data/lib/kaal/cli.rb +38 -33
- data/lib/kaal/config/backend_factory.rb +178 -0
- data/lib/kaal/config/configuration.rb +98 -9
- data/lib/kaal/config/delayed_job_security_policy.rb +60 -0
- data/lib/kaal/config/file_loader.rb +187 -0
- data/lib/kaal/config.rb +3 -0
- data/lib/kaal/core/coordinator.rb +68 -19
- data/lib/kaal/delayed_job/database_engine.rb +116 -0
- data/lib/kaal/delayed_job/dispatch_failure_logger.rb +31 -0
- data/lib/kaal/delayed_job/memory_engine.rb +79 -0
- data/lib/kaal/delayed_job/mysql_version_support.rb +43 -0
- data/lib/kaal/delayed_job/redis_engine.rb +119 -0
- data/lib/kaal/delayed_job/registry.rb +39 -0
- data/lib/kaal/internal/active_record/database_backend.rb +5 -0
- data/lib/kaal/internal/active_record/delayed_job_record.rb +16 -0
- data/lib/kaal/internal/active_record/delayed_job_registry.rb +119 -0
- data/lib/kaal/internal/active_record/migration_templates.rb +33 -3
- data/lib/kaal/internal/active_record/mysql_backend.rb +23 -5
- data/lib/kaal/internal/active_record/postgres_backend.rb +4 -0
- data/lib/kaal/internal/active_record.rb +2 -0
- data/lib/kaal/internal/sequel/database_backend.rb +5 -0
- data/lib/kaal/internal/sequel/mysql_backend.rb +15 -1
- data/lib/kaal/internal/sequel/postgres_backend.rb +4 -0
- data/lib/kaal/internal/sequel.rb +1 -0
- data/lib/kaal/job_dispatcher.rb +108 -0
- data/lib/kaal/persistence/database.rb +4 -0
- data/lib/kaal/persistence/migration_templates.rb +35 -3
- data/lib/kaal/runtime/scheduler_boot_loader.rb +3 -1
- data/lib/kaal/scheduler_file/job_applier.rb +28 -53
- data/lib/kaal/scheduler_file/loader.rb +1 -1
- data/lib/kaal/sequel_support.rb +2 -2
- data/lib/kaal/version.rb +1 -1
- data/lib/kaal.rb +118 -0
- data/sig/00_types.rbs +12 -0
- data/sig/dependencies.rbs +49 -0
- data/sig/kaal/active_record_support.rbs +23 -0
- data/sig/kaal/backend/adapter.rbs +26 -0
- data/sig/kaal/backend/dispatch_attempt_logger.rbs +17 -0
- data/sig/kaal/backend/dispatch_logging.rbs +23 -0
- data/sig/kaal/backend/dispatch_registry_accessor.rbs +17 -0
- data/sig/kaal/backend/memory_adapter.rbs +33 -0
- data/sig/kaal/backend/mysql.rbs +25 -0
- data/sig/kaal/backend/postgres.rbs +19 -0
- data/sig/kaal/backend/redis_adapter.rbs +41 -0
- data/sig/kaal/backend/sqlite.rbs +19 -0
- data/sig/kaal/cli.rbs +41 -0
- data/sig/kaal/config/backend_factory.rbs +41 -0
- data/sig/kaal/config/configuration.rbs +70 -0
- data/sig/kaal/config/delayed_job_security_policy.rbs +19 -0
- data/sig/kaal/config/file_loader.rbs +35 -0
- data/sig/kaal/config/scheduler_config_error.rbs +4 -0
- data/sig/kaal/config/scheduler_time_zone_resolver.rbs +19 -0
- data/sig/kaal/config.rbs +11 -0
- data/sig/kaal/core/coordinator.rbs +103 -0
- data/sig/kaal/core/enabled_entry_enumerator.rbs +21 -0
- data/sig/kaal/core/occurrence_finder.rbs +9 -0
- data/sig/kaal/core.rbs +9 -0
- data/sig/kaal/definition/database_engine.rbs +25 -0
- data/sig/kaal/definition/memory_engine.rbs +23 -0
- data/sig/kaal/definition/persistence_helpers.rbs +9 -0
- data/sig/kaal/definition/redis_engine.rbs +33 -0
- data/sig/kaal/definition/registry.rbs +29 -0
- data/sig/kaal/definitions/registration_service.rbs +27 -0
- data/sig/kaal/definitions/registry_accessor.rbs +17 -0
- data/sig/kaal/delayed_job/database_engine.rbs +37 -0
- data/sig/kaal/delayed_job/dispatch_failure_logger.rbs +7 -0
- data/sig/kaal/delayed_job/memory_engine.rbs +29 -0
- data/sig/kaal/delayed_job/mysql_version_support.rbs +15 -0
- data/sig/kaal/delayed_job/redis_engine.rbs +31 -0
- data/sig/kaal/delayed_job/registry.rbs +20 -0
- data/sig/kaal/dispatch/database_engine.rbs +39 -0
- data/sig/kaal/dispatch/memory_engine.rbs +23 -0
- data/sig/kaal/dispatch/redis_engine.rbs +25 -0
- data/sig/kaal/dispatch/registry.rbs +11 -0
- data/sig/kaal/internal/active_record/base_record.rbs +8 -0
- data/sig/kaal/internal/active_record/connection_support.rbs +25 -0
- data/sig/kaal/internal/active_record/database_backend.rbs +37 -0
- data/sig/kaal/internal/active_record/definition_record.rbs +8 -0
- data/sig/kaal/internal/active_record/definition_registry.rbs +27 -0
- data/sig/kaal/internal/active_record/delayed_job_record.rbs +8 -0
- data/sig/kaal/internal/active_record/delayed_job_registry.rbs +39 -0
- data/sig/kaal/internal/active_record/dispatch_record.rbs +8 -0
- data/sig/kaal/internal/active_record/dispatch_registry.rbs +43 -0
- data/sig/kaal/internal/active_record/lock_record.rbs +8 -0
- data/sig/kaal/internal/active_record/migration_templates.rbs +17 -0
- data/sig/kaal/internal/active_record/mysql_backend.rbs +45 -0
- data/sig/kaal/internal/active_record/postgres_backend.rbs +41 -0
- data/sig/kaal/internal/active_record.rbs +0 -0
- data/sig/kaal/internal/sequel/database_backend.rbs +39 -0
- data/sig/kaal/internal/sequel/mysql_backend.rbs +47 -0
- data/sig/kaal/internal/sequel/postgres_backend.rbs +43 -0
- data/sig/kaal/internal/sequel.rbs +0 -0
- data/sig/kaal/job_dispatcher.rbs +19 -0
- data/sig/kaal/persistence/database.rbs +19 -0
- data/sig/kaal/persistence/migration_templates.rbs +15 -0
- data/sig/kaal/register_conflict_support.rbs +11 -0
- data/sig/kaal/registry.rbs +44 -0
- data/sig/kaal/runtime/runtime_context.rbs +23 -0
- data/sig/kaal/runtime/scheduler_boot_loader.rbs +23 -0
- data/sig/kaal/runtime/signal_handler_chain.rbs +19 -0
- data/sig/kaal/runtime/signal_handler_installer.rbs +19 -0
- data/sig/kaal/runtime.rbs +11 -0
- data/sig/kaal/scheduler_file/hash_transform.rbs +9 -0
- data/sig/kaal/scheduler_file/helper_bundle.rbs +15 -0
- data/sig/kaal/scheduler_file/job_applier.rbs +43 -0
- data/sig/kaal/scheduler_file/job_normalizer.rbs +27 -0
- data/sig/kaal/scheduler_file/loader.rbs +69 -0
- data/sig/kaal/scheduler_file/payload_loader.rbs +33 -0
- data/sig/kaal/scheduler_file/placeholder_support.rbs +19 -0
- data/sig/kaal/scheduler_file.rbs +9 -0
- data/sig/kaal/sequel_support.rbs +25 -0
- data/sig/kaal/support/hash_tools.rbs +27 -0
- data/sig/kaal/utils/cron_humanizer.rbs +39 -0
- data/sig/kaal/utils/cron_utils.rbs +43 -0
- data/sig/kaal/utils/idempotency_key_generator.rbs +5 -0
- data/sig/kaal/utils.rbs +9 -0
- data/sig/kaal/version.rbs +3 -0
- data/sig/kaal.rbs +145 -0
- metadata +100 -3
- data/config/kaal.rb +0 -15
- /data/config/{scheduler.yml → kaal-scheduler.yml} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
module DispatchLogging
|
|
4
|
+
@dispatch_attempt_logger: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
def dispatch_registry: () -> nil
|
|
7
|
+
|
|
8
|
+
def log_dispatch_attempt: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def parse_lock_key: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def self.parse_lock_key: (Kaal::rbs_any key) -> ::Array[Kaal::rbs_any]
|
|
13
|
+
|
|
14
|
+
def self.validate_lock_key!: (Kaal::rbs_any valid, Kaal::rbs_any message) -> (Kaal::rbs_any | nil)
|
|
15
|
+
|
|
16
|
+
def self.invalid_dispatch_lock_key!: (Kaal::rbs_any message) -> Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def dispatch_attempt_logger: () -> Kaal::rbs_any
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class DispatchRegistryAccessor
|
|
4
|
+
@configuration: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
def initialize: (configuration: Kaal::rbs_any) -> void
|
|
7
|
+
|
|
8
|
+
def dispatched?: (Kaal::rbs_any key, Kaal::rbs_any fire_time) -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def registry: () -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def fetch_registry: () -> (nil | Kaal::rbs_any)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class MemoryAdapter < Adapter
|
|
4
|
+
@locks: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
@mutex: Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
@dispatch_registry: Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
@definition_registry: Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
@delayed_store: Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
include DispatchLogging
|
|
15
|
+
|
|
16
|
+
def initialize: () -> void
|
|
17
|
+
|
|
18
|
+
def dispatch_registry: () -> Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
def definition_registry: () -> Kaal::rbs_any
|
|
21
|
+
|
|
22
|
+
def delayed_store: () -> Kaal::rbs_any
|
|
23
|
+
|
|
24
|
+
def acquire: (Kaal::rbs_any key, Kaal::rbs_any ttl) -> Kaal::rbs_any
|
|
25
|
+
|
|
26
|
+
def release: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def prune_expired_locks: () -> Kaal::rbs_any
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class MySQL < Adapter
|
|
4
|
+
@engine: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
UNSET_SKIP_LOCKED_SUPPORT: Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
def initialize: (?database: Kaal::rbs_any?, ?connection: Kaal::rbs_any?, ?namespace: Kaal::rbs_any?, ?use_skip_locked: Kaal::rbs_any) -> void
|
|
9
|
+
|
|
10
|
+
def dispatch_registry: () -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def definition_registry: () -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def delayed_store: () -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def acquire: (Kaal::rbs_any key, Kaal::rbs_any ttl) -> Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
def release: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
def self.build_sequel_backend: (Kaal::rbs_any database, Kaal::rbs_any namespace, Kaal::rbs_any use_skip_locked) -> Kaal::rbs_any
|
|
21
|
+
|
|
22
|
+
def self.build_active_record_backend: (Kaal::rbs_any connection, Kaal::rbs_any namespace, Kaal::rbs_any use_skip_locked) -> Kaal::rbs_any
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class Postgres < Adapter
|
|
4
|
+
@engine: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
def initialize: (?database: Kaal::rbs_any?, ?connection: Kaal::rbs_any?, ?namespace: Kaal::rbs_any?) -> void
|
|
7
|
+
|
|
8
|
+
def dispatch_registry: () -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def definition_registry: () -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def delayed_store: () -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def acquire: (Kaal::rbs_any key, Kaal::rbs_any ttl) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def release: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class RedisAdapter < Adapter
|
|
4
|
+
@redis: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
@namespace: Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
@lock_value_generator: Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
@lock_values: Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
@mutex: Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
@dispatch_registry: Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
@definition_registry: Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
@delayed_store: Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
include DispatchLogging
|
|
21
|
+
|
|
22
|
+
def initialize: (Kaal::rbs_any redis, ?namespace: ::String) -> void
|
|
23
|
+
|
|
24
|
+
def dispatch_registry: () -> Kaal::rbs_any
|
|
25
|
+
|
|
26
|
+
def definition_registry: () -> Kaal::rbs_any
|
|
27
|
+
|
|
28
|
+
def delayed_store: () -> Kaal::rbs_any
|
|
29
|
+
|
|
30
|
+
def acquire: (Kaal::rbs_any key, Kaal::rbs_any ttl) -> Kaal::rbs_any
|
|
31
|
+
|
|
32
|
+
def release: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def generate_lock_value: () -> Kaal::rbs_any
|
|
37
|
+
|
|
38
|
+
def prune_expired_lock_values: () -> Kaal::rbs_any
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class SQLite < Adapter
|
|
4
|
+
@engine: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
def initialize: (?database: Kaal::rbs_any?, ?connection: Kaal::rbs_any?, ?namespace: Kaal::rbs_any?, **Kaal::rbs_any) -> void
|
|
7
|
+
|
|
8
|
+
def dispatch_registry: () -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def definition_registry: () -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def delayed_store: () -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def acquire: (Kaal::rbs_any key, Kaal::rbs_any ttl) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def release: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/sig/kaal/cli.rbs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
class CLI < Thor
|
|
3
|
+
module Helpers
|
|
4
|
+
private
|
|
5
|
+
|
|
6
|
+
def load_project!: () -> Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
def root_path: () -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def config_path: () -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def scheduler_path: () -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def render_config_template: (Kaal::rbs_any backend) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def scheduler_template: () -> "defaults:\n jobs:\n - key: \"example:heartbeat\"\n cron: \"*/5 * * * *\"\n job_class: \"ExampleHeartbeatJob\"\n enabled: true\n args:\n - \"{{fire_time.iso8601}}\"\n kwargs:\n idempotency_key: \"{{idempotency_key}}\"\n metadata:\n owner: \"ops\"\n"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def init: () -> Kaal::rbs_any
|
|
20
|
+
|
|
21
|
+
def start: () -> Kaal::rbs_any
|
|
22
|
+
|
|
23
|
+
def status: () -> Kaal::rbs_any
|
|
24
|
+
|
|
25
|
+
def tick: () -> Kaal::rbs_any
|
|
26
|
+
|
|
27
|
+
def explain: (Kaal::rbs_any expression) -> Kaal::rbs_any
|
|
28
|
+
|
|
29
|
+
def next: (Kaal::rbs_any expression) -> Kaal::rbs_any
|
|
30
|
+
|
|
31
|
+
def self.exit_on_failure?: () -> true
|
|
32
|
+
|
|
33
|
+
def self.write_file: (Kaal::rbs_any path, Kaal::rbs_any contents) -> (nil | Kaal::rbs_any)
|
|
34
|
+
|
|
35
|
+
def self.install_foreground_signal_handlers: (Kaal::rbs_any signal_state) -> Kaal::rbs_any
|
|
36
|
+
|
|
37
|
+
def self.restore_signal_handlers: (Kaal::rbs_any previous_handlers) -> Kaal::rbs_any
|
|
38
|
+
|
|
39
|
+
def self.shutdown_scheduler: (signal: Kaal::rbs_any, signal_state: Kaal::rbs_any, ?previous_handler: Kaal::rbs_any?, ?shell: Kaal::rbs_any?) -> Kaal::rbs_any
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Config
|
|
3
|
+
module BackendFactory
|
|
4
|
+
SUPPORTED_BACKENDS: ::Array["memory" | "redis" | "sqlite" | "postgres" | "mysql"]
|
|
5
|
+
|
|
6
|
+
def self.normalize_name: (Kaal::rbs_any name) -> (nil | Kaal::rbs_any)
|
|
7
|
+
|
|
8
|
+
def self.build: (Kaal::rbs_any name, backend_config: Kaal::rbs_any, namespace: Kaal::rbs_any, ?runtime_context: Kaal::rbs_any?) -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def self.normalize_backend_config: (Kaal::rbs_any backend_config) -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def self.build_redis_backend: (Kaal::rbs_any config, Kaal::rbs_any namespace) -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def self.build_sqlite_backend: (Kaal::rbs_any config, Kaal::rbs_any namespace, Kaal::rbs_any runtime_context) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def self.build_postgres_backend: (Kaal::rbs_any config, Kaal::rbs_any namespace) -> Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
def self.build_mysql_backend: (Kaal::rbs_any config, Kaal::rbs_any namespace) -> Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
def self.build_sqlite_connection: (Kaal::rbs_any connection, Kaal::rbs_any runtime_context) -> Kaal::rbs_any
|
|
21
|
+
|
|
22
|
+
def self.normalize_connection_hash: (Kaal::rbs_any connection, Kaal::rbs_any default_adapter, Kaal::rbs_any runtime_context) -> Kaal::rbs_any
|
|
23
|
+
|
|
24
|
+
def self.resolve_sqlite_database_path: (Kaal::rbs_any database, Kaal::rbs_any runtime_context) -> Kaal::rbs_any
|
|
25
|
+
|
|
26
|
+
def self.sqlite_uri?: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
27
|
+
|
|
28
|
+
def self.sequel_sqlite_database: (Kaal::rbs_any target, Kaal::rbs_any runtime_context) -> Kaal::rbs_any
|
|
29
|
+
|
|
30
|
+
def self.ensure_sqlite_directory!: (Kaal::rbs_any database_path) -> Kaal::rbs_any
|
|
31
|
+
|
|
32
|
+
def self.adapter_name_for_error: (Kaal::rbs_any adapter) -> ("postgres" | "mysql")
|
|
33
|
+
|
|
34
|
+
def self.string_value: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
35
|
+
|
|
36
|
+
def self.require_redis!: () -> Kaal::rbs_any
|
|
37
|
+
|
|
38
|
+
def self.require_sequel!: () -> Kaal::rbs_any
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
class Configuration
|
|
3
|
+
@values: Kaal::rbs_any
|
|
4
|
+
|
|
5
|
+
@backend_name: Kaal::rbs_any
|
|
6
|
+
|
|
7
|
+
@backend_runtime_context: Kaal::rbs_any
|
|
8
|
+
|
|
9
|
+
DEFAULTS: { tick_interval: 5, window_lookback: 120, window_lookahead: 0, lease_ttl: 125, namespace: "kaal", backend: nil, backend_config: ::Hash[Kaal::rbs_any, Kaal::rbs_any], logger: nil, time_zone: nil, enable_log_dispatch_registry: false, enable_dispatch_recovery: true, recovery_window: 86400, recovery_startup_jitter: 5, scheduler_config_path: "config/kaal-scheduler.yml", scheduler_conflict_policy: :error, scheduler_missing_file_policy: :warn, delayed_job_allowed_class_prefixes: ::Array[Kaal::rbs_any] }
|
|
10
|
+
|
|
11
|
+
def initialize: () -> void
|
|
12
|
+
|
|
13
|
+
def method_missing: (Kaal::rbs_any method_name, *Kaal::rbs_any args) -> Kaal::rbs_any
|
|
14
|
+
|
|
15
|
+
def respond_to_missing?: (Kaal::rbs_any method_name, ?bool include_private) -> Kaal::rbs_any
|
|
16
|
+
|
|
17
|
+
def validate: () -> Kaal::rbs_any
|
|
18
|
+
|
|
19
|
+
attr_accessor backend_runtime_context: Kaal::rbs_any
|
|
20
|
+
|
|
21
|
+
def validation_warnings: () -> Kaal::rbs_any
|
|
22
|
+
|
|
23
|
+
def validate!: () -> self
|
|
24
|
+
|
|
25
|
+
def to_h: () -> { tick_interval: Kaal::rbs_any, window_lookback: Kaal::rbs_any, window_lookahead: Kaal::rbs_any, lease_ttl: Kaal::rbs_any, namespace: Kaal::rbs_any, backend: Kaal::rbs_any, backend_config: Kaal::rbs_any, logger: Kaal::rbs_any, time_zone: Kaal::rbs_any, enable_log_dispatch_registry: Kaal::rbs_any, enable_dispatch_recovery: Kaal::rbs_any, recovery_window: Kaal::rbs_any, recovery_startup_jitter: Kaal::rbs_any, scheduler_config_path: Kaal::rbs_any, scheduler_conflict_policy: Kaal::rbs_any, scheduler_missing_file_policy: Kaal::rbs_any, delayed_job_allowed_class_prefixes: Kaal::rbs_any }
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def validation_errors: () -> Kaal::rbs_any
|
|
30
|
+
|
|
31
|
+
def add_tick_interval_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
32
|
+
|
|
33
|
+
def add_window_lookback_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
34
|
+
|
|
35
|
+
def add_window_lookahead_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
36
|
+
|
|
37
|
+
def add_lease_ttl_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
38
|
+
|
|
39
|
+
def add_namespace_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
40
|
+
|
|
41
|
+
def add_backend_config_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
42
|
+
|
|
43
|
+
def add_lease_ttl_window_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
44
|
+
|
|
45
|
+
def add_scheduler_config_path_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
46
|
+
|
|
47
|
+
def add_scheduler_conflict_policy_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
48
|
+
|
|
49
|
+
def add_scheduler_missing_file_policy_error: (Kaal::rbs_any errors) -> (nil | Kaal::rbs_any)
|
|
50
|
+
|
|
51
|
+
def add_delayed_job_security_warning: (Kaal::rbs_any warnings) -> (nil | Kaal::rbs_any)
|
|
52
|
+
|
|
53
|
+
def handle_known_key: (Kaal::rbs_any method_name) { (Kaal::rbs_any, Kaal::rbs_any) -> Kaal::rbs_any } -> (::Array[false | nil] | ::Array[true | Kaal::rbs_any])
|
|
54
|
+
|
|
55
|
+
def set_value: (Kaal::rbs_any key, Kaal::rbs_any value) -> Kaal::rbs_any
|
|
56
|
+
|
|
57
|
+
def normalize_value: (Kaal::rbs_any key, Kaal::rbs_any value) -> Kaal::rbs_any
|
|
58
|
+
|
|
59
|
+
def normalize_backend: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
60
|
+
|
|
61
|
+
def normalize_backend_config: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
62
|
+
|
|
63
|
+
def rebuild_symbolic_backend_if_needed: (Kaal::rbs_any key) -> (nil | Kaal::rbs_any)
|
|
64
|
+
|
|
65
|
+
def normalize_delayed_job_allowed_class_prefixes: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class ConfigurationError < StandardError
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Config
|
|
3
|
+
module DelayedJobSecurityPolicy
|
|
4
|
+
NON_SHARED_BACKEND_CLASS_NAMES: ::Array["NilClass" | "Kaal::Backend::MemoryAdapter" | "Kaal::Backend::NullAdapter"]
|
|
5
|
+
|
|
6
|
+
WARNING_MESSAGE: "Delayed jobs resolve stored job_class values at dispatch time. delayed_job_allowed_class_prefixes is empty, so class resolution is unrestricted on this shared backend. Configure a restrictive delayed_job_allowed_class_prefixes list for production deployments."
|
|
7
|
+
|
|
8
|
+
def self.warning_for: (Kaal::rbs_any configuration) -> (nil | Kaal::rbs_any)
|
|
9
|
+
|
|
10
|
+
def self.production_like_environment?: (?env: Kaal::rbs_any, ?rails: Kaal::rbs_any) -> Kaal::rbs_any
|
|
11
|
+
|
|
12
|
+
def self.shared_delayed_job_backend?: (Kaal::rbs_any backend) -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def self.current_rails: () -> (nil | Kaal::rbs_any)
|
|
15
|
+
|
|
16
|
+
def self.rails_environment: (Kaal::rbs_any rails) -> Kaal::rbs_any
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Config
|
|
3
|
+
class FileLoader
|
|
4
|
+
@configuration: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
@runtime_context: Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
@env: Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
ENV_KEY_MAP: ::Hash[::String, ::Symbol]
|
|
11
|
+
|
|
12
|
+
def initialize: (configuration: Kaal::rbs_any, runtime_context: Kaal::rbs_any, ?env: Kaal::rbs_any) -> void
|
|
13
|
+
|
|
14
|
+
def load: (?path: ::String) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def parse_yaml: (Kaal::rbs_any path) -> Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
def merge_environment_config: (Kaal::rbs_any payload) -> Kaal::rbs_any
|
|
21
|
+
|
|
22
|
+
def hash_section: (Kaal::rbs_any value) -> (::Hash[Kaal::rbs_any, Kaal::rbs_any] | Kaal::rbs_any)
|
|
23
|
+
|
|
24
|
+
def apply_env_overrides: (Kaal::rbs_any config) -> Kaal::rbs_any
|
|
25
|
+
|
|
26
|
+
def coerce_env_value: (Kaal::rbs_any key, Kaal::rbs_any value) -> Kaal::rbs_any
|
|
27
|
+
|
|
28
|
+
def coerce_boolean_env: (Kaal::rbs_any key, Kaal::rbs_any value) -> (true | false | Kaal::rbs_any)
|
|
29
|
+
|
|
30
|
+
def env_name_for: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
31
|
+
|
|
32
|
+
def apply_configuration: (Kaal::rbs_any config) -> Kaal::rbs_any
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
class SchedulerTimeZoneResolver
|
|
3
|
+
@configuration: Kaal::rbs_any
|
|
4
|
+
|
|
5
|
+
DEFAULT_TIME_ZONE: "UTC"
|
|
6
|
+
|
|
7
|
+
def initialize: (configuration: Kaal::rbs_any) -> void
|
|
8
|
+
|
|
9
|
+
def time_zone_identifier: () -> Kaal::rbs_any
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def configured_time_zone: () -> Kaal::rbs_any
|
|
14
|
+
|
|
15
|
+
def normalized_time_zone_value: () -> Kaal::rbs_any
|
|
16
|
+
|
|
17
|
+
def raw_time_zone_value: () -> Kaal::rbs_any
|
|
18
|
+
end
|
|
19
|
+
end
|
data/sig/kaal/config.rbs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
class Coordinator
|
|
3
|
+
@configuration: Kaal::rbs_any
|
|
4
|
+
|
|
5
|
+
@registry: Kaal::rbs_any
|
|
6
|
+
|
|
7
|
+
@thread: Kaal::rbs_any
|
|
8
|
+
|
|
9
|
+
@running: Kaal::rbs_any
|
|
10
|
+
|
|
11
|
+
@stop_requested: Kaal::rbs_any
|
|
12
|
+
|
|
13
|
+
@mutex: Kaal::rbs_any
|
|
14
|
+
|
|
15
|
+
@tick_cv: Kaal::rbs_any
|
|
16
|
+
|
|
17
|
+
@scheduler_time_zone_resolver: Kaal::rbs_any
|
|
18
|
+
|
|
19
|
+
@occurrence_finder: Kaal::rbs_any
|
|
20
|
+
|
|
21
|
+
@enabled_entry_enumerator: Kaal::rbs_any
|
|
22
|
+
|
|
23
|
+
DELAYED_JOB_BATCH_SIZE: 100
|
|
24
|
+
|
|
25
|
+
DELAYED_JOB_MAX_BATCHES_PER_TICK: 10
|
|
26
|
+
|
|
27
|
+
DELAYED_JOB_DELETE_CONFIRMATION_JITTER_MAX: ::Float
|
|
28
|
+
|
|
29
|
+
def initialize: (configuration: Kaal::rbs_any, registry: Kaal::rbs_any) -> void
|
|
30
|
+
|
|
31
|
+
def start!: () -> Kaal::rbs_any
|
|
32
|
+
|
|
33
|
+
def stop!: (?timeout: ::Integer) -> (false | true)
|
|
34
|
+
|
|
35
|
+
def running?: () -> Kaal::rbs_any
|
|
36
|
+
|
|
37
|
+
def restart!: () -> Kaal::rbs_any
|
|
38
|
+
|
|
39
|
+
def tick!: () -> Kaal::rbs_any
|
|
40
|
+
|
|
41
|
+
def reset!: () -> Kaal::rbs_any
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def request_stop: () -> Kaal::rbs_any
|
|
46
|
+
|
|
47
|
+
def run_loop: () -> Kaal::rbs_any
|
|
48
|
+
|
|
49
|
+
def stop_requested?: () -> Kaal::rbs_any
|
|
50
|
+
|
|
51
|
+
def execute_tick: () -> Kaal::rbs_any
|
|
52
|
+
|
|
53
|
+
def calculate_and_dispatch_due_times: (Kaal::rbs_any entry) -> (nil | Kaal::rbs_any)
|
|
54
|
+
|
|
55
|
+
def parse_cron: (Kaal::rbs_any cron_expression) -> Kaal::rbs_any
|
|
56
|
+
|
|
57
|
+
def find_occurrences: (Kaal::rbs_any cron, Kaal::rbs_any start_time, Kaal::rbs_any end_time) -> Kaal::rbs_any
|
|
58
|
+
|
|
59
|
+
def dispatch_if_due: (Kaal::rbs_any entry, Kaal::rbs_any fire_time, Kaal::rbs_any now) -> Kaal::rbs_any
|
|
60
|
+
|
|
61
|
+
def recover_missed_runs: () -> Kaal::rbs_any
|
|
62
|
+
|
|
63
|
+
def recover_entry: (Kaal::rbs_any entry, Kaal::rbs_any start_time, Kaal::rbs_any end_time) -> Kaal::rbs_any
|
|
64
|
+
|
|
65
|
+
def cleanup_old_dispatch_records: (Kaal::rbs_any recovery_window) -> Kaal::rbs_any
|
|
66
|
+
|
|
67
|
+
def already_dispatched?: (Kaal::rbs_any key, Kaal::rbs_any fire_time) -> Kaal::rbs_any
|
|
68
|
+
|
|
69
|
+
def acquire_lock: (Kaal::rbs_any lock_key) -> Kaal::rbs_any
|
|
70
|
+
|
|
71
|
+
def each_enabled_entry: () { (Kaal::rbs_any) -> Kaal::rbs_any } -> Kaal::rbs_any
|
|
72
|
+
|
|
73
|
+
def dispatch_work: (Kaal::rbs_any entry, Kaal::rbs_any fire_time) -> Kaal::rbs_any
|
|
74
|
+
|
|
75
|
+
def dispatch_due_delayed_jobs: () -> Kaal::rbs_any
|
|
76
|
+
|
|
77
|
+
def dispatch_delayed_job: (Kaal::rbs_any job, Kaal::rbs_any delayed_store) -> Kaal::rbs_any
|
|
78
|
+
|
|
79
|
+
def delayed_store_for_tick: () -> Kaal::rbs_any
|
|
80
|
+
|
|
81
|
+
def stop_delayed_dispatch?: () -> Kaal::rbs_any
|
|
82
|
+
|
|
83
|
+
def apply_delayed_job_claim_jitter_if_needed: (Kaal::rbs_any delayed_store) -> (nil | Kaal::rbs_any)
|
|
84
|
+
|
|
85
|
+
def generate_idempotency_key: (Kaal::rbs_any cron_key, Kaal::rbs_any fire_time) -> Kaal::rbs_any
|
|
86
|
+
|
|
87
|
+
def generate_lock_key: (Kaal::rbs_any cron_key, Kaal::rbs_any fire_time) -> ::String
|
|
88
|
+
|
|
89
|
+
def generate_delayed_lock_key: (Kaal::rbs_any job_id) -> ::String
|
|
90
|
+
|
|
91
|
+
def sleep_until_next_tick: () -> Kaal::rbs_any
|
|
92
|
+
|
|
93
|
+
def scheduler_time_zone_resolver: () -> Kaal::rbs_any
|
|
94
|
+
|
|
95
|
+
def occurrence_finder: () -> Kaal::rbs_any
|
|
96
|
+
|
|
97
|
+
def enabled_entry_enumerator: () -> Kaal::rbs_any
|
|
98
|
+
|
|
99
|
+
def log_configuration_error: (Kaal::rbs_any prefix, Kaal::rbs_any error, ?logger: Kaal::rbs_any) -> Kaal::rbs_any
|
|
100
|
+
|
|
101
|
+
def log_runtime_error: (Kaal::rbs_any prefix, Kaal::rbs_any error, ?logger: Kaal::rbs_any) -> Kaal::rbs_any
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
class EnabledEntryEnumerator
|
|
3
|
+
@configuration: Kaal::rbs_any
|
|
4
|
+
|
|
5
|
+
@registry: Kaal::rbs_any
|
|
6
|
+
|
|
7
|
+
@definition_registry_provider: Kaal::rbs_any
|
|
8
|
+
|
|
9
|
+
def initialize: (configuration: Kaal::rbs_any, registry: Kaal::rbs_any, ?definition_registry_provider: Kaal::rbs_any) -> void
|
|
10
|
+
|
|
11
|
+
def each: () { (Kaal::rbs_any) -> Kaal::rbs_any } -> Kaal::rbs_any
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def yield_registry_entries: () { (Kaal::rbs_any) -> Kaal::rbs_any } -> Kaal::rbs_any
|
|
16
|
+
|
|
17
|
+
def resolve_entries: () -> Kaal::rbs_any
|
|
18
|
+
|
|
19
|
+
def build_entry: (Kaal::rbs_any definition) -> (nil | Kaal::rbs_any)
|
|
20
|
+
end
|
|
21
|
+
end
|
data/sig/kaal/core.rbs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Definition
|
|
3
|
+
class DatabaseEngine < Registry
|
|
4
|
+
@database: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
def initialize: (database: Kaal::rbs_any) -> void
|
|
7
|
+
|
|
8
|
+
def upsert_definition: (key: Kaal::rbs_any, cron: Kaal::rbs_any, ?enabled: bool, ?source: ::String, ?metadata: ::Hash[Kaal::rbs_any, Kaal::rbs_any]) -> Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
def remove_definition: (Kaal::rbs_any key) -> (nil | Kaal::rbs_any)
|
|
11
|
+
|
|
12
|
+
def find_definition: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def all_definitions: () -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def enabled_definitions: () -> Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
def self.normalize_row: (Kaal::rbs_any row) -> (nil | { key: Kaal::rbs_any, cron: Kaal::rbs_any, enabled: Kaal::rbs_any, source: Kaal::rbs_any, metadata: Kaal::rbs_any, created_at: Kaal::rbs_any, updated_at: Kaal::rbs_any, disabled_at: Kaal::rbs_any })
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def dataset: () -> Kaal::rbs_any
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Definition
|
|
3
|
+
class MemoryEngine < Registry
|
|
4
|
+
@definitions: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
@mutex: Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
include Kaal::Support::HashTools
|
|
9
|
+
|
|
10
|
+
def initialize: () -> void
|
|
11
|
+
|
|
12
|
+
def upsert_definition: (key: Kaal::rbs_any, cron: Kaal::rbs_any, ?enabled: bool, ?source: ::String, ?metadata: ::Hash[Kaal::rbs_any, Kaal::rbs_any]) -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def remove_definition: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def find_definition: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
def all_definitions: () -> Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
def clear: () -> Kaal::rbs_any
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Definition
|
|
3
|
+
module PersistenceHelpers
|
|
4
|
+
def self.disabled_at_for: (Kaal::rbs_any existing, Kaal::rbs_any enabled, Kaal::rbs_any now) -> (nil | Kaal::rbs_any)
|
|
5
|
+
|
|
6
|
+
def self.parse_metadata: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Definition
|
|
3
|
+
class RedisEngine < Registry
|
|
4
|
+
@redis: Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
@namespace: Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
include Kaal::Support::HashTools
|
|
9
|
+
|
|
10
|
+
def initialize: (Kaal::rbs_any redis, ?namespace: ::String) -> void
|
|
11
|
+
|
|
12
|
+
def upsert_definition: (key: Kaal::rbs_any, cron: Kaal::rbs_any, ?enabled: bool, ?source: ::String, ?metadata: ::Hash[Kaal::rbs_any, Kaal::rbs_any]) -> Kaal::rbs_any
|
|
13
|
+
|
|
14
|
+
def remove_definition: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
15
|
+
|
|
16
|
+
def find_definition: (Kaal::rbs_any key) -> Kaal::rbs_any
|
|
17
|
+
|
|
18
|
+
def all_definitions: () -> Kaal::rbs_any
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def storage_key: () -> ::String
|
|
23
|
+
|
|
24
|
+
def deserialize: (Kaal::rbs_any raw) -> Kaal::rbs_any
|
|
25
|
+
|
|
26
|
+
def self.serialize_payload: (Kaal::rbs_any payload) -> Kaal::rbs_any
|
|
27
|
+
|
|
28
|
+
def self.deserialize_payload: (Kaal::rbs_any raw) -> Kaal::rbs_any
|
|
29
|
+
|
|
30
|
+
def self.parse_time: (Kaal::rbs_any value) -> Kaal::rbs_any
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|