async-job-adapter-active_job 0.14.0 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dd9f7593bc4e508c98ca5cff8a163fc594872625467667138213a3ab8f2ed78
4
- data.tar.gz: 78d52a6b38482a80ee4c227d8f753baa2662d313d6a59e284f35de2e00b84e32
3
+ metadata.gz: 754e798963465a3af74167d1fed826c57f37dd843bb5e0150ab4109e940c3658
4
+ data.tar.gz: e8d8dd967ce0f5f444f1fffa3091a7081c87678b33c8607e8ffb111057d7b51f
5
5
  SHA512:
6
- metadata.gz: f205bafb6e23f4eed08575db38d96ec18e4f7e9bad444830b03b6e5a33fac62d91749f0e2ab4bf0328a2fa5192ee19bbdcf182c792de83464555871112674e26
7
- data.tar.gz: e239ac52ec5e7bfae69347c3dcedd4cb0d6dffae60114bcdad4e3c3528c66a49b1bf2c2e4b940ea447b631abb028192336aab1e81b6806fdb7a3539118b532c8
6
+ metadata.gz: 335a1ede4d6f09e76f11ec86abb87481e5e64ab7fd100fd2614ee7e828a5a5bce1687aab08d919c559769181346e7b7f0fa230866a6a7a1f2bb073c97004953e
7
+ data.tar.gz: dc681b9ed7b5ec17af74784b3404d92e6f60d5d9a9d0afb5c0a87c8eb0b9be08ae40f5561009989fcad6e862715a568a65eae3828d4092510552cee4e8fed519
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'async/service/configuration'
5
- require 'async/service/controller'
4
+ require "async/service/configuration"
5
+ require "async/service/controller"
6
6
 
7
- require 'async/job/adapter/active_job/environment'
7
+ require "async/job/adapter/active_job/environment"
8
8
 
9
9
  configuration = Async::Service::Configuration.build do
10
10
  service "async-job-adapter-active_job-server" do
@@ -3,23 +3,39 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'active_job/queue_adapters/abstract_adapter'
6
+ require "active_job/queue_adapters/abstract_adapter"
7
7
 
8
+ require "kernel/sync"
9
+
10
+ # @namespace
8
11
  module ActiveJob
12
+ # @namespace
9
13
  module QueueAdapters
14
+ # ActiveJob adapter for async-job, providing asynchronous job processing capabilities.
10
15
  class AsyncJobAdapter < AbstractAdapter
16
+ # Initialize the adapter with a dispatcher.
17
+ # @parameter dispatcher [Object] The job dispatcher, defaults to the Railtie dispatcher.
11
18
  def initialize(dispatcher = ::Async::Job::Adapter::ActiveJob::Railtie.dispatcher)
12
19
  @dispatcher = dispatcher
13
20
  end
14
21
 
15
22
  # Enqueue a job for processing.
23
+ # @parameter job [ActiveJob::Base] The job to enqueue.
16
24
  def enqueue(job)
17
- @dispatcher.call(job)
25
+ Sync do
26
+ @dispatcher.call(job)
27
+ end
18
28
  end
19
29
 
20
30
  # Enqueue a job for processing at a specific time.
31
+ # @parameter job [ActiveJob::Base] The job to enqueue.
32
+ # @parameter timestamp [Time] The time at which to enqueue the job.
21
33
  def enqueue_at(job, timestamp)
22
- @dispatcher.call(job)
34
+ job.scheduled_at = timestamp
35
+
36
+ Sync do
37
+ @dispatcher.call(job)
38
+ end
23
39
  end
24
40
  end
25
41
  end
@@ -3,10 +3,10 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require_relative 'executor'
6
+ require_relative "executor"
7
7
 
8
- require 'async/job'
9
- require 'async/job/builder'
8
+ require "async/job"
9
+ require "async/job/builder"
10
10
 
11
11
  module Async
12
12
  module Job
@@ -17,7 +17,7 @@ module Async
17
17
  # Prepare the dispacher with the given definitions and aliases.
18
18
  # @parameter definitions [Hash(String, Proc)] The definitions to use constructing queues.
19
19
  # @parameter aliases [Hash(String, Proc)] The aliases for the definitions.
20
- def initialize(definitions, aliases = {})
20
+ def initialize(definitions = {}, aliases = {})
21
21
  @definitions = definitions
22
22
  @aliases = aliases
23
23
 
@@ -30,6 +30,9 @@ module Async
30
30
  # @attribute [Hash(String, String)] The aliases for the definitions.
31
31
  attr :aliases
32
32
 
33
+ # @attribute [Hash(String, Queue)] The queues that have been constructed.
34
+ attr :queues
35
+
33
36
  # Look up a queue by name, constructing it if necessary using the given definition.
