job_enqueue_logger 0.1.0 → 0.2.0

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: 8bd89f4945224bc0c74d429110323c609a26c63f1eef1202c588d58d9a90bb13
4
- data.tar.gz: 4bda89a97eb8c1afc974edf24e37b4685ea1b354a184e782bd10e80fd383c8b3
3
+ metadata.gz: 8d4b7eb9d105f9c73af421299c43d70573c5ac5b519cf5a334d0a78ed2b704f9
4
+ data.tar.gz: efe3b6d93873f70676e6c7b9cd085328332fda9cba8fcad99007f4151f3e253c
5
5
  SHA512:
6
- metadata.gz: fe5c00d27ef14b4c7da8458cd3500b8dda2af19bdb56f1829588abe3f0a6634f284e8e46b5ca92cdbb2f16a4ed89e1a3be3f9cb578dbd942066b8da809cf11d0
7
- data.tar.gz: cc5b8a0463f46332cb03bb5cadd3aeb4b2de8aa6b3f5cd4fbca7c9fe730e5d18f82e95a656683dc5d83daa7eb2ca664c32c63386ff99bded51f40cff1ad5e9fb
6
+ metadata.gz: 523da331a92ea785d6a58ce1fbd3e4bcbc9dbbe1a8f3f2974ee2bb0b581a805e100f7e4d0f225710e7e83bf699916514b84e163ba7bec1e302bfcb143752e858
7
+ data.tar.gz: 2c2b9128d579945615e85eebdd71531e64027b82ad9e16bbff4d1203a96c875f237a977e3b33aaa7f65ea41b433f4cee8abbaba81201c622383e9336ca47663b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## master (unreleased)
2
2
 
3
- ## 0.1.0 (2023-03-29)
3
+ ## 0.2.0 (2023-04-04)
4
+
5
+ - Support `que`
6
+ - Support `sucker_punch`
7
+
8
+ ## 0.1.0 (2023-03-30)
4
9
 
5
10
  - First release
