Commit Graph

864 Commits

Author SHA1 Message Date
Alex
10bb51a123 Update Active Job testing guide
The testing guide for Active Job currently implies that when you queue a job it will be performed.

This isn't true; by default jobs are enqueued, not performed.

This PR fleshes out the docs a bit to show both examples, and adds a test to confirm the default behaviour.
2023-06-20 09:58:33 +10:00
zzak
722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak
38bef29064
Replace all occurrences of '<tt>(\w+::\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>Rails::Command::NotesCommand</tt> -> +Rails::Command::NotesCommand+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-25 06:56:17 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Shivam Chahar
ad2280afc6 Docs: Fix queue_as doc wording [ci skip]
Changing the wording of `queue_as` doc as per https://github.com/rails/rails/pull/48099#discussion_r1197516258
2023-05-22 19:59:55 +05:30
zzak
398b904c3e
Merge pull request #48099 from shivamsinghchahar/aj-document-queue-with-priority-block
Document queue_with_priority block arguments and their use [ci skip]
2023-05-21 08:22:01 +09:00
Hartley McGuire
d028c14b03
Link rescue_from from modules including Rescuable
Also add some additional words to make it clear that the modules also
implement handling the exceptions configured with rescue_from, because
it was not immediately clear that happened without reading the code.
2023-05-18 12:54:16 -04:00
Shivam Chahar
55ffc6bfe3 Document queue_with_priority block arguments and their use
Currently, we don't document the use case for ActiveJob's `queue_with_priority` block arguments. It seems necessary to document them in the API docs as well considering how useful this option is.
2023-05-18 13:07:02 +05:30
Jordan Brough
fb1dcea6f3 Remove extraneous case condition
In commit 72300f97 the code for the `String` condition was simplified, and it's
now the same as the code for the `*PERMITTED_TYPES` condition, and `String` is
one of the `PERMITTED_TYPES` so we can just eliminate this condition and let
`*PERMITTED_TYPES` cover it.
2023-05-11 07:13:52 -06:00
Yasuo Honda
0b5f6ad82f
Merge pull request #48157 from shivamsinghchahar/improve-aj-queue-adapter-test
Improve AJ queue adapter test case
2023-05-08 11:44:12 +09:00
Shivam Chahar
daf6e2b0de Improve AJ queue adapter test case
In this test case we only check if the third child's queue adpter is nil or not. We should instead check if the queue adapter is the same as base adapter to ensure that it did not change when we changed qdapters for other jobs.
50f0c0f064/activejob/test/cases/queue_adapter_test.rb (L44-L52)
2023-05-07 12:44:53 +05:30
Shivam Chahar
8ccf129ea1 Fix typo in activejob tests
changes `know` -> `known` in activejob serializers test
2023-05-03 20:38:48 +05:30
Sander Verdonschot
e41d1acc91
Improve queue adapter name extraction for logs
We recently made improvements to the name extraction for `MyJob.queue_adapter_name` (see https://github.com/rails/rails/pull/47995 and https://github.com/rails/rails/pull/48003). I had overlooked that we also extract the queue adapter name in a similar (but not identical) way for log messages, so this change aligns the two.
2023-05-02 08:37:53 -04:00
Shivam Chahar
17d1b83b07 Add tests for AJ to verify queue name passed as symbol. Ref: #48034 2023-04-26 21:37:00 +05:30
Shivam Chahar
562846ae0c Allow symbols as queue names in activejob assertions 2023-04-23 18:53:48 +05:30
Sander Verdonschot
6daba18791
Allow queue adapters to provide a custom name
This gives queue adapters more freedom to name and organize their code.

For example, if `FancyQueue` wants to have their adapter at
`FancyQueue::ActiveJobAdapter`, the name would be `active_job` before this
change. After this change, they can implement `queue_adapter_name` to return
`fancy_queue`.
2023-04-20 13:23:50 -04:00
Sander Verdonschot
6b4acb57e2
Fix name extraction for module queue adapters
Before this change, setting a module as queue adapter would result in
`queue_adapter_name` being `"module"`. This PR fixes the name extraction logic
to handle module or class queue adapters.
2023-04-19 18:51:49 -04:00
fatkodima
5ab2034730 [ActiveJob] Add logging for enqueue_all 2023-04-04 13:18:19 +03:00
fatkodima
f6d56fed27 Add support for logging background job enqueue callers 2023-04-02 03:23:42 +03:00
Petrik
31b94b1a2e Use h1 for Active Job documentation titles [ci-skip]
Most of the other frameworks use a h1(`=`) instead of h2(`==`) for
class/module documentation. Having a h1 will improve SEO and makes
things look more consistent.

This also adds a missing title and escapes namespaces so it won't be
linked.
2023-04-01 15:36:48 +02:00
Petrik de Heus
dc0f20595d
Merge pull request #47717 from p8/docs/include-readmes
Include READMEs in main framework pages of the API documentation
2023-03-30 16:43:14 +02:00
Cameron Matheson
0cb0880b1a implement provider_job_id for Backburner jobs 2023-03-23 19:19:34 -06:00
Petrik
7c94708d24 Include READMEs in main framework pages of the API documentation
Currently when opening the main framework pages there is no introduction
to the framework. Instead we only see a whole lot of modules and the
`gem_version` and `version` methods.

By including the READMEs using the `:include:` directive each frameworks
has a nice introduction.
For markdown READMEs we need to add the :markup: directive.

[ci-skip]

Co-authored-by: zzak <zzakscott@gmail.com>
2023-03-21 21:16:28 +01:00
Pascal Zumkehr
3d3ed6eeb0 Make delayed job display_name failsafe
The display_name method is used by delayed job to log information
about a certain job, including failure messages. Whenever a job class
is moved or deleted, the instances still scheduled cannot be
constantized anymore, causing display_name and hence the log method to
raise an exception. In certain cases, e.g. when logging happens in a
rescue block, this may terminate the entire delayed job worker. With
the failsafe method, the worker handles failed jobs gracefully and
continues work, all with appropriate log output.
2023-03-02 13:38:38 +01:00
Hartley McGuire
286f2f0287
Fix all adapters running delayed_job_adapter_test
This file was introduced in de28930 because the Delayed Job JobWrapper
includes an adapter specific method that logs job parameters. Since it
was the first adapter specific test file, there was not previously any
logic to only run some files for each adapter, so this file was included
when running any adapter's tests.

This commit excludes the delayed_job specific test file from all of the
other adapter test tasks so that they do not require delayed_job and run
these tests.

de28930: de28930d463e66b886632c560d58bb7459037223
2023-02-28 21:35:39 -05:00
zzak
d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Étienne Barrié
c326532004 Remove deprecation warning without a deprecator
The initial deprecation was introduced in 6.1:
bbfab0b33abd7481b8a801b672d7b2316609315a

The configuration stayed with a deprecation in 7.0 but was not
preserving the behavior: 10bd5e59c3291bb2034869e97cca30634a559afb

This removes the configuration and deprecation.
2023-02-15 17:23:20 +01:00
Jean Boussier
9b79798297
Merge pull request #46603 from Mangara/mangara-multi-enqueue
Add `perform_all_later` to enqueue multiple jobs at once
2023-02-13 21:03:58 +01:00
Yasuo Honda
f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
zzak
f8544410a2 Use stable guides link for package READMEs
E.g.: These show up here:
https://api.rubyonrails.org/files/actioncable/README_md.html
2023-02-04 09:01:00 +09:00
Sander Verdonschot
9b62f88a2f
Add perform_all_later to enqueue multiple jobs at once
Sidekiq has a useful optimisation called `push_bulk` that enqueues many jobs at
once, eliminating the repeated Redis roundtrips. However, this feature is not
exposed through Active Job, so it only works for `Sidekiq::Worker` jobs. This
adds a barrier to Active Job adoption for apps that rely on this feature. It
also makes it harder for other queue adapters to implement similar
functionality, as they then have to take care of serialization, callbacks, etc.
themselves.

This commit adds `ActiveJob.perform_all_later(<job1>, <job2>)`, backed by
Sidekiq's `push_bulk` and with a fallback to enqueuing serially if the queue
adapter does not support bulk enqueue.

The performance benefit for 1000 jobs can be more than an order of magnitude:

| Enqueue type       | Serial time (ms) | Bulk time (ms) | Speedup |
| ------------------ | ---------------- | -------------- | ------- |
| Raw Sidekiq        |             2661 |            119 |     22x |
| Active Job Sidekiq |             2853 |            208 |     14x |

(Measured in a simple test app in our production environment.)

Instrumentation for perform_all_later uses a new event `enqueue_all.active_job`
2023-02-02 16:39:22 -05:00
Hartley McGuire
285b63acd9
Fix compatability between tests and Sidekiq 6.5
Since Sidekiq 7.0 requires Ruby 2.7, older versions of Rails that
support older Rubies are still tested against Sidekiq 6.x.

Sidekiq::MAJOR was added in 7.0 so it can't be used for version testing,
see 862dc5b

The config change is due to changes in Sidekiq 6.5. These were accounted
for in 7a069dc but removed in 6d31993.
2023-01-08 20:41:59 -05:00
Hartley McGuire
862dc5b9ca
Fix activejob integration for Sidekiq 6
Sidekiq::MAJOR was added in mperham/sidekiq@b4092e3, which is only
included in 7.0.0+ so we can't use it to check the version for
Sidekiq 6.

Since the test code is written to support both, the condition should
also support both.
2023-01-07 13:45:15 -05:00
Ghouse Mohamed
e0559d2c1c Change 2022 -> 2023 2023-01-03 13:22:00 +05:30
Akira Matsuda
c5af4f4505
s/the the /the /
[ci skip]
2022-12-29 03:56:13 +09:00
Étienne Barrié
3d6a7b2faa Initialize deprecators before configuring them
Since engine initializers run later in the process, we need to run this
initializer earlier than the default.

This ensures they're all registered before the environments are loaded.
2022-11-28 10:47:26 +01:00
Jonathan Hefner
77db302aa0 Add ActiveJob.deprecator
This commit adds `ActiveJob.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `activejob/lib` with
`ActiveJob.deprecator`.

Additionally, this commit adds `ActiveJob.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.

This commit also removes a defunct `ActiveSupport::Deprecation.silence`
call that was added in 9eb4b4ed01f893c2fc7ff3ee4f99301dec7ea3c2 but not
removed when the deprecation was completed in
10bd5e59c3291bb2034869e97cca30634a559afb.
2022-10-31 17:04:26 -05:00
fatkodima
6d31993664 Fix running ActiveJob tests for sidekiq 7.0 2022-10-28 20:36:13 +03:00
Yasuo Honda
50f8b85fc8
Merge pull request #46258 from arielvalentin/fix-activejob-test-helper
fix: Ensure `ActiveJob::TestHelper` sets `scheduled_at` to a `Float`
2022-10-25 22:49:21 +09:00
Alex Ghiculescu
f737b5ec13 Fix double logging in ActiveRecord::QueryLog
Fixes https://github.com/rails/rails/issues/46103

An issue exists if you set `config.active_record.query_log_tags` to an array that includes `:controller`, `:action`, or `:job`; the relevant item will get duplicated in the log line. This occured because the relevant railties would add the item to `config.active_record.query_log_tags` again during setup. This PR fixes that by only adding those items to the config if they aren't already set.

The issue proposed more documentation to work around this, but I think it's a bug and should be fixed directly.
2022-10-22 15:53:14 -05:00
Ariel Valentin
658fd53741
fix: Ensure ActiveJob::TestHelper sets scheduled_at to a Float
I noticed a difference in behavior when inspecting `ActiveJob::Core#scheduled_at` in non-test environments vs when inspecting in while executing tests.

Prior to this change, `ActiveJob::TestHelper` would set `ActiveJob::Core#scheduled_at` to a `Time` object in tests,
however this attribute was set to a `Float` objects in non-test environments:

<d1aa6af5cc/activejob/lib/active_job/core.rb (L161)>

This change ensures parity in all runtime environments.
2022-10-17 19:22:24 +00:00
Jean Boussier
d917896f45 Enable verbose mode in test and report warnings as errors
We recently let a few very easy to avoid warnings get merged.
The root cause is that locally the test suite doesn't run in
verbose mode unless you explictly pass `-w`.

On CI warnings are enabled, but there is no reason to look at the
build output unless something is failing. And even if one wanted
to do that, that would be particularly work intensive since warnings
may be specific to a Ruby version etc.

Because of this I believe we should:

  - Always run the test suite with warnings enabled.
  - Raise an error if a warning is unexpected.

We've been using this pattern for a long time at Shopify both in private
and public repositories.
2022-10-11 09:25:18 +02:00
Rafael Mendonça França
13c786f5a7
Communicate minimum Sidekiq version in its adapter 2022-09-20 21:07:17 +00:00
Jonathan del Strother
b38992038f
Use a higher-level Sidekiq API for ActiveJob
This allows Sidekiq to use a custom client_class (rather than
Sidekiq::Client), which is necessary for the new transaction-aware
client in 6.5 (https://github.com/mperham/sidekiq/blob/main/Changes.md#650)
2022-09-20 13:14:24 +01:00
Yasuo Honda
cb22eb2b36 Remove QueAdapter from Active Job
Que and Rails (Active Job QueAdapter) have applied changes each other
to support Ruby 3 keyword arguments and options provided as top level keywords, etc
via these commits:

https://github.com/rails/rails/pull/44734
https://github.com/rails/rails/pull/44248
d9244b9074 via https://github.com/que-rb/que/pull/319

Finally, we've found it is quite difficult to maintain them.
Going forward Active Job Que adapter can be included in the future version of que gem itself.
Refer to https://github.com/rails/rails/issues/45899 the background for this change.

Active Job Que adapter can be included in the future version of que gem itself.
2022-09-12 22:31:10 +09:00
Jean Boussier
545482650b Update redis and resque
Fix: https://github.com/rails/rails/issues/45913
2022-09-07 15:10:43 +02:00
Ryuta Kamizono
e0e64e9474 Fix typo in activejob/CHANGELOG.md [ci-skip] 2022-08-29 15:34:01 +09:00
Jean Boussier
bd19d1baf1 Optimize AS::LogSubscriber
The various LogSubscriber subclasses tend to subscribe to events
but then end up doing nothing if the log level is high enough.

But even if we end up not logging, we have to go through the
entire notification path, record timing etc.

By allowing subscribers to dynamically bail out early, we can
save a lot of work if all subscribers are silenced.
2022-08-12 09:58:17 +02:00
Sam Bostock
b4fffc3c68
Teach ActiveJob to set configs on itself
Previously configs of the form `config.active_job.X` were only forwarded to
`ActiveJob::Base`. This teaches Active Job to set them on `ActiveJob` directly
instead, if the setter exists.

For consistency, this more or less mirrors the way that Active Record does it.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by: Sam Bostock <sam.bostock@shopify.com>

---

Fix use_big_decimal_serializer Rails 7.1 default

This config should be enabled for new Rails 7.1 apps, or apps that have updated
their config to `load_defaults 7.1`, not disabled.

This also clarifies the config accessor comment.

---

Add contributor documentation comment to load_defaults

The process for introducing a change in behavior in Rails can be confusing to
new contributors, so a comment is added roughly explaining how to do so, and
what belongs in `load_defaults` and `new_framework_defaults`.

This comment is aimed at contributors, not consumers, so it is added within the
method, rather than above it.
2022-07-30 11:11:15 -04:00
Gannon McGibbon
e1635ff4a7 Show default parent classes for generators in help texts
Print default parent class for controller, job, and model generators.

Before:

[--parent=PARENT]               # The parent class for the generated job

After:

[--parent=PARENT]               # The parent class for the generated job
                                # Default: ApplicationJob
2022-07-26 18:13:02 -05:00