rails_cron 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d26dbece688aa7396ae1e25181a68e9533fdf63d46d2c52c7425ccb61f92fa12
4
+ data.tar.gz: 1fd1a1f048c6e5afc26650b20bf6d9a6ba76571a541d86980087f2c1f64b6e59
5
+ SHA512:
6
+ metadata.gz: b020b0b130364c6194d91dd3480ebbdb3915519f6a3e707e1a6d895f45ca4d288b61f77720d95b86566a82056bf7a1290fe7bc99cd54d0c7edff9214f9c04850
7
+ data.tar.gz: cceba70a62f2bcf14471dc7c824fa110b8a2ff0258206862517e0bbf4a6aad40fffc23213a58db1af961b96fc7eb2188f40c5cd16a7ebf41885207417956cdc0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 The rails_cron 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,247 @@
1
+ # ⏰ RailsCron
2
+
3
+ > First release 0.1.0 is empty gem.
4
+ > 🕒 A scheduler-agnostic, multi-node-safe cron runner for Ruby and Rails — with Redis or Postgres advisory locks.
5
+
6
+ [![Gem](https://img.shields.io/gem/v/rails_cron.svg?style=flat-square)](https://rubygems.org/gems/rails_cron)
7
+ [![CI](https://github.com/Code-Vedas/rails_cron/actions/workflows/ci.yml/badge.svg)](https://github.com/Code-Vedas/rails_cron/actions/workflows/ci.yml)
8
+ [![Maintainability](https://qlty.sh/gh/Code-Vedas/projects/rails_cron/maintainability.svg)](https://qlty.sh/gh/Code-Vedas/projects/rails_cron)
9
+ [![Code Coverage](https://qlty.sh/gh/Code-Vedas/projects/rails_cron/coverage.svg)](https://qlty.sh/gh/Code-Vedas/projects/rails_cron)
10
+ ![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
11
+ ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-12%2B-336791?style=flat-square&logo=postgresql&logoColor=white)
12
+ ![Redis](https://img.shields.io/badge/Redis-6%2B-d92b2b?style=flat-square&logo=redis&logoColor=white)
13
+
14
+ ---
15
+
16
+ ## ✨ Overview
17
+
18
+ `rails_cron` lets you **bind cron expressions to Ruby code or shell commands** —
19
+ without depending on any specific job system or scheduler (like Sidekiq-Cron or Rufus).
20
+
21
+ It guarantees that:
22
+
23
+ - Each scheduled tick **enqueues work exactly once** across all running Ruby nodes.
24
+ - You remain **agnostic** to your background job system (`ActiveJob`, `Sidekiq`, `Resque`, etc.).
25
+ - Locks are coordinated safely via **Redis** or **PostgreSQL advisory locks**.
26
+ - Cron syntax can be **validated, linted, humanized, and translated** with i18n.
27
+
28
+ ---
29
+
30
+ ## 🧩 Why RailsCron?
31
+
32
+ | Problem | RailsCron Solution |
33
+ | ------------------------------------ | ----------------------------------------------------- |
34
+ | Multiple nodes running the same cron | Distributed locks → exactly-once execution |
35
+ | Cron syntax not human-friendly | Built-in parser + `to_human` translations |
36
+ | Missed runs during downtime | Configurable _lookback_ window replays missed ticks |
37
+ | Coupled to job system | Scheduler-agnostic, works with any Ruby queue backend |
38
+
39
+ ---
40
+
41
+ ## ⚙️ Installation
42
+
43
+ Add to your Gemfile:
44
+
45
+ ```ruby
46
+ gem "rails_cron"
47
+ ```
48
+
49
+ Then run:
50
+
51
+ ```bash
52
+ bundle install
53
+ bin/rails g rails_cron:install
54
+ ```
55
+
56
+ Example initializer (`config/initializers/rails_cron.rb`):
57
+
58
+ ```ruby
59
+ RailsCron.configure do |c|
60
+ # Choose your distributed lock adapter
61
+ # Redis (recommended)
62
+ # c.lock_adapter = RailsCron::Lock::Redis.new(url: ENV["REDIS_URL"])
63
+
64
+ # or Postgres advisory locks
65
+ # c.lock_adapter = RailsCron::Lock::Postgres.new(connection: ActiveRecord::Base.connection)
66
+
67
+ c.tick_interval = 5 # seconds between scheduler ticks
68
+ c.window_lookback = 120 # recover missed runs (seconds)
69
+ c.lease_ttl = 60 # lock TTL in seconds
70
+ end
71
+ ```
72
+
73
+ 👉 [See full installation guide →](https://rails-cron.codevedas.com/install)
74
+
75
+ ---
76
+
77
+ ## 🚀 Quick Start
78
+
79
+ Register a scheduled job anywhere during boot (e.g., `config/initializers/rails_cron_jobs.rb`):
80
+
81
+ ```ruby
82
+ RailsCron.register(
83
+ key: "reports:weekly_summary",
84
+ cron: "0 9 * * 1", # every Monday at 9 AM
85
+ enqueue: ->(fire_time:, idempotency_key:) {
86
+ WeeklySummaryJob.perform_later(fire_time: fire_time, key: idempotency_key)
87
+ }
88
+ )
89
+ ```
90
+
91
+ Start the scheduler:
92
+
93
+ ```bash
94
+ bundle exec rails rails_cron:start
95
+ ```
96
+
97
+ > 💡 Recommended: run as a **dedicated process** in production (Procfile, systemd, Kubernetes).
98
+
99
+ ---
100
+
101
+ ## 🧰 CLI & Rake Tasks
102
+
103
+ ### CLI Examples
104
+
105
+ ```bash
106
+ $ rails-cron explain "*/15 * * * *"
107
+ Every 15 minutes
108
+
109
+ $ rails-cron next "0 9 * * 1" --count 3
110
+ 2025-11-03 09:00:00 UTC
111
+ 2025-11-10 09:00:00 UTC
112
+ 2025-11-17 09:00:00 UTC
113
+ ```
114
+
115
+ ### Rails Tasks
116
+
117
+ ```bash
118
+ bin/rails rails_cron:start # Start scheduler loop
119
+ bin/rails rails_cron:status # Show registry & configuration
120
+ bin/rails rails_cron:tick # Trigger one tick manually
121
+ bin/rails rails_cron:explain["*/5 * * * *"] # Humanize cron expression
122
+ ```
123
+
124
+ ---
125
+
126
+ ## 🧠 Cron Utilities
127
+
128
+ ```ruby
129
+ RailsCron.valid?("0 * * * *") # => true
130
+ RailsCron.simplify("0 0 * * *") # => "@daily"
131
+ RailsCron.lint("*/61 * * * *") # => ["invalid minute step: 61"]
132
+
133
+ I18n.locale = :fr
134
+ RailsCron.to_human("0 9 * * 1") # => "À 09h00 chaque lundi"
135
+ ```
136
+
137
+ > 🈶 All tokens are i18n-based — override translations under `rails_cron.*` keys.
138
+
139
+ ---
140
+
141
+ ## 🧱 Running the Scheduler
142
+
143
+ **Procfile (Heroku / Foreman):**
144
+
145
+ ```procfile
146
+ web: bundle exec puma -C config/puma.rb
147
+ scheduler: bundle exec rails rails_cron:start
148
+ ```
149
+
150
+ **systemd unit:**
151
+
152
+ ```ini
153
+ [Service]
154
+ Type=simple
155
+ WorkingDirectory=/var/apps/myapp/current
156
+ ExecStart=/usr/bin/bash -lc 'bundle exec rails rails_cron:start'
157
+ Restart=always
158
+ ```
159
+
160
+ **Kubernetes Deployment:**
161
+
162
+ ```yaml
163
+ apiVersion: apps/v1
164
+ kind: Deployment
165
+ metadata:
166
+ name: rails-cron
167
+ spec:
168
+ replicas: 1
169
+ template:
170
+ spec:
171
+ containers:
172
+ - name: scheduler
173
+ image: your-app:latest
174
+ command: ["bash", "-lc", "bundle exec rails rails_cron:start"]
175
+ ```
176
+
177
+ ---
178
+
179
+ ## 🔍 Troubleshooting
180
+
181
+ | Symptom | Likely Cause | Fix |
182
+ | -------------------------- | --------------------- | ---------------------------------------- |
183
+ | Jobs run multiple times | Using memory lock | Use Redis or Postgres adapter |
184
+ | Missed jobs after downtime | Short lookback window | Increase `window_lookback` |
185
+ | Scheduler exits early | Normal SIGTERM | Exits gracefully after tick |
186
+ | Redis timeout | Network latency | Increase Redis timeout or switch adapter |
187
+
188
+ 📖 [See FAQ →](https://rails-cron.codevedas.com/faq)
189
+
190
+ ---
191
+
192
+ ## 🧪 Testing Example
193
+
194
+ ```ruby
195
+ RSpec.describe "multi-node safety" do
196
+ it "dispatches exactly once across two threads" do
197
+ redis = FakeRedis::Redis.new
198
+ lock = RailsCron::Lock::Redis.new(client: redis)
199
+ RailsCron.configure { |c| c.lock_adapter = lock }
200
+
201
+ threads = 2.times.map { Thread.new { RailsCron.tick! } }
202
+ threads.each(&:join)
203
+
204
+ expect(redis.keys.grep(/dispatch/).size).to eq(1)
205
+ end
206
+ end
207
+ ```
208
+
209
+ ---
210
+
211
+ ## 🧩 Roadmap
212
+
213
+ | Area | Description | Label |
214
+ | ---------------- | -------------------------------- | --------- |
215
+ | Registry & API | Cron registration and validation | `feature` |
216
+ | Coordinator Loop | Safe ticking and dispatch | `feature` |
217
+ | Lock Adapters | Redis / Postgres | `build` |
218
+ | CLI Tool | `rails-cron` executable | `build` |
219
+ | i18n Humanizer | Multi-language support | `lang` |
220
+ | Docs & Examples | Developer onboarding | `lang` |
221
+
222
+ ---
223
+
224
+ ## 🤝 Contributing
225
+
226
+ 1. Fork the repository
227
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
228
+ 3. Run tests (`bundle exec rspec`)
229
+ 4. Open a PR using the [Feature Request template](.github/ISSUE_TEMPLATE/feature_request.md)
230
+
231
+ Labels: `feature`, `build`, `ci`, `lang`
232
+
233
+ ---
234
+
235
+ ## 📚 Documentation
236
+
237
+ - [Overview & Motivation](https://rails-cron.codevedas.com)
238
+ - [Installation](https://rails-cron.codevedas.com/install)
239
+ - [Usage](https://rails-cron.codevedas.com/usage)
240
+ - [FAQ / Troubleshooting](https://rails-cron.codevedas.com/faq)
241
+
242
+ ---
243
+
244
+ ## 📄 License
245
+
246
+ Released under the [MIT License](LICENSE).
247
+ © 2025 **Codevedas Inc.** — All rights reserved.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'bundler/gem_tasks'
@@ -0,0 +1,13 @@
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
+ # Define a Railtie to integrate with Rails applications
9
+ module RailsCron
10
+ # Define the Railtie class
11
+ class Railtie < ::Rails::Railtie
12
+ end
13
+ end
@@ -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
+
8
+ module RailsCron
9
+ VERSION = '0.1.0'
10
+ end
data/lib/rails_cron.rb ADDED
@@ -0,0 +1,15 @@
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
+ require 'rails_cron/version'
9
+ require 'rails_cron/railtie'
10
+
11
+ ##
12
+ # RailsCron module is the main namespace for the gem
13
+ ##
14
+ module RailsCron
15
+ 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
+
8
+ # desc "Explaining what the task does"
9
+ # task :rails_cron do
10
+ # # Task goes here
11
+ # end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_cron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nitesh Purohit
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '9.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '7.1'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '9.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rails-i18n
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '7.0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '7.0'
46
+ description: " Rails Cron is a Ruby gem that simplifies the management of cron
47
+ jobs in Rails applications, providing an easy-to-use interface for scheduling and
48
+ monitoring background tasks.\n"
49
+ email:
50
+ - nitesh.purohit.it@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/rails_cron.rb
59
+ - lib/rails_cron/railtie.rb
60
+ - lib/rails_cron/version.rb
61
+ - lib/tasks/rails_crons_tasks.rake
62
+ homepage: https://github.com/Code-Vedas/rails_cron
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ bug_tracker_uri: https://github.com/Code-Vedas/rails_cron/issues
67
+ changelog_uri: https://github.com/Code-Vedas/rails_cron/blob/main/CHANGELOG.md
68
+ documentation_uri: https://rails-cron.codevedas.com
69
+ homepage_uri: https://github.com/Code-Vedas/rails_cron
70
+ source_code_uri: https://github.com/Code-Vedas/rails_cron.git
71
+ funding_uri: https://github.com/sponsors/Code-Vedas
72
+ support_uri: https://rails-cron.codevedas.com/support
73
+ rubygems_uri: https://rubygems.org/gems/rails_cron
74
+ rubygems_mfa_required: 'true'
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.6.7
90
+ specification_version: 4
91
+ summary: Ruby gem for managing cron jobs in Rails applications.
92
+ test_files: []