Commit Graph

942 Commits

Author SHA1 Message Date
Hartley McGuire
ac916c643a
Document ActiveJob::Base#logger and #log_arguments 2024-07-10 23:14:42 -04:00
Dennis Paagman
912440d8b7 Improve performance of ActiveJob::LogSubscriber#enqueue_source_location
In line with the improvements made in #49095, implements the same
lazily yielding backtrace frame. This will improve the performance of
`verbose_enqueue_logs`.
2024-07-06 20:07:21 +02:00
Rafael Mendonça França
7ee34d9efb
Enable Rails minitest plugin in our rake tasks 2024-05-23 16:16:37 +00:00
George Ma
9b069eed46 Add regression test for memoized queue adapter 2024-05-14 13:06:48 -04:00
George Ma
94c6de51bc Memoize queue_adapter_for_test
Co-authored-by: Étienne Barrié <etienne.barrie@shopify.com>
2024-05-14 12:21:23 -04:00
Rafael Mendonça França
bf59d363fb
Clean CHANGELOG for 8.0 2024-05-13 16:55:52 +00:00
Rafael Mendonça França
37fd0e7fe4
Development of Rails 8.0 starts now
🎉
2024-05-13 16:45:20 +00:00
Alex Ghiculescu
2194a738c7 Active Job: Correctly use the desired test adapter in tests 2024-05-09 17:35:50 +10:00
fatkodima
702638291c
Fix tests without assertions in the framework 2024-04-30 23:29:30 +00:00
Jean Boussier
d5c88d68c3 Fix some more ignored block warnings
Ref: https://bugs.ruby-lang.org/issues/15554

A couple are harmless, but another couple found actual problems
in the test suite where we passed blocks to `assert_*` methods that
didn't expect one.
2024-04-19 10:23:42 +02:00
sampatbadhe
528e9016d9 Correct typo for ActiveJob::Enqueuing::ClassMethods doc 2024-04-18 07:24:56 +05:30
Jean Boussier
afa019835b Fix ActiveJob::EnqueueAfterTransactionCommit API
Fix: https://github.com/rails/rails/pull/51426#issuecomment-2042611790

`perform_later` is supposed to return the Job instance on success,
and `false` on error.

When the `enqueue` is automatically delayed, it's of course impossible
to predict if the actual queueing will succeed, but for backward compatibility
reasons, it's best to assume it will.

If necessary, you can hold onto the job instance and check for
`#successfully_enqueued?` after the transaction has completed.
2024-04-10 09:20:12 +02:00
fatkodima
041de49399 Remove usage of OpenStruct 2024-04-09 21:35:08 +03:00
Carlos Antonio da Silva
8ad19d9865 Minor tweaks / improvements to recent changelog/api docs [ci skip] 2024-04-08 14:48:44 -03:00
Petrik
52f37c4d81 Update enqueue_after_transaction_commit changelog [ci-skip]
The config option accepts `:never`, `:always` and `:default`.
2024-04-05 21:26:28 +02:00
Jean Boussier
e922c59207 Implement Active Job enqueue_after_transaction_commit
A fairly common mistake with Rails is to enqueue a job from inside a
transaction, with a record as argumemnt, which then lead to a RecordNotFound
error when picked up by the queue.

This is even one of the arguments advanced for job runners backed by the
database such as `solid_queue`, `delayed_job` or `good_job`.

But relying on this is undesirable in my opinion as it makes the Active Job
abstraction leaky, and if in the future you need to migrate to another backend
or even just move the queue to a separate database, you may experience a lot of
race conditions of the sort.

To resolve this problem globally, we can make Active Job optionally transaction
aware, and automatically defer job queueing to `after_commit`.

Co-Authored-By: Cristian Bica <cristian.bica@gmail.com>
2024-04-03 16:32:16 +02:00
Jean Boussier
50daadaa71 Update test suite for compatibility with Ruby 3.4-dev
https://bugs.ruby-lang.org/issues/19117 and https://bugs.ruby-lang.org/issues/16495
slightly change how backtrace are rendered which makes a few tests fail.
2024-02-16 11:55:44 +01:00
Rafael Mendonça França
154f7c2181
Register autoload for ActiveJob::Arguments
Since #50715, there are cases where `ActiveJob::Arguments` is used
but not required anymore in the test environment. This could be a
test for a custom argument serializer.