34
37
  # @parameter name [String] The name of the queue.
35
38
  def [](name)
@@ -39,6 +42,8 @@ module Async
39
42
  end
40
43
  end
41
44
 
45
+ # Dispatch a job to the appropriate queue.
46
+ # @parameter job [ActiveJob::Base] The job to dispatch.
42
47
  def call(job)
43
48
  name = @aliases.fetch(job.queue_name, job.queue_name)
44
49
 
@@ -50,6 +55,8 @@ module Async
50
55
  self[name].server.start
51
56
  end
52
57
 
58
+ # Get the names of all available queue definitions.
59
+ # @returns [Array<String>] The queue definition names.
53
60
  def keys
54
61
  @definitions.keys
55
62
  end
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require_relative 'service'
6
+ require_relative "service"
7
7
 
8
8
  module Async
9
9
  module Job
@@ -16,18 +16,22 @@ module Async
16
16
  Service
17
17
  end
18
18
 
19
+ # The rails root.
20
+ # @return [String]
19
21
  def root
20
- ENV.fetch('RAILS_ROOT', Dir.pwd)
22
+ ENV.fetch("RAILS_ROOT", Dir.pwd)
21
23
  end
22
24
 
25
+ # Get the default dispatcher instance.
26
+ # @returns [Object] The dispatcher from the Railtie.
23
27
  def dispatcher
24
28
  Railtie.dispatcher
25
29
  end
26
30
 
27
31
  # The name of the queue to use.
28
32
  def queue_names
29
- if queue_names = ENV['ASYNC_JOB_ADAPTER_ACTIVE_JOB_QUEUE_NAMES']
30
- queue_names.split(',')
33
+ if queue_names = ENV["ASYNC_JOB_ADAPTER_ACTIVE_JOB_QUEUE_NAMES"]
34
+ queue_names.split(",")
31
35
  else
32
36
  dispatcher.keys
33
37
  end
@@ -3,13 +3,13 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'json'
6
+ require "json"
7
7
 
8
- require 'console'
9
- require 'console/event/failure'
8
+ require "console"
9
+ require "console/event/failure"
10
10
 
11
- require 'active_job'
12
- require 'active_job/base'
11
+ require "active_job"
12
+ require "active_job/base"
13
13
 
14
14
  module Async
15
15
  module Job
@@ -17,10 +17,14 @@ module Async
17
17
  module ActiveJob
18
18
  # An executor for processing jobs using `ActiveJob`.
19
19
  class Executor
20
+ # Initialize the executor with an optional delegate.
21
+ # @parameter delegate [Object] An optional delegate object for handling lifecycle methods.
20
22
  def initialize(delegate = nil)
21
23
  @delegate = delegate
22
24
  end
23
25
 
26
+ # Execute a job with the given data.
27
+ # @parameter job_data [Hash] Serialized job data from ActiveJob.
24
28
  def execute(job_data)
25
29
  ::ActiveJob::Callbacks.run_callbacks(:execute) do
26
30
  job = ::ActiveJob::Base.deserialize(job_data)
@@ -46,10 +50,12 @@ module Async
46
50
  @delegate&.call(job)
47
51
  end
48
52
 
53
+ # Start the delegate if present.
49
54
  def start
50
55
  @delegate&.start
51
56
  end
52
57
 
58
+ # Stop the delegate if present.
53
59
  def stop
54
60
  @delegate&.stop
55
61
  end
@@ -3,10 +3,10 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'async/job'
7
- require 'async/job/processor/inline'
6
+ require "async/job"
7
+ require "async/job/processor/inline"
8
8
 
9
- require_relative 'thread_local_dispatcher'
9
+ require_relative "thread_local_dispatcher"
10
10
 
11
11
  module Async
12
12
  module Job
@@ -19,6 +19,7 @@ module Async
19
19
  dequeue Processor::Inline
20
20
  end
21
21
 
22
+ # Initialize the railtie with default queue configuration.
22
23
  def initialize
23
24
  @definitions = {"default" => DEFAULT_QUEUE_DEFINITION}
24
25
  @aliases = {}
@@ -3,9 +3,11 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'async/service/generic'
7
- require 'console/event/failure'
8
- require 'async/barrier'
6
+ require "async/service/generic"
7
+ require "console/event/failure"
8
+
9
+ require "async"
10
+ require "async/barrier"
9
11
 
10
12
  module Async
11
13
  module Job
@@ -18,7 +20,7 @@ module Async
18
20
  container.run(name: self.name, restart: true) do |instance|
19
21
  evaluator = @environment.evaluator
20
22
 
