Commit Graph

39 Commits

Author SHA1 Message Date
fatkodima
f6d56fed27 Add support for logging background job enqueue callers 2023-04-02 03:23:42 +03: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
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
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
Ben Sheldon
8fceabd1e8 Defer constant loading of ActiveRecord::DestroyAssociationAsyncJob via a String instead of a class constant
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-13 11:58:20 -05:00
Nick Holden
edf4ef9b26 Fix config.active_record.destroy_association_async_job configuration
`config.active_record.destroy_association_async_job` should allow applications
to specify the job that will be used to destroy associated records in the
background for `has_many` associations with the `dependent: :destroy_async`
option. That's being ignored, which means the default
`ActiveRecord::DestroyAssociationAsyncJob` always destroys records in the
background. This change stops ignoring the configuration.
2022-02-16 10:42:25 -07:00
Jean Boussier
6bad959565 Extract ActiveSupport::ExecutionContext out of ActiveRecord::QueryLogs
I'm working on a standardized error reporting interface
(https://github.com/rails/rails/issues/43472) and it has the same need
for a `context` than Active Record's query logs.

Just like query logs, when reporting an error you want to know what the
current controller or job is, etc.

So by extracting it we can allow both API to use the same store.
2021-11-10 09:36:02 +01:00
Jean Boussier
51c45d334c Refactor ActiveRecord::QueryLogs context API
This remove the null object as discussed in
8af78700d2.
Since it pretends to be nil but acts as thruthy in boolean context
it cause more confusion than it clean code.

`update_context` is removed in favor of `set_context` without
a block.
2021-10-26 09:55:33 +02:00
Jean Boussier
af87199a80 Handle NullObject instances in Active Job query tag 2021-08-24 15:07:20 +02:00
Jean Boussier
b9635ccc05 Pass ActiveRecord::QueryLogs as argument rather than instance_exec
Otherwise we expose all the interal state of `QueryLogs` as an API.

It also makes the API more friendly to typing frameworks.
2021-08-23 20:29:45 +02:00
Rafael Mendonça França
614fc3d827
Delay the exclusion of the configs to the last minute
The framework still rely on the configuration object being modified
in initializers, so we need to delay the exclusion to the last minute.
2021-08-18 00:04:25 +00:00
Rafael Mendonça França
ac77ab469f
Only try to configure the query log tags if Active Record is present 2021-08-17 23:35:47 +00:00
Rafael Mendonça França
a6aa9376f1
Stop relying on mutating the configuration object 2021-08-17 23:35:46 +00:00
Rafael Mendonça França
8af78700d2
Improve taggings API by introducing a null object
Instead of adding chains of `&.` we should use a null object to allow
the taggings definition to be more concise.
2021-08-17 23:35:44 +00:00
Rafael Mendonça França
18cd634e07
Fix initialization proccess of the query tags
The tags were being added in the wrong way, now it is always using the
configuration.
2021-08-17 22:59:44 +00:00
Rafael Mendonça França
6d983e86da
Remove more unneeded methods that should be configs 2021-08-17 22:35:22 +00:00
Rafael Mendonça França
3597afc605
Avoid using class_eval and just include a module 2021-08-17 22:16:06 +00:00
Rafael Mendonça França
e214f25463
Do not change the framework if all we want are configs
The value of the configs in the base classes were not being used in
the code. We only needed configs, so we can just use that.
2021-08-17 22:13:00 +00:00
Keeran Raj Hawoldar
2408615154 Add QueryLogTags to Rails
Co-authored-by: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2021-08-09 15:21:08 +01:00
George Claghorn
c89632abf0 Revert "Merge pull request #39472"
This change broke config.active_job.queue_name_prefix with eager-loading enabled (i.e. in production, by default).

This reverts commit a173a657309f03016f24b7a3d8a24c846e5ab331, reversing
changes made to 89414f561a672e98d8d6deda39d358fc6e0c0386.
2020-12-17 19:27:14 -05:00
Rafael Mendonça França
a173a65730
Merge pull request #39472
Closes #39472.
2020-12-01 00:40:52 +00:00
George Claghorn
4cf7559280 Destroy associations in a background job.
Sometimes cascading association deletions can cause timeouts due to
an IO issue. Perhaps a model has associations that are destroyed on
deletion which in turn trigger other deletions and this can continue
down a complex tree. Along this tree you may also hit other IO
operations. Such deep deletions can lead to server timeouts while
awaiting completion and really the user may not notice all the
changes on their side immediately making them wait unnecesarially or
worse causing a timeout during the operation.

We now allow associations supporting the `dependent:` key to take `:destroy_async`,
which schedules a background job to destroy associations.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
Co-authored-by: Cory Gwin @gwincr11 <gwincr11@github.com>
2020-09-24 14:24:15 -04:00
fatkodima
2156226e6e Do not swallow unknown configuration options for ActiveJob 2020-05-29 17:48:51 +03:00
Ricardo Díaz
64a9759aff Include test helpers when ActionDispatch::IntegrationTest is loaded
As @dhh brings up, the point of `ActionDispatch::IntegrationTest` is to
allow users to test the integration of all the pieces called by a
controller. Asserting about the emails and jobs queued is part of that
task.

This commit includes the `ActionMailer::TestHelper` and
`ActiveJob::TestHelper` modules when the ActionMailer and ActiveJob
railties are initialized respectively.
2018-09-12 16:58:14 -05:00
Yuji Yaginuma
3cc93de6ad Fix custome serializer setting
The serializer should be set up in `after_initialize` so that it work
properly even if the user specifies serializer with initializers.

Also, since `custom_serializers` is `Array`, it needs to be flattened
before setting the value.
2018-02-16 14:56:05 +09:00
Rafael Mendonça França
a5f7357a3d Add configuration to set custom serializers 2018-02-14 13:10:08 -05:00
Koichi ITO
aa28c5ca65 [Active Job] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
14ece5e429 Use frozen-string-literal in ActiveJob 2017-07-09 20:50:52 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Xavier Noria
93c9534c98 applies new string literal convention in activejob/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:40:07 +02:00
Matthew Draper
5bdeb9bfd7 Use AS::Reloader to support reloading in ActiveJob 2016-03-02 02:14:54 +10:30
David Heinemeier Hansson
439fadf758 Missed a few spots in inline -> async switch 2016-02-05 16:05:48 +01:00
Abdelkader Boudih
080296be61 [ActiveJob] require global_id/railtie 2014-08-17 23:17:38 +00:00
Cristian Bica
94ae25ecd5 ActiveJob: Reworked queue_base_name as default_queue_name + Allow configure ActiveJob from app.config.active_job 2014-08-15 23:32:08 +03:00
Cristian Bica
3ed69cd5f5 Fixed failing tests; Load active_job in railtie; Renamed generator to job 2014-08-12 13:53:46 +03:00
Abdelkader Boudih
a75f085941 Add 'activejob/' from commit '14f74a8331f94150dfee653224de8fc837797709'
git-subtree-dir: activejob
git-subtree-mainline: b45b99894a60eda434abec94d133a1cfd8de2dda
git-subtree-split: 14f74a8331f94150dfee653224de8fc837797709
2014-08-12 09:17:19 +00:00