One solution could be to add a require "active_job/arguments" in
all the usages, but that isn't a convention we follow in Rails.

Instead, let's register the autoload for `ActiveJob::Arguments` in
`active_job.rb` so that it's always available when needed.
2024-02-13 20:34:10 +00:00
Nick Dower
22bc976576 Tiny update to callbacks docs [ci skip]
The following was added to the `ActiveJob::Callbacks`,
`ActiveModel::Callbacks` and `AbstractController:Callbacks` docs
in #29072:

> NOTE: Calling the same callback multiple times will overwrite
> previous callback definitions.

The comment refers to "calling" callbacks but seems to be about defining
callbacks, as mentioned in the PR description.

In the ActiveJob and AbstractController docs, I believe this will be
misinterpreted as referring to setting callbacks, which, as far as I can
tell, does not have such a restriction.

In the ActiveModel docs, I believe it would be slightly clearer to
replace "calling" with "defining".
2024-02-02 12:11:30 +01:00
Lorenzo Zabot
349ce8dc2d docs: correct fixed-width font documentation 2024-01-25 20:20:10 +01:00
Petrik
db6eb7b72c Specify singleton method name for accessors defined on singleton_class [ci-skip]
RDoc can't extract the name of accessors defined with
`singleton_class.attr_accessor`, resulting in methods called `unknown`
in RDoc.
2024-01-22 12:34:07 +01:00
Petrik
8565f45100 Use relative includes of README's in documentation [ci-skip]
The Rails documentation uses the `:include:` directive to inline the
README of the framework into the main documentation page. As the
README's aren't in the root directory from where SDoc is run we need to
add the framework path to the include:

    # :include: activesupport/README.md

This results in a warning when installing the gems as generating the rdoc for the gem is run from the gem/framework root:

    Couldn't find file to include 'activesupport/README.rdoc' from lib/active_support.rb

The `:include:` RDoc directive supports includes relative to the current
file as well:

    # :include: ../README.md

