kaal 0.2.1 → 0.3.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +81 -286
  3. data/Rakefile +4 -2
  4. data/config/kaal.rb +15 -0
  5. data/config/scheduler.yml +12 -0
  6. data/{lib/tasks/kaal_tasks.rake → exe/kaal} +5 -3
  7. data/lib/kaal/backend/adapter.rb +0 -1
  8. data/lib/kaal/backend/dispatch_attempt_logger.rb +33 -0
  9. data/lib/kaal/backend/dispatch_logging.rb +36 -23
  10. data/lib/kaal/backend/dispatch_registry_accessor.rb +43 -0
  11. data/lib/kaal/backend/memory_adapter.rb +7 -5
  12. data/lib/kaal/backend/redis_adapter.rb +6 -6
  13. data/lib/kaal/cli.rb +230 -0
  14. data/lib/kaal/{configuration.rb → config/configuration.rb} +0 -1
  15. data/lib/kaal/{scheduler_config_error.rb → config/scheduler_config_error.rb} +0 -1
  16. data/lib/kaal/config/scheduler_time_zone_resolver.rb +50 -0
  17. data/lib/kaal/config.rb +19 -0
  18. data/lib/kaal/{coordinator.rb → core/coordinator.rb} +42 -62
  19. data/lib/kaal/core/enabled_entry_enumerator.rb +51 -0
  20. data/lib/kaal/core/occurrence_finder.rb +38 -0
  21. data/lib/kaal/core.rb +18 -0
  22. data/lib/kaal/definition/memory_engine.rb +11 -18
  23. data/lib/kaal/definition/persistence_helpers.rb +31 -0
  24. data/lib/kaal/definition/redis_engine.rb +9 -6
  25. data/lib/kaal/definition/registry.rb +24 -2
  26. data/lib/kaal/definitions/registration_service.rb +62 -0
  27. data/lib/kaal/definitions/registry_accessor.rb +33 -0
  28. data/lib/kaal/dispatch/memory_engine.rb +3 -4
  29. data/lib/kaal/dispatch/redis_engine.rb +2 -3
  30. data/lib/kaal/dispatch/registry.rb +0 -1
  31. data/lib/kaal/register_conflict_support.rb +0 -1
  32. data/lib/kaal/registry.rb +0 -1
  33. data/lib/kaal/runtime/runtime_context.rb +41 -0
  34. data/lib/kaal/runtime/scheduler_boot_loader.rb +52 -0
  35. data/lib/kaal/runtime/signal_handler_chain.rb +42 -0
  36. data/lib/kaal/runtime/signal_handler_installer.rb +39 -0
  37. data/lib/kaal/runtime.rb +20 -0
  38. data/lib/kaal/scheduler_file/hash_transform.rb +22 -0
  39. data/lib/kaal/scheduler_file/helper_bundle.rb +28 -0
  40. data/lib/kaal/scheduler_file/job_applier.rb +242 -0
  41. data/lib/kaal/scheduler_file/job_normalizer.rb +90 -0
  42. data/lib/kaal/scheduler_file/loader.rb +152 -0
  43. data/lib/kaal/scheduler_file/payload_loader.rb +95 -0
  44. data/lib/kaal/{scheduler_placeholder_support.rb → scheduler_file/placeholder_support.rb} +0 -1
  45. data/lib/kaal/scheduler_file.rb +18 -0
  46. data/lib/kaal/support/hash_tools.rb +93 -0
  47. data/lib/kaal/{cron_humanizer.rb → utils/cron_humanizer.rb} +19 -1
  48. data/lib/kaal/{cron_utils.rb → utils/cron_utils.rb} +0 -1
  49. data/lib/kaal/{idempotency_key_generator.rb → utils/idempotency_key_generator.rb} +3 -3
  50. data/lib/kaal/utils.rb +18 -0
  51. data/lib/kaal/version.rb +1 -2
  52. data/lib/kaal.rb +77 -397
  53. metadata +64 -44
  54. data/app/models/kaal/cron_definition.rb +0 -76
  55. data/app/models/kaal/cron_dispatch.rb +0 -50
  56. data/app/models/kaal/cron_lock.rb +0 -38
  57. data/lib/generators/kaal/install/install_generator.rb +0 -72
  58. data/lib/generators/kaal/install/templates/create_kaal_definitions.rb.tt +0 -21
  59. data/lib/generators/kaal/install/templates/create_kaal_dispatches.rb.tt +0 -20
  60. data/lib/generators/kaal/install/templates/create_kaal_locks.rb.tt +0 -17
  61. data/lib/generators/kaal/install/templates/kaal.rb.tt +0 -31
  62. data/lib/generators/kaal/install/templates/scheduler.yml.tt +0 -22
  63. data/lib/kaal/backend/mysql_adapter.rb +0 -170
  64. data/lib/kaal/backend/postgres_adapter.rb +0 -134
  65. data/lib/kaal/backend/sqlite_adapter.rb +0 -116
  66. data/lib/kaal/definition/database_engine.rb +0 -50
  67. data/lib/kaal/dispatch/database_engine.rb +0 -94
  68. data/lib/kaal/railtie.rb +0 -183
  69. data/lib/kaal/rake_tasks.rb +0 -184
  70. data/lib/kaal/scheduler_file_loader.rb +0 -321
  71. data/lib/kaal/scheduler_hash_transform.rb +0 -45
