delayed_job-active_job 1.0.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/lib/delayed_job/active_job/job_attributes.rb +15 -0
- data/lib/delayed_job/active_job/run_at.rb +20 -0
- data/lib/delayed_job/active_job/version.rb +7 -0
- data/lib/delayed_job/active_job.rb +6 -0
- data/lib/delayed_job/delayed_job_adapter.rb +96 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73a9d8e3e9c660ca02a3912662159c63885f34fee8a5b979443022a6ef6e8c64
|
4
|
+
data.tar.gz: 3c7dc284a05854437c0a870b497327561e7c3e6d5d1e2f74e735585d07713418
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b20d80faf8e3bc9ba422c8079c1f7bae1183aeaca711820999c42ae293c205390ad0624dfc5aefa830876dbe3ec1d4f6d8f115dbe5764a324669f8e64075e061
|
7
|
+
data.tar.gz: b5726d299fbd037909bc3e14093f6d369f5f3dfd705e127a4e64da7384737b282a9071bc24e131e116e02b82797547c6f38d10de6a7fa526bd8c5e1b506401e1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Alex
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# delayed_job-active_job
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/delayed_job-active_job)
|
4
|
+
[](https://www.ruby-toolbox.com/projects/delayed_job-active_job)
|
5
|
+
[](https://github.com/TandaHQ/delayed_job-active_job/actions/workflows/ci.yml)
|
6
|
+
|
7
|
+
The Delayed Job adapter will be [removed from Rails soon](https://github.com/rails/rails/commit/d55ec9d5831b05ea5de75c105635c80376c0bf11). This gem extracts it so that you can continue using Delayed Job with Active Job.
|
8
|
+
|
9
|
+
If you are using a version of Rails that includes a Delayed Job adapter, using this gem will replace Rails' version with this gem's.
|
10
|
+
|
11
|
+
This gem implements some new features beyond what the Rails adapter did:
|
12
|
+
|
13
|
+
- Support for [`perform_all_later`](https://github.com/rails/rails/pull/46603).
|
14
|
+
- You can set `run_at` directly on a job instance.
|
15
|
+
- You can persist extra attributes on a job by writing to `job_attributes`.
|
16
|
+
|
17
|
+
---
|
18
|
+
|
19
|
+
- [Quick start](#quick-start)
|
20
|
+
- [Support](#support)
|
21
|
+
- [License](#license)
|
22
|
+
- [Contribution guide](#contribution-guide)
|
23
|
+
|
24
|
+
## Quick start
|
25
|
+
|
26
|
+
```
|
27
|
+
gem install delayed_job-active_job
|
28
|
+
```
|
29
|
+
|
30
|
+
Configure the Active Job backend. [See the Rails docs for more information](https://guides.rubyonrails.org/active_job_basics.html#alternate-queuing-backends).
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# config/application.rb
|
34
|
+
config.active_job.queue_adapter = :delayed_job
|
35
|
+
```
|
36
|
+
|
37
|
+
## Support
|
38
|
+
|
39
|
+
If you want to report a bug, or have ideas, feedback or questions about the gem, [let me know via GitHub issues](https://github.com/TandaHQ/delayed_job-active_job/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
44
|
+
|
45
|
+
## Contribution guide
|
46
|
+
|
47
|
+
Pull requests are welcome!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
# Includes the ability to store extra attributes on a job instance, that are persisted into the delayed_jobs table.
|
5
|
+
module JobAttributes
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
class_attribute :job_attributes, instance_writer: true, instance_accessor: true, default: {}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveSupport.on_load(:active_job) do
|
14
|
+
include ActiveJob::JobAttributes
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
# Includes the ability to override when a job should run.
|
5
|
+
module RunAt
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
class_attribute :run_at, instance_writer: true, instance_accessor: false, default: -> { Time.current }
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_at
|
12
|
+
@run_at = instance_exec(&@run_at) if @run_at.is_a?(Proc)
|
13
|
+
@run_at
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveSupport.on_load(:active_job) do
|
19
|
+
include ActiveJob::RunAt
|
20
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delayed_job"
|
4
|
+
require "active_job"
|
5
|
+
require "active_support/core_ext/string/inflections"
|
6
|
+
|
7
|
+
module ActiveJob
|
8
|
+
module QueueAdapters
|
9
|
+
# Override existing Rails adapter.
|
10
|
+
remove_const :DelayedJobAdapter if constants.include?(:DelayedJobAdapter)
|
11
|
+
|
12
|
+
# = Delayed Job adapter for Active Job
|
13
|
+
#
|
14
|
+
# Delayed::Job (or DJ) encapsulates the common pattern of asynchronously
|
15
|
+
# executing longer tasks in the background. Although DJ can have many
|
16
|
+
# storage backends, one of the most used is based on Active Record.
|
17
|
+
# Read more about Delayed Job {here}[https://github.com/collectiveidea/delayed_job].
|
18
|
+
#
|
19
|
+
# To use Delayed Job, set the queue_adapter config to +:delayed_job+.
|
20
|
+
#
|
21
|
+
# Rails.application.config.active_job.queue_adapter = :delayed_job
|
22
|
+
class DelayedJobAdapter < ActiveJob::QueueAdapters::AbstractAdapter
|
23
|
+
def enqueue(job)
|
24
|
+
delayed_job = Delayed::Job.enqueue(
|
25
|
+
JobWrapper.new(job.serialize),
|
26
|
+
queue: job.queue_name,
|
27
|
+
priority: job.priority,
|
28
|
+
run_at: job.run_at,
|
29
|
+
**job.job_attributes
|
30
|
+
)
|
31
|
+
job.provider_job_id = delayed_job.id
|
32
|
+
delayed_job
|
33
|
+
end
|
34
|
+
|
35
|
+
def enqueue_at(job, timestamp)
|
36
|
+
delayed_job = Delayed::Job.enqueue(
|
37
|
+
JobWrapper.new(job.serialize),
|
38
|
+
queue: job.queue_name,
|
39
|
+
priority: job.priority,
|
40
|
+
run_at: job.run_at || Time.at(timestamp),
|
41
|
+
**job.job_attributes
|
42
|
+
)
|
43
|
+
job.provider_job_id = delayed_job.id
|
44
|
+
delayed_job
|
45
|
+
end
|
46
|
+
|
47
|
+
def enqueue_all(jobs)
|
48
|
+
wrapped_jobs = jobs.filter_map do |job|
|
49
|
+
options = Delayed::Backend::JobPreparer.new(
|
50
|
+
JobWrapper.new(job.serialize),
|
51
|
+
queue: job.queue_name,
|
52
|
+
priority: job.priority,
|
53
|
+
run_at: job.run_at,
|
54
|
+
**job.job_attributes
|
55
|
+
).prepare
|
56
|
+
job_to_enqueue = Delayed::Job.new(options)
|
57
|
+
if Delayed::Worker.delay_job?(job_to_enqueue)
|
58
|
+
job_to_enqueue.attributes.except("id", "created_at", "updated_at")
|
59
|
+
else
|
60
|
+
job_to_enqueue.invoke_job
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
Delayed::Job.insert_all(wrapped_jobs)
|
65
|
+
end
|
66
|
+
|
67
|
+
class JobWrapper # :nodoc:
|
68
|
+
attr_accessor :job_data
|
69
|
+
|
70
|
+
def initialize(job_data)
|
71
|
+
@job_data = job_data
|
72
|
+
end
|
73
|
+
|
74
|
+
def display_name
|
75
|
+
base_name = "#{job_data['job_class']} [#{job_data['job_id']}] from DelayedJob(#{job_data['queue_name']})"
|
76
|
+
|
77
|
+
return base_name unless log_arguments?
|
78
|
+
|
79
|
+
"#{base_name} with arguments: #{job_data['arguments']}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def perform
|
83
|
+
Base.execute(job_data)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def log_arguments?
|
89
|
+
job_data["job_class"].constantize.log_arguments?
|
90
|
+
rescue NameError
|
91
|
+
false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: delayed_job-active_job
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activejob
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: delayed_job_active_record
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- alex@tanda.co
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.md
|
50
|
+
- lib/delayed_job/active_job.rb
|
51
|
+
- lib/delayed_job/active_job/job_attributes.rb
|
52
|
+
- lib/delayed_job/active_job/run_at.rb
|
53
|
+
- lib/delayed_job/active_job/version.rb
|
54
|
+
- lib/delayed_job/delayed_job_adapter.rb
|
55
|
+
homepage: https://github.com/TandaHQ/delayed_job-active_job
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata:
|
59
|
+
bug_tracker_uri: https://github.com/TandaHQ/delayed_job-active_job/issues
|
60
|
+
changelog_uri: https://github.com/TandaHQ/delayed_job-active_job/releases
|
61
|
+
source_code_uri: https://github.com/TandaHQ/delayed_job-active_job
|
62
|
+
homepage_uri: https://github.com/TandaHQ/delayed_job-active_job
|
63
|
+
rubygems_mfa_required: 'true'
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '3.1'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.5.23
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Active Job adapter for Delayed Job
|
83
|
+
test_files: []
|