21
- require File.expand_path('config/environment', evaluator.root)
23
+ require File.expand_path("config/environment", evaluator.root)
22
24
 
23
25
  dispatcher = evaluator.dispatcher
24
26
 
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require_relative 'dispatcher'
6
+ require_relative "dispatcher"
7
7
 
8
8
  Thread.attr_accessor :async_job_adapter_active_job_dispatcher
9
9
 
@@ -13,6 +13,9 @@ module Async
13
13
  module ActiveJob
14
14
  # Used for dispatching jobs to a thread-local queue to avoid thread-safety issues.
15
15
  class ThreadLocalDispatcher
16
+ # Initialize with queue definitions and aliases.
17
+ # @parameter definitions [Hash] The queue definitions.
18
+ # @parameter aliases [Hash] The queue aliases.
16
19
  def initialize(definitions, aliases)
17
20
  @definitions = definitions
18
21
  @aliases = aliases
@@ -31,10 +34,14 @@ module Async
31
34
  Thread.current.async_job_adapter_active_job_dispatcher ||= Dispatcher.new(@definitions, @aliases)
32
35
  end
33
36
 
37
+ # Get a queue by name.
38
+ # @parameter name [String] The queue name.
34
39
  def [](name)
35
40
  dispatcher[name]
36
41
  end
37
42
 
43
+ # Dispatch a job using the thread-local dispatcher.
44
+ # @parameter job [ActiveJob::Base] The job to dispatch.
38
45
  def call(job)
39
46
  dispatcher.call(job)
40
47
  end
@@ -7,7 +7,7 @@ module Async
7
7
  module Job
8
8
  module Adapter
9
9
  module ActiveJob
10
- VERSION = "0.14.0"
10
+ VERSION = "0.15.0"
11
11
  end
12
12
  end
13
13
  end
@@ -10,3 +10,16 @@ if defined?(Rails::Railtie)
10
10
  require_relative "active_job/railtie"
11
11
  require "active_job/queue_adapters/async_job_adapter"
12
12
  end
13
+
14
+ # @namespace
15
+ module Async
16
+ # @namespace
17
+ module Job
18
+ # @namespace
19
+ module Adapter
20
+ # @namespace
21
+ module ActiveJob
22
+ end
23
+ end
24
+ end
25
+ end
data/license.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # MIT License
2
2
 
3
3
  Copyright, 2024, by Samuel Williams.
4
+ Copyright, 2024, by Trevor Turk.
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -8,7 +8,61 @@ Provides an adapter for ActiveJob on top of `Async::Job`.
8
8
 