@@ -4,14 +4,15 @@
4
4
  #
5
5
  # This source code is licensed under the MIT license found in the
6
6
  # LICENSE file in the root directory of this source tree.
7
-
8
7
  require 'fugit'
9
8
  require 'i18n'
9
+ require 'yaml'
10
10
 
11
11
  module Kaal
12
12
  ##
13
13
  # Human-friendly cron phrase generation with i18n support.
14
14
  module CronHumanizer
15
+ I18N_LOAD_MUTEX = Mutex.new
15
16
  MACRO_PHRASES = {
16
17
  '@yearly' => 'phrases.yearly',
17
18
  '@monthly' => 'phrases.monthly',
@@ -23,6 +24,8 @@ module Kaal
23
24
  module_function
24
25
 
25
26
  def to_human(expression, locale: nil)
27
+ ensure_i18n_loaded!
28
+
26
29
  normalized = CronUtils.safe_normalize_expression(expression)
27
30
  raise ArgumentError, CronUtils.invalid_expression_error_message('') unless normalized
28
31
  raise ArgumentError, CronUtils.invalid_expression_error_message(normalized) if normalized.empty?
@@ -178,5 +181,20 @@ module Kaal
178
181
  I18n.t("kaal.#{key}", **)
179
182
  end
180
183
  private_class_method :translate_phrase
184
+
185
+ def ensure_i18n_loaded!
186
+ locale_file = File.expand_path('../../../config/locales/en.yml', __dir__)
187
+ return if I18n.load_path.include?(locale_file)
188
+
189
+ I18N_LOAD_MUTEX.synchronize do
190
+ return if I18n.load_path.include?(locale_file)
191
+
192
+ I18n.load_path << locale_file
193
+ locales = YAML.safe_load_file(locale_file, aliases: true) || {}
194
+ I18n.available_locales = Array(I18n.available_locales) | locales.keys.map(&:to_sym)
195
+ I18n.backend.load_translations
196
+ end
197
+ end
198
+ private_class_method :ensure_i18n_loaded!
181
199
  end
182
200
  end
@@ -4,7 +4,6 @@
4
4
  #
5
5
  # This source code is licensed under the MIT license found in the
6
6
  # LICENSE file in the root directory of this source tree.
7
-
8
7
  require 'fugit'
9
8
 
10
9
  module Kaal
@@ -4,7 +4,6 @@
4
4
  #
5
5
  # This source code is licensed under the MIT license found in the
6
6
  # LICENSE file in the root directory of this source tree.
7
-
8
7
  module Kaal
9
8
  ##
10
9
  # Utility class for generating idempotency keys.
@@ -13,7 +12,7 @@ module Kaal
13
12
  # Format: {namespace}-{cron_key}-{fire_time_unix}
14
13
  #
15
14
  # @example Generate a key
16
- # key = Kaal::IdempotencyKeyGenerator.call('reports:daily', Time.current, configuration: config)
15
+ # key = Kaal::IdempotencyKeyGenerator.call('reports:daily', Time.now.utc, configuration: config)
17
16
  # # => "kaal-reports:daily-1708283400"
18
17
  class IdempotencyKeyGenerator
19
18
  ##
@@ -24,7 +23,8 @@ module Kaal
24
23
  # @param configuration [Configuration] the Kaal configuration instance
25
24
  # @return [String] the formatted idempotency key
26
25
  def self.call(cron_key, fire_time, configuration:)
27
- namespace = configuration.namespace || 'kaal'
26
+ namespace = configuration.namespace.to_s.strip
27
+ namespace = 'kaal' if namespace.empty?
28
28
  "#{namespace}-#{cron_key}-#{fire_time.to_i}"
29
29
  end
30
30
  end
data/lib/kaal/utils.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright Codevedas Inc. 2025-present
4
+ #
5
+ # This source code is licensed under the MIT license found in the
6
+ # LICENSE file in the root directory of this source tree.
7
+ require 'kaal/utils/cron_utils'
8
+ require 'kaal/utils/cron_humanizer'
9
+ require 'kaal/utils/idempotency_key_generator'
10
+
11
+ module Kaal
12
+ # Utility functions and pure helpers.
13
+ module Utils
14
+ CronUtils = ::Kaal::CronUtils
15
+ CronHumanizer = ::Kaal::CronHumanizer
16
+ IdempotencyKeyGenerator = ::Kaal::IdempotencyKeyGenerator
17
+ end
18
+ end
data/lib/kaal/version.rb CHANGED
@@ -4,7 +4,6 @@
4
4
  #
5
5
  # This source code is licensed under the MIT license found in the
6
6
  # LICENSE file in the root directory of this source tree.
7
-
8
7
  module Kaal
9
- VERSION = '0.2.1'
8
+ VERSION = '0.3.0'
10
9
  end