kaal-hanami 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5eb7f6bfd10c50d917f398cb8dc3bb86890287b089dd0acb5a2917057c734c9
4
- data.tar.gz: cfa820d9b97bd7cc987886211cbb63fe95022072dc7c8f3f68288e98a645f859
3
+ metadata.gz: e1ec2250d7b6d9b2a8af4fe3c9e5b5d542a9e1ee6623d36c411e3fa89d8f676c
4
+ data.tar.gz: 06d0e49ac88b8a03ed5cc107a405714bde70b992a7db01b1362e9fc385110ef4
5
5
  SHA512:
6
- metadata.gz: 5b150d1fac759cdc90be18ce0e5c3ff695ce3f1d356cc0bc76eb6c34f7081ed06d9e30fe443bad4c77f851845c35b2225f78b3263114c409713d409dd16393af
7
- data.tar.gz: 0f18e4f660296296d41fb3829dc0ba8b928ee15410033789f2a46e3621c45390f5215fb2a6714b3821cc0f244edd6d91fcc5666149aafce510acf8b8b7634acf
6
+ metadata.gz: 9286c5220ef5ccbc51ea1e4dd08d896a5d36db98fcb09f6ece02a6a7c455df9e0da6ebbd0d04d495fe0fe7e0ed1de5ff47abf3dc5ad93427254d9ede276cec02
7
+ data.tar.gz: 37caed455e28e8f4052637116d0d595de74ddc0ed5796b464460a0468bce1974a089c849cc0a3ca3b9427045e35488aded439037e66c91f434614f2e9bc75451
data/README.md CHANGED
@@ -29,7 +29,7 @@ If you use SQL persistence, create the Kaal tables using Sequel migrations. `kaa
29
29
  - PostgreSQL: `kaal_dispatches`, `kaal_definitions`, `kaal_delayed_jobs`
30
30
  - MySQL: `kaal_dispatches`, `kaal_definitions`, `kaal_delayed_jobs`
31
31
 
32
- Your app should also provide `config/scheduler.yml`.
32
+ Your app should also provide `config/kaal-scheduler.yml`.
33
33
 
34
34
  ## What It Provides
35
35
 
@@ -50,8 +50,7 @@ module MyApp
50
50
  class App < Hanami::App
51
51
  Kaal::Hanami.configure!(
52
52
  self,
53
- backend: Kaal::Backend::MemoryAdapter.new,
54
- scheduler_config_path: 'config/scheduler.yml',
53
+ scheduler_config_path: 'config/kaal-scheduler.yml',
55
54
  namespace: 'my-app',
56
55
  start_scheduler: false
57
56
  )
@@ -66,12 +65,12 @@ require 'redis'
66
65
 
67
66
  module MyApp
68
67
  class App < Hanami::App
69
- REDIS = Redis.new(url: ENV.fetch('REDIS_URL'))
68
+ REDIS = Redis.new(url: "redis://127.0.0.1:6379/0")
70
69
 
71
70
  Kaal::Hanami.configure!(
72
71
  self,
73
72
  redis: REDIS,
74
- scheduler_config_path: 'config/scheduler.yml',
73
+ scheduler_config_path: 'config/kaal-scheduler.yml',
75
74
  namespace: 'my-app',
76
75
  start_scheduler: false
77
76
  )
@@ -94,7 +93,7 @@ module MyApp
94
93
  self,
95
94
  database: database,
96
95
  adapter: 'postgres', # optional when Sequel can infer it
97
- scheduler_config_path: 'config/scheduler.yml'
96
+ scheduler_config_path: 'config/kaal-scheduler.yml'
98
97
  )
99
98
  end
100
99
  end
@@ -126,7 +125,7 @@ Preferred deployment model:
126
125
  ## Public API
127
126
 
128
127
  - `Kaal::Hanami.configure!(app, **options)`
129
- - `Kaal::Hanami.register!(app, backend: nil, database: nil, redis: nil, scheduler_config_path: 'config/scheduler.yml', namespace: nil, start_scheduler: false, adapter: nil, root: nil, environment: nil)`
128
+ - `Kaal::Hanami.register!(app, backend: nil, database: nil, redis: nil, scheduler_config_path: 'config/kaal-scheduler.yml', namespace: nil, start_scheduler: false, adapter: nil, root: nil, environment: nil)`
130
129
  - `Kaal::Hanami.configure_backend!(backend: nil, database: nil, redis: nil, adapter: nil, configuration: Kaal.configuration)`
131
130
  - `Kaal::Hanami.detect_backend_name(database, adapter: nil)`
132
131
  - `Kaal::Hanami.load_scheduler_file!(root:, environment: nil)`
@@ -14,7 +14,7 @@ module Kaal
14
14
  backend: nil,
15
15
  database: nil,
16
16
  redis: nil,
17
- scheduler_config_path: 'config/scheduler.yml',
17
+ scheduler_config_path: 'config/kaal-scheduler.yml',
18
18
  namespace: nil,
19
19
  start_scheduler: false,
20
20
  adapter: nil,
@@ -6,6 +6,6 @@
6
6
  # LICENSE file in the root directory of this source tree.
7
7
  module Kaal
8
8
  module Hanami
9
- VERSION = '0.5.0'
9
+ VERSION = '0.6.0'
10
10
  end
11
11
  end
data/lib/kaal/hanami.rb CHANGED
@@ -24,7 +24,7 @@ module Kaal
24
24
  backend: nil,
25
25
  database: nil,
26
26
  redis: nil,
27
- scheduler_config_path: 'config/scheduler.yml',
27
+ scheduler_config_path: 'config/kaal-scheduler.yml',
28
28
  namespace: nil,
29
29
  start_scheduler: false,
30
30
  adapter: nil,
@@ -32,11 +32,12 @@ module Kaal
32
32
  environment: nil
33
33
  )
34
34
  configuration = Kaal.configuration
35
- normalized_scheduler_config_path = scheduler_config_path.to_s.strip
36
- normalized_namespace = namespace.to_s.strip
37
- configuration.scheduler_config_path = normalized_scheduler_config_path unless normalized_scheduler_config_path.empty?
38
- configuration.namespace = normalized_namespace unless normalized_namespace.empty?
39
-
35
+ load_config_file!(
36
+ root: root_path_for(app, root:),
37
+ environment: environment_name_for(app, environment:),
38
+ configuration:
39
+ )
40
+ apply_runtime_overrides(configuration:, scheduler_config_path:, namespace:)
40
41
  configure_backend!(backend:, database:, redis:, adapter:, configuration:)
41
42
  load_scheduler_file!(
42
43
  root: root_path_for(app, root:),
@@ -72,6 +73,11 @@ module Kaal
72
73
  configuration.backend = build_backend(backend_name, database)
73
74
  end
74
75
 
76
+ def load_config_file!(root:, environment:, configuration: Kaal.configuration)
77
+ runtime_context = Kaal::Runtime::RuntimeContext.new(root_path: root, environment_name: runtime_environment_name(environment))
78
+ Kaal::Config::FileLoader.new(configuration:, runtime_context:).load
79
+ end
80
+
75
81
  def detect_backend_name(database, adapter: nil)
76
82
  explicit_adapter = normalize_backend_name(adapter)
77
83
  return explicit_adapter if explicit_adapter
@@ -119,6 +125,13 @@ module Kaal
119
125
  end
120
126
  end
121
127
 
128
+ def apply_runtime_overrides(configuration:, scheduler_config_path:, namespace:)
129
+ normalized_scheduler_config_path = scheduler_config_path.to_s.strip
130
+ normalized_namespace = namespace.to_s.strip
131
+ configuration.scheduler_config_path = normalized_scheduler_config_path unless normalized_scheduler_config_path.empty?
132
+ configuration.namespace = normalized_namespace unless normalized_namespace.empty?
133
+ end
134
+
122
135
  def database_adapter_name(database)
123
136
  return if database.nil?
124
137
 
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,55 @@
1
+ module Kaal
2
+ module Backend
3
+ class MemoryAdapter
4
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
5
+ end
6
+
7
+ class RedisAdapter
8
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
9
+ end
10
+
11
+ class SQLite
12
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
13
+ end
14
+
15
+ class Postgres
16
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
17
+ end
18
+
19
+ class MySQL
20
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
21
+ end
22
+ end
23
+
24
+ def self.configuration: () -> rbs_any
25
+ def self.running?: () -> bool
26
+ def self.start!: () -> rbs_any
27
+ def self.stop!: (*rbs_any args, **rbs_any kwargs) -> rbs_any
28
+ def self.load_scheduler_file!: (*rbs_any args, **rbs_any kwargs) -> rbs_any
29
+
30
+ module Runtime
31
+ class RuntimeContext
32
+ def self.new: (*rbs_any args, **rbs_any kwargs) -> RuntimeContext
33
+ def self.environment_name_from: (Hash[String, String] env) -> String
34
+ end
35
+
36
+ class SchedulerBootLoader
37
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
38
+ def load_on_boot!: () -> rbs_any
39
+ end
40
+ end
41
+
42
+ module Config
43
+ class FileLoader
44
+ def initialize: (*rbs_any args, **rbs_any kwargs) -> void
45
+ def load: (*rbs_any args, **rbs_any kwargs) -> rbs_any
46
+ end
47
+ end
48
+ end
49
+
50
+ module Hanami
51
+ def self.env: () -> String
52
+
53
+ class App
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module Kaal
2
+ module Hanami
3
+ class Middleware
4
+ @app: ::Kaal::rbs_any
5
+
6
+ def initialize: (::Kaal::rbs_any app, hanami_app: ::Kaal::rbs_any, ?backend: ::Kaal::rbs_any?, ?database: ::Kaal::rbs_any?, ?redis: ::Kaal::rbs_any?, ?scheduler_config_path: ::String, ?namespace: ::Kaal::rbs_any?, ?start_scheduler: bool, ?adapter: ::Kaal::rbs_any?, ?root: ::Kaal::rbs_any?, ?environment: ::Kaal::rbs_any?) -> void
7
+
8
+ def call: (::Kaal::rbs_any env) -> ::Kaal::rbs_any
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Kaal
2
+ module Hanami
3
+ VERSION: String
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ module Kaal
2
+ module Hanami
3
+ self.@shutdown_hook_mutex: ::Kaal::rbs_any
4
+
5
+ def self.configure!: (::Kaal::rbs_any app, **::Kaal::rbs_any) -> ::Kaal::rbs_any
6
+
7
+ def self.register!: (::Kaal::rbs_any app, ?backend: ::Kaal::rbs_any?, ?database: ::Kaal::rbs_any?, ?redis: ::Kaal::rbs_any?, ?scheduler_config_path: ::String, ?namespace: ::Kaal::rbs_any?, ?start_scheduler: bool, ?adapter: ::Kaal::rbs_any?, ?root: ::Kaal::rbs_any?, ?environment: ::Kaal::rbs_any?) -> ::Kaal::rbs_any
8
+
9
+ def self.configure_backend!: (?backend: ::Kaal::rbs_any?, ?database: ::Kaal::rbs_any?, ?redis: ::Kaal::rbs_any?, ?adapter: ::Kaal::rbs_any?, ?configuration: ::Kaal::rbs_any) -> ::Kaal::rbs_any
10
+
11
+ def self.load_config_file!: (root: ::Kaal::rbs_any, environment: ::Kaal::rbs_any, ?configuration: ::Kaal::rbs_any) -> ::Kaal::rbs_any
12
+
13
+ def self.detect_backend_name: (::Kaal::rbs_any database, ?adapter: ::Kaal::rbs_any?) -> ::Kaal::rbs_any
14
+
15
+ def self.load_scheduler_file!: (root: ::Kaal::rbs_any, ?environment: ::Kaal::rbs_any?) -> ::Kaal::rbs_any
16
+
17
+ def self.start!: () -> ::Kaal::rbs_any
18
+
19
+ def self.stop!: (?timeout: ::Integer) -> ::Kaal::rbs_any
20
+
21
+ private
22
+
23
+ def self.build_redis_backend: (::Kaal::rbs_any redis, ::Kaal::rbs_any configuration) -> ::Kaal::rbs_any
24
+
25
+ def self.build_backend: (::Kaal::rbs_any backend_name, ::Kaal::rbs_any database) -> ::Kaal::rbs_any
26
+
27
+ def self.apply_runtime_overrides: (configuration: ::Kaal::rbs_any, scheduler_config_path: ::Kaal::rbs_any, namespace: ::Kaal::rbs_any) -> ::Kaal::rbs_any
28
+
29
+ def self.database_adapter_name: (::Kaal::rbs_any database) -> (nil | ::Kaal::rbs_any)
30
+
31
+ def self.normalize_backend_name: (::Kaal::rbs_any adapter_name) -> (nil | "sqlite" | "postgres" | "mysql")
32
+
33
+ def self.root_path_for: (::Kaal::rbs_any app, ?root: ::Kaal::rbs_any?) -> ::Kaal::rbs_any
34
+
35
+ def self.environment_name_for: (::Kaal::rbs_any app, ?environment: ::Kaal::rbs_any?) -> ::Kaal::rbs_any
36
+
37
+ def self.runtime_environment_name: (::Kaal::rbs_any environment) -> ::Kaal::rbs_any
38
+
39
+ def self.start_managed_scheduler!: () -> (nil | ::Kaal::rbs_any)
40
+
41
+ def self.install_shutdown_hook: () -> (nil | ::Kaal::rbs_any)
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaal-hanami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nitesh Purohit
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.5.0
39
+ version: 0.6.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.5.0
46
+ version: 0.6.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +79,11 @@ files:
79
79
  - lib/kaal/hanami.rb
80
80
  - lib/kaal/hanami/middleware.rb
81
81
  - lib/kaal/hanami/version.rb
82
+ - sig/00_types.rbs
83
+ - sig/dependencies.rbs
84
+ - sig/kaal/hanami.rbs
85
+ - sig/kaal/hanami/middleware.rbs
86
+ - sig/kaal/hanami/version.rbs
82
87
  homepage: https://github.com/Code-Vedas/kaal
83
88
  licenses:
84
89
  - MIT