9
9
  Please see the [project documentation](https://socketry.github.io/async-job-adapter-active_job/) for more details.
10
10
 
11
- - [Getting Started](https://socketry.github.io/async-job-adapter-active_job/guides/getting-started/index) - This guide explains how to get started with the `async-job-active_job-adapter` gem.
11
+ - [Getting Started](https://socketry.github.io/async-job-adapter-active_job/guides/getting-started/index) - This guide explains how to get started with the `async-job-adapter-active_job` gem.
12
+
13
+ ## Releases
14
+
15
+ Please see the [project releases](https://socketry.github.io/async-job-adapter-active_job/releases/index) for all releases.
16
+
17
+ ### v0.15.0
18
+
19
+ - Fix handling of scheduled jobs with proper `scheduled_at` assignment.
20
+ - 100% documentation coverage.
21
+ - 100% test coverage.
22
+ - Modernize code formatting and structure.
23
+ - Fix typo in gem name (\#7).
24
+
25
+ ### v0.14.1
26
+
27
+ - Ensure the adapter wraps enqueue operations with `Sync` (\#10).
28
+
29
+ ### v0.14.0
30
+
31
+ - Support for running multiple queues.
32
+ - Minor documentation fixes.
33
+
34
+ ### v0.13.0
35
+
36
+ - Add support for `:async_job` queue adapter name.
37
+ - Require `active_job` in the executor.
38
+ - Updated logging examples and documentation.
39
+ - Remove `thread-local` gem dependency.
40
+ - Improve error handling - don't log failures as ActiveJob already handles this.
41
+
42
+ ### v0.12.1
43
+
44
+ - Force string names for queue identifiers, fixes \#5.
45
+
46
+ ### v0.12.0
47
+
48
+ - Improved error handling - let ActiveJob handle retry logic.
49
+
50
+ ### v0.11.0
51
+
52
+ - Prefer `define_queue` and `alias_queue` methods for queue configuration.
53
+
54
+ ### v0.10.0
55
+
56
+ - Rename "pipeline" concept to "queue" for consistency.
57
+
58
+ ### v0.9.0
59
+
60
+ - Update interface to suit upstream async-job changes.
61
+
62
+ ### v0.8.0
63
+
64
+ - Add `#start`/`#stop` delegators for better lifecycle management.
65
+ - Performance improvements with benchmarking.
12
66
 
13
67
  ## Contributing
14
68
 
data/releases.md ADDED
@@ -0,0 +1,86 @@
1
+ # Releases
2
+
3
+ ## v0.15.0
4
+
5
+ - Fix handling of scheduled jobs with proper `scheduled_at` assignment.
6
+ - 100% documentation coverage.
7
+ - 100% test coverage.
8
+ - Modernize code formatting and structure.
9
+ - Fix typo in gem name (\#7).
10
+
11
+ ## v0.14.1
12
+
13
+ - Ensure the adapter wraps enqueue operations with `Sync` (\#10).
14
+
15
+ ## v0.14.0
16
+
17
+ - Support for running multiple queues.
18
+ - Minor documentation fixes.
19
+
20
+ ## v0.13.0
21
+
22
+ - Add support for `:async_job` queue adapter name.
23
+ - Require `active_job` in the executor.
24
+ - Updated logging examples and documentation.
25
+ - Remove `thread-local` gem dependency.
26
+ - Improve error handling - don't log failures as ActiveJob already handles this.
27
+
28
+ ## v0.12.1
29
+
30
+ - Force string names for queue identifiers, fixes \#5.
31
+
32
+ ## v0.12.0
33
+
34
+ - Improved error handling - let ActiveJob handle retry logic.
35
+
36
+ ## v0.11.0
37
+
38
+ - Prefer `define_queue` and `alias_queue` methods for queue configuration.
39
+
40
+ ## v0.10.0
41
+
42
+ - Rename "pipeline" concept to "queue" for consistency.
43
+
44
+ ## v0.9.0
45
+
46
+ - Update interface to suit upstream async-job changes.
47
+
48
+ ## v0.8.0
49
+
50
+ - Add `#start`/`#stop` delegators for better lifecycle management.
51
+ - Performance improvements with benchmarking.
52
+
53
+ ## v0.7.0
54
+
55
+ - Major modernization of the gem structure.
56
+ - Improved documentation generation.
57
+ - Drop Ruby 3.0 support.
58
+ - Fix server binary and add default server configuration.
59
+
60
+ ## v0.6.0
61
+
62
+ - Update dependency on `async-service`.
63
+ - Add explicit `Environment` class for better configuration.
64
+
65
+ ## v0.5.0
66
+
67
+ - Move builder pattern to `async-job` library.
68
+ - Significantly improved test coverage.
69
+
70
+ ## v0.4.0
71
+
72
+ - Add Redis workflow support.
73
+
74
+ ## v0.3.0
75
+
76
+ - Introduce builder pattern for constructing adapters and queues.
77
+ - Support for multiple queues.
78
+
79
+ ## v0.2.0
80
+
81
+ - Add support for basic configuration.
82
+ - Initial test suite.
83
+
84
+ ## v0.1.0
85
+
86
+ - Initial extraction of ActiveJob adapter code from `async-job`.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-job-adapter-active_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ - Trevor Turk
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-08-11 00:00:00.000000000 Z
40
+ date: 1980-01-02 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: async-job
@@ -67,8 +67,6 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0.12'
70
- description:
71
- email:
72
70
  executables:
73
71
  - async-job-adapter-active_job-server
74
72
  extensions: []
@@ -86,13 +84,13 @@ files:
86
84
  - lib/async/job/adapter/active_job/version.rb
87
85
  - license.md
88
86
  - readme.md
87
+ - releases.md
89
88
  homepage: https://github.com/socketry/async-job-adapter-active_job
90
89
  licenses:
91
90
  - MIT
92
91
  metadata:
93
92
  documentation_uri: https://socketry.github.io/async-job-adapter-active_job/
94
93
  source_code_uri: https://github.com/socketry/async-job-adapter-active_job.git
95
- post_install_message:
96
94
  rdoc_options: []
97
95
  require_paths:
98
96
  - lib
@@ -100,15 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
98
  requirements:
101
99
  - - ">="
102
100
  - !ruby/object:Gem::Version
103
- version: '3.1'
101
+ version: '3.2'
104
102
  required_rubygems_version: !ruby/object:Gem::Requirement
105
103
  requirements:
106
104
  - - ">="
107
105
  - !ruby/object:Gem::Version
108
106
  version: '0'
109
107
  requirements: []
110
- rubygems_version: 3.5.11
111
- signing_key:
108
+ rubygems_version: 3.6.7
112
109
  specification_version: 4
113
110
  summary: A asynchronous job queue for Ruby on Rails.
114
111
  test_files: []
metadata.gz.sig CHANGED
Binary file