crontinel-rails 0.1.0 → 0.1.1

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: 2f623c18fd71a3225917bf9c97efb3325a562ddd6d35264e58031e3b29dba8e2
4
- data.tar.gz: 27624c308a624b11536745fcc299bdc7cffbb3838ae43f1af42e5b043dcde00b
3
+ metadata.gz: f7ae9e0abdf91d498f53525fca10376aa5ed1c34cc4488f39d9aa4f20bda1b4f
4
+ data.tar.gz: 10c60ab16d6c7f5c4bd9324f683f4f5bfb02ea7bd9a6a85966f36ef4699e4c9c
5
5
  SHA512:
6
- metadata.gz: 4307c84a27cca9079cf2d737a2772679ff45a618ac9cebb5f8dfff5c3c547432710664b83ef29efde75e20df1ddc928fa60e0ff653b9da0ff669628f4cd85e3f
7
- data.tar.gz: d9b700db533109e35d78f5538971747bc5b645072db40640c48d9273d704b77ecbd1f909827db659b2d8900b08f88ff6c659df0197cb1532aabcc362a6ad48c5
6
+ metadata.gz: 1cedace53dcbc68845b9c0570760376e19a623a803b74573ac7cd03b3a320e542a026c0e4ff2c0ae1f6534d99d9185e7c05aaf5bdc76e0bfac2728ed27cb6493
7
+ data.tar.gz: 5e63e1b0b32fbdf1c6982c4ed8bc14d76cfc16f0d01fb0469e59adfa66aacd9a2701da13e7ea77d2edff39894ad6996bf10ea8cc80b9867422bfc450eb8dc76f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.1] - 2026-11-16
4
+
5
+ - Fix: jobs now report. 0.1.0 called `Crontinel.client` with no key, which always raised and was swallowed, so nothing was sent.
6
+ - Fix: the default endpoint no longer points at `/api/v1/api/mcp` (404). A configured `/api/v1` suffix is dropped.
7
+ - Runs are named by job class, not `Class-<job_id>`, so they group as one job.
8
+ - Each run reports once (no separate start call that recorded an extra finished run).
9
+ - A Crontinel outage no longer fails the job.
10
+ - Removed the Railtie's rake task hook, which required a missing file.
11
+
3
12
  ## [0.1.0] - 2026-04-18
4
13
 
5
14
  - Initial release
data/README.md CHANGED
@@ -9,8 +9,7 @@ Unlike generic uptime tools, Crontinel knows when a job started but crashed sile
9
9
  Add to your `Gemfile`:
10
10
 
11
11
  ```ruby
12
- gem "crontinel-rails", "~> 0.1"
13
- gem "crontinel", "~> 0.1"
12
+ gem "crontinel-rails", "~> 0.1.1"
14
13
  ```
15
14
 
16
15
  ```bash
@@ -19,58 +18,37 @@ bundle install
19
18
 
20
19
  ## Configuration
21
20
 
22
- Create `config/initializers/crontinel.rb`:
23
-
24
- ```ruby
25
- Crontinel.setup do |config|
26
- config.api_key = ENV.fetch("CRONTINEL_API_KEY")
27
- config.endpoint = "https://app.crontinel.com/api/v1" # optional
28
- end
29
- ```
30
-
31
- Or via environment variables:
21
+ Set your app's ingest key. That is all most apps need:
32
22
 
33
23
  ```bash
34
24
  CRONTINEL_API_KEY=your_key_here
35
- CRONTINEL_ENDPOINT=https://app.crontinel.com/api/v1 # optional
25
+ CRONTINEL_ENDPOINT=https://app.crontinel.com # optional, for self-hosted
36
26
  ```
37
27
 
38
- ## ActiveJob Integration
39
-
40
- Automatically tracks all ActiveJob.perform_later jobs:
28
+ Or in `config/application.rb`:
41
29
 
42
30
  ```ruby
