tanga_que_extensions 0.0.16 → 0.0.17

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
  SHA1:
3
- metadata.gz: e861756f6a1f5e6d147072c59a1a0679f926b82d
4
- data.tar.gz: 75ca3cec4029c8941a89a02c118d67dbea9bfd03
3
+ metadata.gz: 8b6eb481ef8df32512bd6a0a0bf9e412129264db
4
+ data.tar.gz: bfb4c939f9e54286b8e600466b625d5285a139a3
5
5
  SHA512:
6
- metadata.gz: cd34bf0a467fb9e27ade5e86bb86cc248d0850e70269cfae158170f2b7f255d70fe430e1f84a2054f3ef81aab4907f509e380542c26d2eace727170b05c7807d
7
- data.tar.gz: 5760a93129e8a927dc61a83eb55c83e8309170c2fa951c6243e7cc74a6b4db5b11d4a24b3ee53e4bd5a7a5c25df6c65a92a5ae649caf001bc281873ba83f7f80
6
+ metadata.gz: adef7ab0a0c7aa13ed82f3240c626586b68c860cb010526861e4cf92cada7cf461bd16f56f5a91d4919320e7e1c396d683c421288eaa520c7856201d1103a094
7
+ data.tar.gz: 3a3c286e5b91935c8e5e92dfbdcd683162192b3da8d453b4faa1ffb32982261af6c21609b737eade50e4ea8bd46cd737d6f112868e306d75689168f2a4378c77
@@ -0,0 +1,31 @@
1
+ require 'digest/md5'
2
+
3
+ module Que
4
+ module PreventDuplicates
5
+ def self.included(base)
6
+ base.send(:extend, ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def enqueue(*args)
11
+ # Handle args same way que does
12
+ if args.last.is_a?(Hash)
13
+ options = args.pop
14
+ options.delete(:queue) || '' if options.key?(:queue)
15
+ job_class = options.delete(:job_class)
16
+ options.delete(:run_at)
17
+ options.delete(:priority)
18
+ args << options if options.any?
19
+ end
20
+
21
+ md5 = Digest::MD5.hexdigest("#{job_class || to_s}#{args.to_json}")
22
+ if ::QueJob.where("md5(job_class || args::text) = ?", md5).exists?
23
+ puts "preventing dupes"
24
+ return
25
+ else
26
+ super
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -9,3 +9,4 @@ require_relative 'notify_on_failures'
9
9
  require_relative 'que_job'
10
10
  require_relative 'que_job_status'
11
11
  require_relative 'set_application_name_when_job_runs'
12
+ require_relative 'prevent_duplicates'
data/test/test.rb CHANGED
@@ -8,12 +8,15 @@ require_relative '../lib/tanga_que_extensions'
8
8
  ActiveRecord::Base.establish_connection 'postgres://localhost/tanga_dev'
9
9
  Que.connection = ActiveRecord
10
10
 
11
+ ActiveRecord::Base.logger = Logger.new($stdout)
12
+
11
13
  #p QueJobStatus.first
12
14
  #p QueJob.first
13
15
 
14
16
  class J < Que::Job
15
17
  prepend Que::RecordJobStatus
16
18
  prepend Que::NotifyDevOnFailures
19
+ include Que::PreventDuplicates
17
20
 
18
21
  class Ack < StandardError
19
22
  def initialize(message, args)
@@ -41,6 +44,11 @@ Que.mode = :async
41
44
 
42
45
  loop do
43
46
  J.enqueue({foo: 1, joe: 'args'})
47
+ J.enqueue({foo: 1, joe: 'args'})
48
+ #J.enqueue({foo: 1, joe: 'args'})
49
+ #J.enqueue({foo: 1, joe: 'args'})
50
+ #J.enqueue({foo: 1, joe: 'args'})
51
+ #J.enqueue({foo: 1, joe: 'args'})
44
52
  sleep 1
45
53
  end
46
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanga_que_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Van Dyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-02 00:00:00.000000000 Z
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: que
@@ -91,6 +91,7 @@ files:
91
91
  - lib/memory_info.rb
92
92
  - lib/notify_on_failures.rb
93
93
  - lib/periodic_job.rb
94
+ - lib/prevent_duplicates.rb
94
95
  - lib/que_job.rb
95
96
  - lib/que_job_status.rb
96
97
  - lib/record_job_status.rb