This makes sure it works for the Rails API docs and the separate gems.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2024-01-18 10:39:15 +01:00
Sander Verdonschot
427acd8d6a
Improve after_enqueue example
The current example suggests that after_enqueue is only called if the
enqueue is successful, which is not always true.
2024-01-12 17:14:50 -05:00
maximerety
f72d2118fe
[Fix #50713] Do not trigger loading of ActiveJob::Base in ActiveJob::TestHelper 2024-01-11 19:52:47 +01:00
Jean Boussier
27140247c2 Cleanup defined? usage
Now that we dropped support for Ruby 2.7, we no longer
need to check if variables are defined before accessing them
to avoid the undefined variable warning.
2024-01-05 15:05:35 +01:00
Jean Boussier
c2636a615e
Merge pull request #50491 from byroot/bump-required-ruby
Bump the required Ruby version to 3.1.0
2023-12-31 09:16:59 +01:00
Jean Boussier
6ba2fdb2fe Bump the required Ruby version to 3.1.0
Until now, Rails only droped compatibility with older
rubies on new majors, but I propose to change this policy
because it causes us to either keep compatibility with long
EOLed rubies or to bump the Rails major more often, and to
drop multiple Ruby versions at once when we bump the major.

In my opinion it's a bad alignments of incentives. And we'd
be much better to just drop support in new minors whenever they
go EOL (so 3 years).

Also Ruby being an upstream dependency, it's not even
a semver violation AFAICT.

Since Rails 7.2 isn't planned before a few months, we
can already drop Ruby 3.0 as it will be EOL in March.
2023-12-31 08:54:03 +01:00
Will Jessop
7606002f13 Move singleton require.
ActiveSupport::Deprecation used to `include Singleton` which is why the require is here, but it was removed in 9812641891f1c9ba4c3f8ffb8549ec26fc2668c4 (June 5 2023). Leaving the require seems to have been an oversight.

However, module ActiveJob::Serializers::ObjectSerializer does require Singleton and was relying on AS:Deprecation to require it. This PR just moves the require to the place it's actually used.
2023-12-30 12:02:01 +00:00
John Hawthorn
1a4474e7ee
Revert "Do not overwrite AJ logger if it is supplied" 2023-12-04 17:32:50 -08:00
Joshua Young
18098ccc4c [Fix #50230] Preserve serialized timezone when deserializing with ActiveJob::Serializers::TimeWithZoneSerializer 2023-12-03 00:37:09 +10:00
Hartley McGuire
d64acfdcac
Fix Active Job skips
Similarly to Action Mailbox, these tests didn't pass because the skip
patch was included before ActiveSupport::TestCase was defined. Moving
the patch to the bottom of the file fixes the issue.

Once the skip patch was fixed, all of the skips were due to differences
in adapters which aren't really test skips as much as tests that should
not ever run against those adapters.
2023-11-30 11:11:22 -05:00
Aerdayne
e03cc187f5 Do not overwrite AJ logger if it is supplied
Use conditional assignment within 'active_job.logger' initializer
2023-11-25 09:36:45 +01:00
Rafael Mendonça França
03dae98092
Remove deprecated :exponentially_longer value for the :wait in retry_on 2023-11-22 22:13:59 +00:00
Rafael Mendonça França
798289699d
Remove deprecated support to set numeric values to scheduled_at attribute 2023-11-22 22:13:06 +00:00
Rafael Mendonça França
2a761d23d2
Remove deprecated primitive serializer for BigDecimal arguments 2023-11-22 22:13:03 +00:00
Katherine Oelsner
e57e462a62 ActiveJob: fallback serializing String subclasses
https://github.com/rails/rails/pull/50090 broke serialization of String
subclasses that don't have serializers, like ActiveSupport::SafeBuffer.

Co-authored-by: John Hawthorn <john@hawthorn.email>
2023-11-20 23:41:19 +00:00
fatkodima
14578eaa4f Fix ActiveJob arguments serialization to correctly serialize String subclasses having custom serializers
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-11-18 01:55:24 +02:00
Aidan Haran
6dd980fed0 Remove unused test job 2023-11-08 16:33:53 +00:00
Aashish Saini
d8b3c557e9 Use cannonical form of library names 2023-10-30 12:51:35 -05:00
Jean Boussier
9497f47131 Turn skips into errors on Rails CI
We had a few cases of tests being skipped accidentally on CI
hence not bein ran for a long time.

Skipping make sense when running the test suite locally, e.g.
you may not have Redis or some other dependency running.

But on CI, a test not being ran should be considered an error.
2023-10-26 12:46:01 +02:00
William Johnston
584a9d409c
Fix ActiveJob method name in sucker_punch 1.0 error 2023-10-23 16:13:11 -05:00
Akhil G Krishnan
6eb93332c4 Typo fix in BigDecimal job arguments warning 2023-10-19 21:22:31 +05:30
Dustin Brown
be9d0f05a4 Don't include enqueuing info when job wasn't enqueued 2023-10-11 10:57:36 -07:00
Jonathan Hefner
4230d0d2be Fix perform_enqueued_jobs :at option doc [ci-skip]
The `:at` option will perform jobs that have been enqueued to run at the
exact specified time, as well as before the specified time.
2023-10-07 12:26:26 -05:00
Jonathan Hefner
705d515ac5 Reword adapter caveat for perform_enqueued_jobs [ci-skip] 2023-10-07 12:26:26 -05:00
Jonathan Hefner
3f2987403e Reword queue_adapter_for_test doc [ci-skip] 2023-10-07 12:26:26 -05:00
Jonathan Hefner
ed08eea99f Capitalize framework names [ci-skip] 2023-10-07 12:26:26 -05:00
Rafael Mendonça França
1f0262aa2b
Separate the CI environment from the application CI environment
Right now we are using both to test the Rails applications we generate
and to test Rails itself. Let's keep CI for the app and BUILDKITE to
the framework.
2023-10-04 09:36:51 +00:00
Bart de Water
95b6fbd00f Stop building AS::Notifications::Event manually
It's possible since Rails 6 (3ea2857943dc294d7809930b4cc5b318b9c39577) to let the framework create Event objects, but the guides and docs weren't updated to lead with this example.

Manually instantiating an Event doesn't record CPU time and allocations, I've seen it more than once that people copy-pasting the example code get confused about these stats returning 0. The tests here show that - just like the apps I've worked on - the old pattern keeps getting copy-pasted.
2023-09-29 12:34:23 -04:00
Petrik de Heus
6c9967f85a
Merge pull request #49413 from ghiculescu/document-retry-on
Document hierarchy for `retry_on` and `discard_on`
2023-09-28 07:34:06 +02:00