kaal-rails 0.5.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 +1 -1
- data/lib/generators/kaal/install_generator.rb +2 -0
- data/lib/kaal/rails/installer.rb +37 -3
- data/lib/kaal/rails/version.rb +1 -1
- data/lib/kaal/rails.rb +7 -0
- data/lib/tasks/kaal/rails_tasks.rake +1 -0
- data/sig/00_types.rbs +12 -0
- data/sig/dependencies.rbs +65 -0
- data/sig/generators/kaal/install_generator.rbs +11 -0
- data/sig/kaal/rails/installer.rbs +47 -0
- data/sig/kaal/rails/railtie.rbs +6 -0
- data/sig/kaal/rails/version.rbs +5 -0
- data/sig/kaal/rails.rbs +15 -0
- metadata +10 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9574f048025ccf1cf2395da1365a7b10c2f831ba2234ae4bcc27f3f5708e0cc9
|
|
4
|
+
data.tar.gz: a599d190ac316df5e2e5bf9937c610f3ebc46f02eba29cce772414e9fff7971b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b806c7170acb9e05dfd25abd395afa9d3b9fb4c272cc478920e5c0d6a8f1ffbcd74ccbc91f895511616cdb056193c54e0d209049af87423b03c9c15fb2fcf4ab
|
|
7
|
+
data.tar.gz: 6909cde3ec4e36d3d7cb986c5d72aa4c77288b827504a206da0775a28b9b470baeaea034619ca5114c407034b7aff4386e7199a505f2d82f9497c2b143191ec5
|
data/README.md
CHANGED
|
@@ -57,7 +57,7 @@ Add the gem to your Rails app and configure only if you need overrides:
|
|
|
57
57
|
|
|
58
58
|
```ruby
|
|
59
59
|
Kaal.configure do |config|
|
|
60
|
-
config.scheduler_config_path = Rails.root.join('config/scheduler.yml')
|
|
60
|
+
config.scheduler_config_path = Rails.root.join('config/kaal-scheduler.yml')
|
|
61
61
|
end
|
|
62
62
|
```
|
|
63
63
|
|
|
@@ -14,6 +14,8 @@ module Kaal
|
|
|
14
14
|
|
|
15
15
|
def install_kaal
|
|
16
16
|
results = Kaal::Rails.install!(root: destination_root, backend: selected_backend)
|
|
17
|
+
runtime_config = results.fetch(:runtime_config)
|
|
18
|
+
say_status(runtime_config.fetch(:status), runtime_config.fetch(:path))
|
|
17
19
|
scheduler_config = results.fetch(:scheduler_config)
|
|
18
20
|
say_status(scheduler_config.fetch(:status), scheduler_config.fetch(:path))
|
|
19
21
|
results.fetch(:migrations).each do |migration|
|
data/lib/kaal/rails/installer.rb
CHANGED
|
@@ -12,6 +12,20 @@ module Kaal
|
|
|
12
12
|
module Rails
|
|
13
13
|
# Installs scheduler config and Active Record migrations into a Rails app.
|
|
14
14
|
class Installer
|
|
15
|
+
KAAL_TEMPLATE = <<~YAML
|
|
16
|
+
defaults:
|
|
17
|
+
namespace: kaal
|
|
18
|
+
tick_interval: 5
|
|
19
|
+
window_lookback: 120
|
|
20
|
+
window_lookahead: 0
|
|
21
|
+
lease_ttl: 125
|
|
22
|
+
scheduler_config_path: config/kaal-scheduler.yml
|
|
23
|
+
enable_dispatch_recovery: true
|
|
24
|
+
enable_log_dispatch_registry: false
|
|
25
|
+
delayed_job_allowed_class_prefixes: []
|
|
26
|
+
backend_config: {}
|
|
27
|
+
YAML
|
|
28
|
+
|
|
15
29
|
SCHEDULER_TEMPLATE = <<~YAML
|
|
16
30
|
defaults:
|
|
17
31
|
jobs:
|
|
@@ -31,8 +45,16 @@ module Kaal
|
|
|
31
45
|
@time_source = time_source
|
|
32
46
|
end
|
|
33
47
|
|
|
48
|
+
def install_runtime_config
|
|
49
|
+
ensure_config_dir
|
|
50
|
+
return { status: :exists, path: runtime_config_path_string } if runtime_config_exists?
|
|
51
|
+
|
|
52
|
+
File.write(runtime_config_path, KAAL_TEMPLATE)
|
|
53
|
+
{ status: :create, path: runtime_config_path_string }
|
|
54
|
+
end
|
|
55
|
+
|
|
34
56
|
def install_scheduler_config
|
|
35
|
-
|
|
57
|
+
ensure_config_dir
|
|
36
58
|
return { status: :exists, path: scheduler_config_path_string } if scheduler_config_exists?
|
|
37
59
|
|
|
38
60
|
File.write(scheduler_config_path, SCHEDULER_TEMPLATE)
|
|
@@ -71,18 +93,30 @@ module Kaal
|
|
|
71
93
|
end
|
|
72
94
|
|
|
73
95
|
def scheduler_config_path
|
|
74
|
-
root.join('config', 'scheduler.yml')
|
|
96
|
+
root.join('config', 'kaal-scheduler.yml')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def runtime_config_path
|
|
100
|
+
root.join('config', 'kaal.yml')
|
|
75
101
|
end
|
|
76
102
|
|
|
77
103
|
def scheduler_config_exists?
|
|
78
104
|
scheduler_config_path.exist?
|
|
79
105
|
end
|
|
80
106
|
|
|
107
|
+
def runtime_config_exists?
|
|
108
|
+
runtime_config_path.exist?
|
|
109
|
+
end
|
|
110
|
+
|
|
81
111
|
def scheduler_config_path_string
|
|
82
112
|
scheduler_config_path.to_s
|
|
83
113
|
end
|
|
84
114
|
|
|
85
|
-
def
|
|
115
|
+
def runtime_config_path_string
|
|
116
|
+
runtime_config_path.to_s
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def ensure_config_dir
|
|
86
120
|
FileUtils.mkdir_p(scheduler_config_path.dirname)
|
|
87
121
|
end
|
|
88
122
|
end
|
data/lib/kaal/rails/version.rb
CHANGED
data/lib/kaal/rails.rb
CHANGED
|
@@ -41,6 +41,7 @@ module Kaal
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def configure_backend!(configuration: Kaal.configuration, backend: build_backend)
|
|
44
|
+
load_config_file!(configuration:)
|
|
44
45
|
logger = configuration.logger
|
|
45
46
|
current_backend = configuration.backend
|
|
46
47
|
selected_backend = current_backend || backend
|
|
@@ -51,9 +52,15 @@ module Kaal
|
|
|
51
52
|
selected_backend
|
|
52
53
|
end
|
|
53
54
|
|
|
55
|
+
def load_config_file!(configuration: Kaal.configuration, root: ::Rails.root, environment: ::Rails.env)
|
|
56
|
+
runtime_context = Kaal::Runtime::RuntimeContext.new(root_path: root, environment_name: environment.to_s)
|
|
57
|
+
Kaal::Config::FileLoader.new(configuration:, runtime_context:).load
|
|
58
|
+
end
|
|
59
|
+
|
|
54
60
|
def install!(root: ::Rails.root, backend: detect_backend_name)
|
|
55
61
|
installer = Installer.new(root:, backend:)
|
|
56
62
|
{
|
|
63
|
+
runtime_config: installer.install_runtime_config,
|
|
57
64
|
scheduler_config: installer.install_scheduler_config,
|
|
58
65
|
migrations: installer.install_migrations
|
|
59
66
|
}
|
|
@@ -10,6 +10,7 @@ namespace :kaal do
|
|
|
10
10
|
desc 'Install Kaal scheduler config and Active Record migrations'
|
|
11
11
|
task all: :environment do
|
|
12
12
|
results = Kaal::Rails.install!
|
|
13
|
+
puts "#{results.fetch(:runtime_config).fetch(:status)} #{results.fetch(:runtime_config).fetch(:path)}"
|
|
13
14
|
puts "#{results.fetch(:scheduler_config).fetch(:status)} #{results.fetch(:scheduler_config).fetch(:path)}"
|
|
14
15
|
results.fetch(:migrations).each do |migration|
|
|
15
16
|
puts "#{migration.fetch(:status)} #{migration.fetch(:path)}"
|
data/sig/00_types.rbs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
interface _RBSOpaque
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
interface _RBSCallable
|
|
6
|
+
def call: (*rbs_any args, **rbs_any kwargs) -> rbs_any
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
type rbs_scalar = nil | bool | Integer | Float | Rational | String | Symbol | Time
|
|
10
|
+
type rbs_hash_key = String | Symbol | Integer
|
|
11
|
+
type rbs_any = rbs_scalar | _RBSOpaque | _RBSCallable | Array[rbs_any] | Hash[rbs_hash_key, rbs_any]
|
|
12
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Backend
|
|
3
|
+
class SQLite
|
|
4
|
+
def initialize: (*rbs_any args, **rbs_any kwargs) -> void
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class Postgres
|
|
8
|
+
def initialize: (*rbs_any args, **rbs_any kwargs) -> void
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class MySQL
|
|
12
|
+
def initialize: (*rbs_any args, **rbs_any kwargs) -> void
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.configuration: () -> rbs_any
|
|
17
|
+
def self.warn_on_risky_configuration!: (*rbs_any args, **rbs_any kwargs) -> rbs_any
|
|
18
|
+
|
|
19
|
+
class RuntimeContext
|
|
20
|
+
def self.new: (*rbs_any args, **rbs_any kwargs) -> RuntimeContext
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Config
|
|
24
|
+
class FileLoader
|
|
25
|
+
def initialize: (*rbs_any args, **rbs_any kwargs) -> void
|
|
26
|
+
def load: (*rbs_any args, **rbs_any kwargs) -> rbs_any
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module Internal
|
|
31
|
+
module ActiveRecord
|
|
32
|
+
module MigrationTemplates
|
|
33
|
+
def self.for_backend: (rbs_any backend) -> Array[[String, String]]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module ActiveRecord
|
|
40
|
+
class ConnectionNotEstablished < StandardError
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class Base
|
|
44
|
+
def self.connection_db_config: () -> ::Kaal::rbs_any
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module Rails
|
|
49
|
+
def self.root: () -> ::Kaal::rbs_any
|
|
50
|
+
def self.env: () -> String
|
|
51
|
+
|
|
52
|
+
module Generators
|
|
53
|
+
class Base
|
|
54
|
+
def self.argument: (*::Kaal::rbs_any args, **::Kaal::rbs_any kwargs) -> void
|
|
55
|
+
def self.class_option: (*::Kaal::rbs_any args, **::Kaal::rbs_any kwargs) -> void
|
|
56
|
+
def self.desc: (*::Kaal::rbs_any args, **::Kaal::rbs_any kwargs) -> void
|
|
57
|
+
def self.namespace: (*::Kaal::rbs_any args, **::Kaal::rbs_any kwargs) -> void
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Railtie
|
|
62
|
+
def self.initializer: (*::Kaal::rbs_any args, **::Kaal::rbs_any kwargs) { () -> ::Kaal::rbs_any } -> void
|
|
63
|
+
def self.rake_tasks: () { () -> ::Kaal::rbs_any } -> void
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Rails
|
|
3
|
+
class Installer
|
|
4
|
+
@root: ::Kaal::rbs_any
|
|
5
|
+
|
|
6
|
+
@backend: ::Kaal::rbs_any
|
|
7
|
+
|
|
8
|
+
@time_source: ::Kaal::rbs_any
|
|
9
|
+
|
|
10
|
+
KAAL_TEMPLATE: "defaults:\n namespace: kaal\n tick_interval: 5\n window_lookback: 120\n window_lookahead: 0\n lease_ttl: 125\n scheduler_config_path: config/kaal-scheduler.yml\n enable_dispatch_recovery: true\n enable_log_dispatch_registry: false\n delayed_job_allowed_class_prefixes: []\n backend_config: {}\n"
|
|
11
|
+
|
|
12
|
+
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"
|
|
13
|
+
|
|
14
|
+
def initialize: (root: ::Kaal::rbs_any, backend: ::Kaal::rbs_any, ?time_source: ::Kaal::rbs_any) -> void
|
|
15
|
+
|
|
16
|
+
def install_runtime_config: () -> ({ status: :exists, path: ::Kaal::rbs_any } | { status: :create, path: ::Kaal::rbs_any })
|
|
17
|
+
|
|
18
|
+
def install_scheduler_config: () -> ({ status: :exists, path: ::Kaal::rbs_any } | { status: :create, path: ::Kaal::rbs_any })
|
|
19
|
+
|
|
20
|
+
def install_migrations: () -> ::Kaal::rbs_any
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_reader backend: ::Kaal::rbs_any
|
|
25
|
+
|
|
26
|
+
attr_reader root: ::Kaal::rbs_any
|
|
27
|
+
|
|
28
|
+
attr_reader time_source: ::Kaal::rbs_any
|
|
29
|
+
|
|
30
|
+
def validate_backend: (::Kaal::rbs_any backend_name) -> ::Kaal::rbs_any
|
|
31
|
+
|
|
32
|
+
def scheduler_config_path: () -> ::Kaal::rbs_any
|
|
33
|
+
|
|
34
|
+
def runtime_config_path: () -> ::Kaal::rbs_any
|
|
35
|
+
|
|
36
|
+
def scheduler_config_exists?: () -> ::Kaal::rbs_any
|
|
37
|
+
|
|
38
|
+
def runtime_config_exists?: () -> ::Kaal::rbs_any
|
|
39
|
+
|
|
40
|
+
def scheduler_config_path_string: () -> ::Kaal::rbs_any
|
|
41
|
+
|
|
42
|
+
def runtime_config_path_string: () -> ::Kaal::rbs_any
|
|
43
|
+
|
|
44
|
+
def ensure_config_dir: () -> ::Kaal::rbs_any
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/sig/kaal/rails.rbs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Kaal
|
|
2
|
+
module Rails
|
|
3
|
+
DETECT_BACKEND_DEFAULT: ::Kaal::rbs_any
|
|
4
|
+
|
|
5
|
+
def self.detect_backend_name: (?::Kaal::rbs_any db_config) -> ::Kaal::rbs_any
|
|
6
|
+
|
|
7
|
+
def self.build_backend: (?::Kaal::rbs_any backend_name) -> ::Kaal::rbs_any
|
|
8
|
+
|
|
9
|
+
def self.configure_backend!: (?configuration: ::Kaal::rbs_any, ?backend: ::Kaal::rbs_any) -> (nil | ::Kaal::rbs_any)
|
|
10
|
+
|
|
11
|
+
def self.load_config_file!: (?configuration: ::Kaal::rbs_any, ?root: ::Kaal::rbs_any, ?environment: ::Kaal::rbs_any) -> ::Kaal::rbs_any
|
|
12
|
+
|
|
13
|
+
def self.install!: (?root: ::Kaal::rbs_any, ?backend: ::Kaal::rbs_any) -> { runtime_config: ::Kaal::rbs_any, scheduler_config: ::Kaal::rbs_any, migrations: ::Kaal::rbs_any }
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kaal-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nitesh Purohit
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - '='
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.
|
|
19
|
+
version: 0.6.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - '='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.
|
|
26
|
+
version: 0.6.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rails
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -88,6 +88,13 @@ files:
|
|
|
88
88
|
- lib/kaal/rails/railtie.rb
|
|
89
89
|
- lib/kaal/rails/version.rb
|
|
90
90
|
- lib/tasks/kaal/rails_tasks.rake
|
|
91
|
+
- sig/00_types.rbs
|
|
92
|
+
- sig/dependencies.rbs
|
|
93
|
+
- sig/generators/kaal/install_generator.rbs
|
|
94
|
+
- sig/kaal/rails.rbs
|
|
95
|
+
- sig/kaal/rails/installer.rbs
|
|
96
|
+
- sig/kaal/rails/railtie.rbs
|
|
97
|
+
- sig/kaal/rails/version.rbs
|
|
91
98
|
homepage: https://github.com/Code-Vedas/kaal
|
|
92
99
|
licenses:
|
|
93
100
|
- MIT
|