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 +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +2 -0
- data/lib/job_enqueue_logger/que_adapter.rb +70 -0
- data/lib/job_enqueue_logger/sucker_punch_adapter.rb +40 -0
- data/lib/job_enqueue_logger/version.rb +1 -1
- data/lib/job_enqueue_logger.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d4b7eb9d105f9c73af421299c43d70573c5ac5b519cf5a334d0a78ed2b704f9
|
4
|
+
data.tar.gz: efe3b6d93873f70676e6c7b9cd085328332fda9cba8fcad99007f4151f3e253c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523da331a92ea785d6a58ce1fbd3e4bcbc9dbbe1a8f3f2974ee2bb0b581a805e100f7e4d0f225710e7e83bf699916514b84e163ba7bec1e302bfcb143752e858
|
7
|
+
data.tar.gz: 2c2b9128d579945615e85eebdd71531e64027b82ad9e16bbff4d1203a96c875f237a977e3b33aaa7f65ea41b433f4cee8abbaba81201c622383e9336ca47663b
|
data/CHANGELOG.md
CHANGED
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)
|
data/lib/job_enqueue_logger.rb
CHANGED
@@ -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.
|
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-
|
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
|