placate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c781f759fd2282b4cbbf32039ef53e5eed2f1959bf46d670b13cc57139e7a91
4
- data.tar.gz: e96b43f21704a5ae648a1acc2a3dfd8530f5669c301cfdf872d44d8bbbc73510
3
+ metadata.gz: 2d3b1bfbb5182eadb35385c0d3e8f0578f675a26c9ae25e368730294215defba
4
+ data.tar.gz: cf536fb1870080c6177c24b3482d3bd7c95a63594f6c2f4d6ea4d754a59624c1
5
5
  SHA512:
6
- metadata.gz: 7d3005d9ff5ba7a53b501706066bb5d7657fa72e5e40b6846dab2e1b8282dcf973a5a932d4d1c932f02a2d2409851060b56c22d492b759d0915651dea7a60acf
7
- data.tar.gz: e2be1bab70de91dd7e595c64c50367e3a2985551d69f2f587af4e0d3183c03c9ada2a3b99562497f2396f69609ee08d9e7f8922fcb7820f7663aa500dd2e6f7d
6
+ metadata.gz: 237bd256ed3127604b1bb2a511d3be0390f2eb4ed49fe97ac2d094724bd9a492497e0a0d328f46844655639d4d43491fb6a774b6dfa1127012353f0e3fdc5a25
7
+ data.tar.gz: a092e2c6e0c6f4d6919d8a88ea1e4a2a27ab4f93f3108c3bdaaba5d7b766df8779f9b85479574ce136c3c2b822aa4bf1867e79c0244d2300d3dfb4db43dbaad3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Placate
2
2
 
3
- Placate is a simple Redis-based solution for preventing duplicate job execution in Ruby background job processors. It's designed to work with ActiveJob and any Redis-backed job system.
3
+ Placate is a lightweight Redis-based solution designed to prevent duplicate jobs in Rails ActiveJob.
4
4
 
5
5
  ## Installation
6
6
 
@@ -25,7 +25,10 @@ First, configure Placate with your Redis connection:
25
25
  # config/initializers/placate.rb
26
26
  Placate.configure do |config|
27
27
  config.redis = Redis.new
28
- config.default_lock_ttl = 30 # Default time-to-live in seconds
28
+
29
+ # time-to-live in seconds
30
+ # default is nil, which only allows 1 job to be queued at a time
31
+ # config.default_lock_ttl = 30
29
32
  end
30
33
  ```
31
34
 
@@ -5,7 +5,7 @@ module Placate
5
5
  attr_accessor :redis, :default_lock_ttl
6
6
 
7
7
  def initialize
8
- @default_lock_ttl = 60 # 1 minute default
8
+ @default_lock_ttl = nil
9
9
  end
10
10
  end
11
11
  end
@@ -28,11 +28,17 @@ module Placate
28
28
  existing_lock = Placate.redis.get(lock_key)
29
29
 
30
30
  if existing_lock
31
- lock_time = existing_lock.to_i
32
- throw :abort if current_time - lock_time < (job.class.unique_lock_ttl || 30)
31
+ # Only check TTL if it's set
32
+ if job.class.unique_lock_ttl
33
+ lock_time = existing_lock.to_i
34
+ throw :abort unless current_time - lock_time >= job.class.unique_lock_ttl
35
+ else
36
+ throw :abort # No TTL, just prevent duplicates
37
+ end
33
38
  end
34
39
 
35
40
  Placate.redis.set(lock_key, current_time)
41
+ job.instance_variable_set(:@unique_lock_key, lock_key)
36
42
  end
37
43
 
38
44
  after_perform do |job|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Placate
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: placate
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
  - Toby