kaal-rails 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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/bin/importmap +9 -0
- data/bin/rails +18 -0
- data/bin/reek +26 -0
- data/bin/rspec +31 -0
- data/bin/rspec-e2e +8 -0
- data/bin/rspec-unit +3 -0
- data/bin/rubocop +31 -0
- data/bin/update-bundle +9 -0
- data/lib/generators/kaal/install_generator.rb +31 -0
- data/lib/kaal/rails/installer.rb +90 -0
- data/lib/kaal/rails/railtie.rb +22 -0
- data/lib/kaal/rails/version.rb +11 -0
- data/lib/kaal/rails.rb +61 -0
- data/lib/tasks/kaal/rails_tasks.rake +27 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 800bd823b767eafa640969d895f5c1b408f6cfdbce1ea386ca98950eadd2ccc1
|
|
4
|
+
data.tar.gz: 8f611cf0bd2b4f9002184cbf5f5743444aeb8ebcd0b2faa8482f761a5c48ddfb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ea626952cb9cf77da562331ebb7ba727fdae05ff434d99a652e5c9d19c1549a12754d546d63ea69188962dab96391802ce04052f9e2014f46119a20437e9c913
|
|
7
|
+
data.tar.gz: 6cbb6b3d94a29f3b3217fd19052c74feaad8f009ec2b69e6ebfaae41687f51f73ddf17e7a1c4e07d9d32541b115f33563d9d4a3926b841cb5706f9bf0e7e4959
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Codevedas Inc. and the Kaal Authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Kaal::Rails
|
|
2
|
+
|
|
3
|
+
Rails plugin gem for Kaal.
|
|
4
|
+
|
|
5
|
+
`kaal-rails` depends on:
|
|
6
|
+
|
|
7
|
+
- `kaal`
|
|
8
|
+
- `kaal-activerecord`
|
|
9
|
+
|
|
10
|
+
It owns the Rails integration surface:
|
|
11
|
+
|
|
12
|
+
- Railtie
|
|
13
|
+
- rake tasks
|
|
14
|
+
- generators
|
|
15
|
+
- Active Record migration generation
|
|
16
|
+
- Rails dummy app and Rails-specific test coverage
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'kaal-rails'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then generate the scheduler config and migrations:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bundle exec rails generate kaal:install --backend=sqlite
|
|
28
|
+
bundle exec rails db:migrate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
PostgreSQL:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
bundle exec rails generate kaal:install --backend=postgres
|
|
35
|
+
bundle exec rails db:migrate
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
MySQL:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
bundle exec rails generate kaal:install --backend=mysql
|
|
42
|
+
bundle exec rails db:migrate
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## What It Provides
|
|
46
|
+
|
|
47
|
+
- Rails-native setup on top of the Kaal engine
|
|
48
|
+
- Active Record-backed persistence through `kaal-activerecord`
|
|
49
|
+
- migration templates for the Kaal tables required by the selected backend
|
|
50
|
+
- automatic backend selection from the Rails database adapter unless the app sets `Kaal.configuration.backend` itself
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
Add the gem to your Rails app and configure only if you need overrides:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
Kaal.configure do |config|
|
|
58
|
+
config.scheduler_config_path = Rails.root.join('config/scheduler.yml')
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
If you do nothing, `kaal-rails` will auto-wire:
|
|
63
|
+
|
|
64
|
+
- SQLite to `Kaal::ActiveRecord::DatabaseAdapter`
|
|
65
|
+
- PostgreSQL to `Kaal::ActiveRecord::PostgresAdapter`
|
|
66
|
+
- MySQL to `Kaal::ActiveRecord::MySQLAdapter`
|
|
67
|
+
|
|
68
|
+
Available Rails surfaces:
|
|
69
|
+
|
|
70
|
+
- `bin/rails generate kaal:install --backend=sqlite`
|
|
71
|
+
- `bin/rails generate kaal:install --backend=postgres`
|
|
72
|
+
- `bin/rails generate kaal:install --backend=mysql`
|
|
73
|
+
- `bin/rake kaal:install:all`
|
|
74
|
+
- `bin/rake kaal:install:migrations`
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
bin/rspec-unit
|
|
80
|
+
bin/rspec-e2e sqlite
|
|
81
|
+
bin/rubocop
|
|
82
|
+
bin/reek
|
|
83
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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 'bundler/setup'
|
|
8
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
|
9
|
+
load 'rails/tasks/engine.rake'
|
|
10
|
+
require 'bundler/gem_tasks'
|
data/bin/importmap
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Copyright Codevedas Inc. 2025-present
|
|
5
|
+
#
|
|
6
|
+
# This source code is licensed under the MIT license found in the
|
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
|
8
|
+
require_relative '../config/application'
|
|
9
|
+
require 'importmap/commands'
|
data/bin/rails
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Copyright Codevedas Inc. 2025-present
|
|
5
|
+
#
|
|
6
|
+
# This source code is licensed under the MIT license found in the
|
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
|
8
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
9
|
+
# installed from the root of your application.
|
|
10
|
+
|
|
11
|
+
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
|
|
12
|
+
|
|
13
|
+
# Set up gems listed in the Gemfile.
|
|
14
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
15
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
16
|
+
|
|
17
|
+
require 'rails/all'
|
|
18
|
+
require 'rails/engine/commands'
|
data/bin/reek
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Copyright Codevedas Inc. 2025-present
|
|
5
|
+
#
|
|
6
|
+
# This source code is licensed under the MIT license found in the
|
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
|
8
|
+
require 'pty'
|
|
9
|
+
|
|
10
|
+
root_dir = File.expand_path('..', __dir__)
|
|
11
|
+
Dir.chdir(root_dir)
|
|
12
|
+
|
|
13
|
+
command = ['bundle', 'exec', 'reek', *ARGV]
|
|
14
|
+
output = +''
|
|
15
|
+
status = nil
|
|
16
|
+
|
|
17
|
+
PTY.spawn(*command) do |reader, _writer, pid|
|
|
18
|
+
reader.each { |line| output << line }
|
|
19
|
+
rescue Errno::EIO
|
|
20
|
+
nil
|
|
21
|
+
ensure
|
|
22
|
+
_, status = Process.wait2(pid)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
print(output.gsub("\r\n", "\n"))
|
|
26
|
+
exit(status.exitstatus || 1)
|
data/bin/rspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Copyright Codevedas Inc. 2025-present
|
|
5
|
+
#
|
|
6
|
+
# This source code is licensed under the MIT license found in the
|
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
|
8
|
+
#
|
|
9
|
+
# This file was generated by Bundler.
|
|
10
|
+
#
|
|
11
|
+
# The application 'rspec' is installed as part of a gem, and
|
|
12
|
+
# this file is here to facilitate running it.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
16
|
+
|
|
17
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
|
18
|
+
|
|
19
|
+
if File.file?(bundle_binstub)
|
|
20
|
+
if File.read(bundle_binstub, 300).include?('This file was generated by Bundler')
|
|
21
|
+
load(bundle_binstub)
|
|
22
|
+
else
|
|
23
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
24
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
require 'rubygems'
|
|
29
|
+
require 'bundler/setup'
|
|
30
|
+
|
|
31
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/rspec-e2e
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
ADAPTER="${1:-nshift}" # default adapter
|
|
5
|
+
shift || true # remove first arg, leave the rest in "$@"
|
|
6
|
+
|
|
7
|
+
# Run RSpec with environment variables and proper tags
|
|
8
|
+
E2E="1" NO_COVERAGE=1 bin/rspec spec/e2e --tag "integration:${ADAPTER}" "$@"
|
data/bin/rspec-unit
ADDED
data/bin/rubocop
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Copyright Codevedas Inc. 2025-present
|
|
5
|
+
#
|
|
6
|
+
# This source code is licensed under the MIT license found in the
|
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
|
8
|
+
#
|
|
9
|
+
# This file was generated by Bundler.
|
|
10
|
+
#
|
|
11
|
+
# The application 'rubocop' is installed as part of a gem, and
|
|
12
|
+
# this file is here to facilitate running it.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
16
|
+
|
|
17
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
|
18
|
+
|
|
19
|
+
if File.file?(bundle_binstub)
|
|
20
|
+
if File.read(bundle_binstub, 300).include?('This file was generated by Bundler')
|
|
21
|
+
load(bundle_binstub)
|
|
22
|
+
else
|
|
23
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
24
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
require 'rubygems'
|
|
29
|
+
require 'bundler/setup'
|
|
30
|
+
|
|
31
|
+
load Gem.bin_path('rubocop', 'rubocop')
|
data/bin/update-bundle
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
bundle update
|
|
6
|
+
BUNDLE_GEMFILE=gemfiles/rails_7_2.gemfile bundle update
|
|
7
|
+
BUNDLE_GEMFILE=gemfiles/rails_8_0.gemfile bundle update
|
|
8
|
+
BUNDLE_GEMFILE=gemfiles/rails_8_1.gemfile bundle update
|
|
9
|
+
BUNDLE_GEMFILE=gemfiles/rails_edge.gemfile bundle update
|
|
@@ -0,0 +1,31 @@
|
|
|
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 'rails/generators'
|
|
8
|
+
|
|
9
|
+
module Kaal
|
|
10
|
+
module Generators
|
|
11
|
+
# Installs Kaal scheduler config and Active Record migrations into a Rails app.
|
|
12
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
13
|
+
class_option :backend, type: :string, desc: 'sqlite, postgres, or mysql'
|
|
14
|
+
|
|
15
|
+
def install_kaal
|
|
16
|
+
results = Kaal::Rails.install!(root: destination_root, backend: selected_backend)
|
|
17
|
+
scheduler_config = results.fetch(:scheduler_config)
|
|
18
|
+
say_status(scheduler_config.fetch(:status), scheduler_config.fetch(:path))
|
|
19
|
+
results.fetch(:migrations).each do |migration|
|
|
20
|
+
say_status(migration.fetch(:status), migration.fetch(:path))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def selected_backend
|
|
27
|
+
options[:backend] || Kaal::Rails.detect_backend_name
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
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 'fileutils'
|
|
8
|
+
require 'pathname'
|
|
9
|
+
|
|
10
|
+
module Kaal
|
|
11
|
+
module Rails
|
|
12
|
+
# Installs scheduler config and Active Record migrations into a Rails app.
|
|
13
|
+
class Installer
|
|
14
|
+
SCHEDULER_TEMPLATE = <<~YAML
|
|
15
|
+
defaults:
|
|
16
|
+
jobs:
|
|
17
|
+
- key: "example:heartbeat"
|
|
18
|
+
cron: "*/5 * * * *"
|
|
19
|
+
job_class: "ExampleHeartbeatJob"
|
|
20
|
+
enabled: true
|
|
21
|
+
args:
|
|
22
|
+
- "{{fire_time.iso8601}}"
|
|
23
|
+
kwargs:
|
|
24
|
+
idempotency_key: "{{idempotency_key}}"
|
|
25
|
+
YAML
|
|
26
|
+
|
|
27
|
+
def initialize(root:, backend:, time_source: -> { Time.now.utc })
|
|
28
|
+
@root = Pathname(root)
|
|
29
|
+
@backend = validate_backend(backend.to_s)
|
|
30
|
+
@time_source = time_source
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def install_scheduler_config
|
|
34
|
+
ensure_scheduler_config_dir
|
|
35
|
+
return { status: :exists, path: scheduler_config_path_string } if scheduler_config_exists?
|
|
36
|
+
|
|
37
|
+
File.write(scheduler_config_path, SCHEDULER_TEMPLATE)
|
|
38
|
+
{ status: :create, path: scheduler_config_path_string }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def install_migrations
|
|
42
|
+
migrations_dir = root.join('db', 'migrate')
|
|
43
|
+
base_time = time_source.call
|
|
44
|
+
FileUtils.mkdir_p(migrations_dir)
|
|
45
|
+
|
|
46
|
+
Kaal::ActiveRecord::MigrationTemplates.for_backend(backend).map.with_index do |(name, contents), index|
|
|
47
|
+
slug = name.sub(/^\d+_/, '')
|
|
48
|
+
existing = Dir[migrations_dir.join("*_#{slug}").to_s].first
|
|
49
|
+
next({ status: :exists, path: existing.to_s }) if existing
|
|
50
|
+
|
|
51
|
+
timestamp = (base_time + index).strftime('%Y%m%d%H%M%S')
|
|
52
|
+
target = migrations_dir.join("#{timestamp}_#{slug}")
|
|
53
|
+
File.write(target, contents)
|
|
54
|
+
{ status: :create, path: target.to_s }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
attr_reader :backend, :root, :time_source
|
|
61
|
+
|
|
62
|
+
def validate_backend(backend_name)
|
|
63
|
+
if backend_name.strip.empty?
|
|
64
|
+
raise ArgumentError,
|
|
65
|
+
'Could not detect backend from ActiveRecord adapter; pass --backend (sqlite/postgres/mysql)'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
return backend_name if %w[sqlite postgres mysql].include?(backend_name)
|
|
69
|
+
|
|
70
|
+
raise ArgumentError, "Unsupported Rails datastore backend: #{backend_name.inspect}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def scheduler_config_path
|
|
74
|
+
root.join('config', 'scheduler.yml')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def scheduler_config_exists?
|
|
78
|
+
scheduler_config_path.exist?
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def scheduler_config_path_string
|
|
82
|
+
scheduler_config_path.to_s
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def ensure_scheduler_config_dir
|
|
86
|
+
FileUtils.mkdir_p(scheduler_config_path.dirname)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
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 'rails/railtie'
|
|
8
|
+
|
|
9
|
+
module Kaal
|
|
10
|
+
module Rails
|
|
11
|
+
# Railtie that wires Kaal into a Rails app.
|
|
12
|
+
class Railtie < ::Rails::Railtie
|
|
13
|
+
initializer 'kaal-rails.configure_backend', after: 'active_record.initialize_database' do
|
|
14
|
+
Kaal::Rails.configure_backend!
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
rake_tasks do
|
|
18
|
+
load File.expand_path('../../tasks/kaal/rails_tasks.rake', __dir__)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
module Kaal
|
|
8
|
+
module Rails
|
|
9
|
+
VERSION = '0.3.0'
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/kaal/rails.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 'pathname'
|
|
8
|
+
require 'kaal'
|
|
9
|
+
require 'kaal/active_record'
|
|
10
|
+
require 'kaal/rails/version'
|
|
11
|
+
require 'kaal/rails/installer'
|
|
12
|
+
require 'kaal/rails/railtie'
|
|
13
|
+
|
|
14
|
+
module Kaal
|
|
15
|
+
# Rails integration surface for Kaal.
|
|
16
|
+
module Rails
|
|
17
|
+
class << self
|
|
18
|
+
DETECT_BACKEND_DEFAULT = Object.new
|
|
19
|
+
|
|
20
|
+
def detect_backend_name(db_config = DETECT_BACKEND_DEFAULT)
|
|
21
|
+
db_config = ::ActiveRecord::Base.connection_db_config if db_config.equal?(DETECT_BACKEND_DEFAULT)
|
|
22
|
+
adapter = db_config&.adapter.to_s.downcase
|
|
23
|
+
|
|
24
|
+
return 'sqlite' if adapter.include?('sqlite')
|
|
25
|
+
return 'postgres' if adapter.include?('postgres')
|
|
26
|
+
return 'mysql' if adapter.include?('mysql') || adapter.include?('trilogy')
|
|
27
|
+
|
|
28
|
+
nil
|
|
29
|
+
rescue ::ActiveRecord::ConnectionNotEstablished
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def build_backend(backend_name = detect_backend_name)
|
|
34
|
+
case backend_name.to_s
|
|
35
|
+
when 'sqlite'
|
|
36
|
+
Kaal::ActiveRecord::DatabaseAdapter.new
|
|
37
|
+
when 'postgres'
|
|
38
|
+
Kaal::ActiveRecord::PostgresAdapter.new
|
|
39
|
+
when 'mysql'
|
|
40
|
+
Kaal::ActiveRecord::MySQLAdapter.new
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def configure_backend!(configuration: Kaal.configuration, backend: build_backend)
|
|
45
|
+
current_backend = configuration.backend
|
|
46
|
+
return current_backend if current_backend
|
|
47
|
+
return nil unless backend
|
|
48
|
+
|
|
49
|
+
configuration.backend = backend
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def install!(root: ::Rails.root, backend: detect_backend_name)
|
|
53
|
+
installer = Installer.new(root:, backend:)
|
|
54
|
+
{
|
|
55
|
+
scheduler_config: installer.install_scheduler_config,
|
|
56
|
+
migrations: installer.install_migrations
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
8
|
+
namespace :kaal do
|
|
9
|
+
namespace :install do
|
|
10
|
+
desc 'Install Kaal scheduler config and Active Record migrations'
|
|
11
|
+
task all: :environment do
|
|
12
|
+
results = Kaal::Rails.install!
|
|
13
|
+
puts "#{results.fetch(:scheduler_config).fetch(:status)} #{results.fetch(:scheduler_config).fetch(:path)}"
|
|
14
|
+
results.fetch(:migrations).each do |migration|
|
|
15
|
+
puts "#{migration.fetch(:status)} #{migration.fetch(:path)}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
desc 'Install Kaal Active Record migrations'
|
|
20
|
+
task migrations: :environment do
|
|
21
|
+
installer = Kaal::Rails::Installer.new(root: Rails.root, backend: Kaal::Rails.detect_backend_name)
|
|
22
|
+
installer.install_migrations.each do |migration|
|
|
23
|
+
puts "#{migration.fetch(:status)} #{migration.fetch(:path)}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kaal-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nitesh Purohit
|
|
8
|
+
- Codevedas Inc.
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: kaal
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.3.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.3.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: kaal-activerecord
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.3.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.3.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rails
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '7.1'
|
|
48
|
+
- - "<"
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '9.0'
|
|
51
|
+
type: :runtime
|
|
52
|
+
prerelease: false
|
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '7.1'
|
|
58
|
+
- - "<"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '9.0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rails-i18n
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '7.0'
|
|
68
|
+
type: :runtime
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '7.0'
|
|
75
|
+
description: " Kaal-Rails is a Ruby gem that provides seamless integration of Kaal
|
|
76
|
+
with Ruby on Rails, allowing you to easily schedule and manage cron jobs in a distributed
|
|
77
|
+
environment using ActiveRecord models. With Kaal-Rails, you can define your cron
|
|
78
|
+
jobs as ActiveRecord models, and Kaal will handle the scheduling and execution of
|
|
79
|
+
those jobs across multiple instances of your Rails application. This makes it easy
|
|
80
|
+
to build scalable and reliable background job processing systems in your Rails applications.\n"
|
|
81
|
+
email:
|
|
82
|
+
- nitesh.purohit.it@gmail.com
|
|
83
|
+
- team@codevedas.com
|
|
84
|
+
executables: []
|
|
85
|
+
extensions: []
|
|
86
|
+
extra_rdoc_files: []
|
|
87
|
+
files:
|
|
88
|
+
- LICENSE
|
|
89
|
+
- README.md
|
|
90
|
+
- Rakefile
|
|
91
|
+
- bin/importmap
|
|
92
|
+
- bin/rails
|
|
93
|
+
- bin/reek
|
|
94
|
+
- bin/rspec
|
|
95
|
+
- bin/rspec-e2e
|
|
96
|
+
- bin/rspec-unit
|
|
97
|
+
- bin/rubocop
|
|
98
|
+
- bin/update-bundle
|
|
99
|
+
- lib/generators/kaal/install_generator.rb
|
|
100
|
+
- lib/kaal/rails.rb
|
|
101
|
+
- lib/kaal/rails/installer.rb
|
|
102
|
+
- lib/kaal/rails/railtie.rb
|
|
103
|
+
- lib/kaal/rails/version.rb
|
|
104
|
+
- lib/tasks/kaal/rails_tasks.rake
|
|
105
|
+
homepage: https://github.com/Code-Vedas/kaal
|
|
106
|
+
licenses:
|
|
107
|
+
- MIT
|
|
108
|
+
metadata:
|
|
109
|
+
bug_tracker_uri: https://github.com/Code-Vedas/kaal/issues
|
|
110
|
+
changelog_uri: https://github.com/Code-Vedas/kaal/blob/main/CHANGELOG.md
|
|
111
|
+
documentation_uri: https://kaal.codevedas.com
|
|
112
|
+
homepage_uri: https://github.com/Code-Vedas/kaal
|
|
113
|
+
source_code_uri: https://github.com/Code-Vedas/kaal.git
|
|
114
|
+
funding_uri: https://github.com/sponsors/Code-Vedas
|
|
115
|
+
support_uri: https://kaal.codevedas.com/support
|
|
116
|
+
rubygems_uri: https://rubygems.org/gems/kaal-rails
|
|
117
|
+
rubygems_mfa_required: 'true'
|
|
118
|
+
rdoc_options: []
|
|
119
|
+
require_paths:
|
|
120
|
+
- lib
|
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '3.2'
|
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
requirements: []
|
|
132
|
+
rubygems_version: 3.6.7
|
|
133
|
+
specification_version: 4
|
|
134
|
+
summary: Kaal-Rails provides seamless integration of Kaal with Ruby on Rails
|
|
135
|
+
test_files: []
|