data/README.md CHANGED
@@ -32,6 +32,8 @@ This gem supports most common job queuing backends:
32
32
  * [Sidekiq](https://github.com/sidekiq/sidekiq) >= 6.5.0
33
33
  * [Resque](https://github.com/resque/resque) >= 2.0.0
34
34
  * [DelayedJob](https://github.com/collectiveidea/delayed_job) >= 4.1.5
35
+ * [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) >= 3.0.0
36
+ * [Que](https://github.com/que-rb/que) >= 2.0.0
35
37
 
36
38
  If you need support for older rubies or older versions of queuing backends (or additional backends), [open an issue](https://github.com/fatkodima/job_enqueue_logger/issues/new).
37
39
 
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JobEnqueueLogger
4
+ module QueAdapter
5
+ module Job
6
+ def enqueue(*)
7
+ job = super
8
+ unless Thread.current[:que_jobs_to_bulk_insert]
9
+ job_attrs = job.que_attrs
10
+ job_class = job_attrs[:job_class]
11
+ args = job_attrs[:args]
12
+ args << job_attrs[:kwargs] unless job_attrs[:kwargs].empty?
13
+
14
+ if (id = job_attrs[:id])
15
+ message = "Enqueued #{job_class} (id=#{id}) to Que(#{job_attrs[:queue]})"
16
+
17
+ run_at = job_attrs[:run_at].utc
18
+ message += " at #{run_at}" if run_at > Time.now.utc
19
+ message += Utils.args_info(args)
20
+ else
21
+ # Job performed inline.
22
+ message = "Performed inline #{job_class}" + Utils.args_info(args)
23
+ end
24
+ Utils.log_job_enqueue(QueAdapter.logger, message)
25
+ end
26
+ job
27
+ end
28
+ ruby2_keywords(:enqueue)
29
+
30
+ def bulk_enqueue(**)
31
+ jobs = super
32
+ if jobs.any?
33
+ job_attrs = jobs.first.que_attrs
34
+ job_class = job_attrs[:job_class]
35
+
36
+ if job_attrs[:id]
37
+ run_at = job_attrs[:run_at].utc
38
+
39
+ message = "Enqueued"
40
+ message += " #{jobs.size}" if jobs.size > 1
41
+ message += " #{job_class} to Que(#{job_attrs[:queue]})"
42
+ message += " at #{run_at}" if run_at > Time.now.utc
43
+ else
44
+ message = "Performed inline"
45
+ message += " #{jobs.size}" if jobs.size > 1
46
+ message += " #{job_class}"
47
+ end
48
+
49
+ Utils.log_job_enqueue(QueAdapter.logger, message)
50
+ end
51
+ jobs
52
+ end
53
+ end
54
+
55
+ def self.logger
56
+ # Que.server? is defined in the newest version of Que - https://github.com/que-rb/que/pull/382
57
+ is_server = defined?(Que::CommandLineInterface)
58
+
59
+ if !is_server && defined?(Rails)
60
+ Rails.logger
61
+ elsif Que.logger.respond_to?(:call)
62
+ Que.logger.call
63
+ else
64
+ Que.logger
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ Que::Job.singleton_class.prepend(JobEnqueueLogger::QueAdapter::Job)
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JobEnqueueLogger
4
+ # There is no easy way to detect if the job is performed inline,
5
+ # so extend only enqueuing methods.
6
+ module SuckerPunchAdapter
7
+ module Job
8
+ def perform_async(*args)
9
+ enqueued = super
10
+ if enqueued
11
+ message = "Enqueued #{name} to SuckerPunch" + Utils.args_info(args)
12
+ Utils.log_job_enqueue(SuckerPunchAdapter.logger, message)
13
+ end
14
+ enqueued
15
+ end
16
+ ruby2_keywords(:perform_async)
17
+
18
+ def perform_in(interval, *args)
19
+ enqueued = super
20
+ if enqueued
21
+ at = (Time.now + interval).utc
22
+ message = "Enqueued #{name} to SuckerPunch in #{interval} seconds (at #{at})" + Utils.args_info(args)
23
+ Utils.log_job_enqueue(SuckerPunchAdapter.logger, message)
24
+ end
25
+ enqueued
26
+ end
27
+ ruby2_keywords(:perform_in)
28
+ end
29
+
30
+ def self.logger
31
+ if defined?(Rails)
32
+ Rails.logger
33
+ else
34
+ SuckerPunch.logger
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ SuckerPunch::Job::ClassMethods.prepend(JobEnqueueLogger::SuckerPunchAdapter::Job)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobEnqueueLogger
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -30,4 +30,6 @@ end
30
30
  require_relative "job_enqueue_logger/sidekiq_adapter" if defined?(Sidekiq)
31
31
  require_relative "job_enqueue_logger/resque_adapter" if defined?(Resque)
32
32
  require_relative "job_enqueue_logger/delayed_job_adapter" if defined?(Delayed::Job)
33
+ require_relative "job_enqueue_logger/sucker_punch_adapter" if defined?(SuckerPunch)
34
+ require_relative "job_enqueue_logger/que_adapter" if defined?(Que)
33
35
  require_relative "job_enqueue_logger/railtie" if defined?(Rails)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job_enqueue_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-30 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Log background jobs enqueued by your application (additionally with backtraces).
@@ -25,9 +25,11 @@ files:
25
25
  - README.md
26
26
  - lib/job_enqueue_logger.rb
27
27
  - lib/job_enqueue_logger/delayed_job_adapter.rb
28
+ - lib/job_enqueue_logger/que_adapter.rb
28
29
  - lib/job_enqueue_logger/railtie.rb
29
30
  - lib/job_enqueue_logger/resque_adapter.rb
30
31
  - lib/job_enqueue_logger/sidekiq_adapter.rb
32
+ - lib/job_enqueue_logger/sucker_punch_adapter.rb
31
33
  - lib/job_enqueue_logger/utils.rb
32
34
  - lib/job_enqueue_logger/version.rb
33
35
  homepage: https://github.com/fatkodima/job_enqueue_logger