43
- # Just include the module — it wraps around_perform automatically
44
- class MyJob < ApplicationJob
45
- include Crontinel::Rails::ActiveJob
46
-
47
- def perform(*args)
48
- # your job work
49
- end
50
- end
31
+ config.crontinel.api_key = ENV["CRONTINEL_API_KEY"]
32
+ config.crontinel.enabled = true # set false to turn reporting off
51
33
  ```
52
34
 
53
- ## Sidekiq Integration
35
+ Without an API key the gem reports nothing and your jobs run as usual.
54
36
 
55
- Automatically tracks Sidekiq jobs via middleware:
37
+ ## What it reports
56
38
 
57
- ```ruby
58
- # lib/crontinel_rails.rb
59
- require "crontinel/rails/sidekiq/server_middleware"
39
+ - **Active Job:** every job reports one run when `perform` finishes, named by the job class (`NightlyReportJob`). An exception reports a failed run and is re-raised.
40
+ - **Sidekiq:** plain Sidekiq workers report the same way through server middleware, added automatically. Active Job jobs on Sidekiq report once, not twice.
60
41
 
61
- Sidekiq.configure_server do |config|
62
- config.server_middleware do |chain|
63
- chain.add Crontinel::Rails::Sidekiq::ServerMiddleware
64
- end
65
- end
66
- ```
42
+ If Crontinel is unreachable, the gem logs a warning and your job's result is unchanged.
43
+
44
+ Runs are sent over the MCP endpoint and carry no outcome metrics. To alert when a job finished but did nothing, send the [HTTP check-in receipt](https://docs.crontinel.com/check-in/recipes/) with a count from inside the job.
67
45
 
68
- ## Manual Tracking
46
+ ## Manual tracking
69
47
 
70
48
  ```ruby
71
- Crontinel.client.task_started(name: "my-cron-job")
72
- # do work...
73
- Crontinel.client.task_finished(name: "my-cron-job", duration_ms: 150)
49
+ Crontinel::Rails.track("nightly-import") do
50
+ # your work
51
+ end
74
52
  ```
75
53
 
76
54
  ## Supported Rails Versions
@@ -7,22 +7,7 @@ module Crontinel
7
7
 
8
8
  included do
9
9
  around_perform do |job, block|
10
- client = Crontinel.client rescue nil
11
- return block.call unless client
12
-
13
- task_name = "#{job.class.name}-#{job.job_id}"
14
- client.task_started(name: task_name)
15
-
16
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
17
- begin
18
- block.call
19
- duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).to_i
20
- client.task_finished(name: task_name, duration_ms: duration_ms)
21
- rescue => e
22
- duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).to_i
23
- client.task_failed(name: task_name, error: e.message, duration_ms: duration_ms)
24
- raise
25
- end
10
+ Crontinel::Rails.track(job.class.name) { block.call }
26
11
  end
27
12
  end
28
13
  end
@@ -3,40 +3,27 @@
3
3
  module Crontinel
4
4
  module Rails
5
5
  class Engine < ::Rails::Engine
6
- isolate_namespace Crontinel::Rails
7
-
8
6
  config.crontinel = ActiveSupport::OrderedOptions.new
9
-
10
- config.crontinel.api_key = ENV["CRONTINEL_API_KEY"]
11
- config.crontinel.endpoint = ENV.fetch("CRONTINEL_ENDPOINT", "https://app.crontinel.com/api/v1")
12
7
  config.crontinel.enabled = true
13
- config.crontinel.log_level = :info
14
-
15
- initializer "crontinel.configure_defaults" do |app|
16
- next unless app.config.crontinel.enabled
17
8
 
18
- app.config.crontinel.api_key ||= ENV["CRONTINEL_API_KEY"]
19
- app.config.crontinel.endpoint ||= "https://app.crontinel.com/api/v1"
20
-
21
- Crontinel.client(
22
- api_key: app.config.crontinel.api_key,
23
- endpoint: app.config.crontinel.endpoint
24
- )
9
+ initializer "crontinel.configure" do |app|
10
+ cfg = app.config.crontinel
11
+ Crontinel::Rails.settings = { api_key: cfg.api_key, endpoint: cfg.endpoint || ENV["CRONTINEL_ENDPOINT"] }
12
+ Crontinel::Rails.reset_client!
25
13
  end
26
14
 
27
- initializer "crontinel.rails.active_job" do
28
- ActiveSupport.on_load(:active_job) do
29
- include Crontinel::Rails::ActiveJob
30
- end
15
+ initializer "crontinel.rails.active_job" do |app|
16
+ next unless app.config.crontinel.enabled
17
+
18
+ ActiveSupport.on_load(:active_job) { include Crontinel::Rails::ActiveJob }
31
19
  end
32
20
 
33
- initializer "crontinel.rails.sidekiq" do
34
- next unless defined?(::Sidekiq) && defined?(::Sidekiq::Middleware)
21
+ initializer "crontinel.rails.sidekiq" do |app|
22
+ next unless app.config.crontinel.enabled && defined?(::Sidekiq) && defined?(::Sidekiq::Middleware)
35
23
 
36
- Sidekiq.configure_server do |config|
37
- config.server_middleware do |chain|
38
- chain.add Crontinel::Rails::Sidekiq::ServerMiddleware
39
- end
24
+ require "crontinel/rails/sidekiq/server_middleware"
25
+ ::Sidekiq.configure_server do |config|
26
+ config.server_middleware { |chain| chain.add Crontinel::Rails::Sidekiq::ServerMiddleware }
40
27
  end
41
28
  end
42
29
  end
@@ -4,28 +4,11 @@ module Crontinel
4
4
  module Rails
5
5
  module Sidekiq
6
6
  class ServerMiddleware
7
- def call(worker, msg, queue)
8
- client = Crontinel.client rescue nil
9
- task_name = "#{worker.class.name}-#{msg["jid"]}"
7
+ def call(worker, msg, _queue, &block)
8
+ # Active Job jobs run through Sidekiq report from their own around_perform.
9
+ return yield if msg["wrapped"]
10
10
 
11
- if client
12
- client.task_started(name: task_name)
13
- end
14
-
15
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
16
- begin
17
- yield
18
- if client
19
- duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).to_i
20
- client.task_finished(name: task_name, duration_ms: duration_ms)
21
- end
22
- rescue => e
23
- if client
24
- duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).to_i
25
- client.task_failed(name: task_name, error: e.message, duration_ms: duration_ms)
26
- end
27
- raise
28
- end
11
+ Crontinel::Rails.track(worker.class.name, &block)
29
12
  end
30
13
  end
31
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Crontinel
4
4
  module Rails
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -1,14 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "crontinel"
3
4
  require "crontinel/rails/version"
4
- require "crontinel/rails/engine"
5
- require "crontinel/rails/railtie" if defined?(Rails::Railtie)
6
5
 
7
6
  module Crontinel
8
7
  module Rails
9
- autoload :Railtie, "crontinel/rails/railtie"
10
- autoload :Middleware, "crontinel/rails/middleware"
11
8
  autoload :ActiveJob, "crontinel/rails/active_job"
12
- autoload :Sidekiq, "crontinel/rails/sidekiq"
9
+
10
+ class << self
11
+ attr_writer :settings
12
+
13
+ # Settings from config.crontinel (the engine fills these in), falling back to Crontinel.setup and env.
14
+ def settings
15
+ @settings ||= {}
16
+ end
17
+
18
+ # One client for the app, or nil when no API key is configured (reporting is then off).
19
+ def client
20
+ return @client if defined?(@client)
21
+
22
+ api_key = settings[:api_key].presence || Crontinel.config.api_key
23
+ endpoint = (settings[:endpoint].presence || Crontinel.config.endpoint).to_s.chomp("/").delete_suffix("/api/v1")
24
+ @client = api_key.present? ? Crontinel.client(api_key: api_key, endpoint: endpoint) : nil
25
+ end
26
+
27
+ def reset_client!
28
+ remove_instance_variable(:@client) if defined?(@client)
29
+ end
30
+
31
+ # Report one run of a job named by its class. A Crontinel outage never fails the job itself.
32
+ def track(name)
33
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
34
+ result = yield
35
+ report { |c| c.task_finished(name: name, duration_ms: elapsed_ms(start)) }
36
+ result
37
+ rescue Exception => e # rubocop:disable Lint/RescueException -- re-raised; only reports first
38
+ report { |c| c.task_failed(name: name, error: e.message, duration_ms: elapsed_ms(start)) } if start
39
+ raise
40
+ end
41
+
42
+ private
43
+
44
+ def elapsed_ms(start)
45
+ ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).to_i
46
+ end
47
+
48
+ def report
49
+ c = client
50
+ yield c if c
51
+ rescue StandardError => e
52
+ warn "[crontinel-rails] could not report run: #{e.class}: #{e.message}"
53
+ end
54
+ end
13
55
  end
14
56
  end
57
+
58
+ require "crontinel/rails/engine" if defined?(Rails::Engine)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crontinel-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harun R Rayhan
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-07-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: crontinel
@@ -78,42 +77,42 @@ dependencies:
78
77
  requirements:
79
78
  - - "~>"
80
79
  - !ruby/object:Gem::Version
81
- version: '5.0'
80
+ version: '6.0'
82
81
  type: :development
83
82
  prerelease: false
84
83
  version_requirements: !ruby/object:Gem::Requirement
85
84
  requirements:
86
85
  - - "~>"
87
86
  - !ruby/object:Gem::Version
88
- version: '5.0'
87
+ version: '6.0'
89
88
  - !ruby/object:Gem::Dependency
90
89
  name: rails
91
90
  requirement: !ruby/object:Gem::Requirement
92
91
  requirements:
93
92
  - - "~>"
94
93
  - !ruby/object:Gem::Version
95
- version: '7.0'
94
+ version: '8.1'
96
95
  type: :development
97
96
  prerelease: false
98
97
  version_requirements: !ruby/object:Gem::Requirement
99
98
  requirements:
100
99
  - - "~>"
101
100
  - !ruby/object:Gem::Version
102
- version: '7.0'
101
+ version: '8.1'
103
102
  - !ruby/object:Gem::Dependency
104
103
  name: sidekiq
105
104
  requirement: !ruby/object:Gem::Requirement
106
105
  requirements:
107
106
  - - "~>"
108
107
  - !ruby/object:Gem::Version
109
- version: '7.0'
108
+ version: '8.1'
110
109
  type: :development
111
110
  prerelease: false
112
111
  version_requirements: !ruby/object:Gem::Requirement
113
112
  requirements:
114
113
  - - "~>"
115
114
  - !ruby/object:Gem::Version
116
- version: '7.0'
115
+ version: '8.1'
117
116
  - !ruby/object:Gem::Dependency
118
117
  name: rubocop
119
118
  requirement: !ruby/object:Gem::Requirement
@@ -144,7 +143,6 @@ files:
144
143
  - lib/crontinel-rails.rb
145
144
  - lib/crontinel/rails/active_job.rb
146
145
  - lib/crontinel/rails/engine.rb
147
- - lib/crontinel/rails/railtie.rb
148
146
  - lib/crontinel/rails/sidekiq/server_middleware.rb
149
147
  - lib/crontinel/rails/version.rb
150
148
  homepage: https://crontinel.com
@@ -155,7 +153,6 @@ metadata:
155
153
  source_code_uri: https://github.com/crontinel/ruby-on-rails
156
154
  changelog_uri: https://github.com/crontinel/ruby-on-rails/blob/main/CHANGELOG.md
157
155
  bug_tracker_uri: https://github.com/crontinel/ruby-on-rails/issues
158
- post_install_message:
159
156
  rdoc_options: []
160
157
  require_paths:
161
158
  - lib
@@ -170,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
167
  - !ruby/object:Gem::Version
171
168
  version: '0'
172
169
  requirements: []
173
- rubygems_version: 3.0.3.1
174
- signing_key:
170
+ rubygems_version: 4.0.23
175
171
  specification_version: 4
176
172
  summary: Crontinel integration for Ruby on Rails — monitor cron jobs and background
177
173
  workers
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Crontinel
4
- module Rails
5
- class Railtie < ::Rails::Railtie
6
- config.crontinel = ActiveSupport::OrderedOptions.new
7
-
8
- initializer "crontinel.configure" do |app|
9
- api_key = app.config.crontinel.api_key || ENV["CRONTINEL_API_KEY"]
10
- Crontinel.configure { |c| c.api_key = api_key } if api_key && defined?(Crontinel)
11
- end
12
-
13
- rake_tasks do
14
- require "crontinel/rails/tasks"
15
- end
16
- end
17
- end
18
- end