Commit Graph

900 Commits

Author SHA1 Message Date
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
Petrik de Heus
a7041d3138
Merge pull request #49394 from johanstenberg92/fix-method-documentation-for-attempts-retry-on [ci skip]
Adjust method documentation for `ActiveJob::Exceptions::ClassMethods#retry_on`
2023-09-28 07:28:35 +02:00
Alex
bb8d6c9349 Document hierarchy for retry_on and discard_on
Fixes https://github.com/rails/rails/issues/49406
2023-09-28 15:00:29 +10:00
Rafael Mendonça França
32eba97a08
Make sure scheduled_at is a Time object when asserting enqueued jobs
When the `:at` attribute is sent to the test adapter it is converted
to a float, and that float is what is added to the payload, so we
need to convert back to a Time object.

See:
8a37276416/activejob/lib/active_job/enqueuing.rb (L95)
8a37276416/activejob/lib/active_job/queue_adapters/test_adapter.rb (L34)
2023-09-27 15:29:11 +00:00
fatkodima
7ef86b6a49 Enable Lint/RedundantSafeNavigation rubocop cop 2023-09-27 14:55:07 +03:00
Johan Stenberg
9ea1e7aa78
Update activejob/lib/active_job/exceptions.rb
Co-authored-by: Alex Ghiculescu <alex@tanda.co>
2023-09-27 08:37:12 +02:00
Rafael Mendonça França
fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França
e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
Ben Sheldon [he/him]
c919b474a7
Set, serialize, and deserialize Active Job scheduled_at as Time; deserialize enqueued_at as Time; deprecate setting scheduled_at= with numeric/epoch
Co-authored-by: Adam Pahlevi <adam.pahlevi@gmail.com>
2023-09-26 17:01:41 -07:00
Johan Stenberg
09889cd4f0 Adjust method documentation for ActiveJob::Exceptions::ClassMethods#retry_on. The argument does take the initial job execution attempt into account, this is not reflected in the method documentation. 2023-09-26 20:07:18 +02:00
Victor Mours
1bdabc1102 Clarify that the default retry strategy uses polynomial backoff and not exponential backoff 2023-09-16 00:51:14 +02:00
Shouichi Kamiya
7ff936570b Add tests for AJ events
Because events are documented but not tested.
2023-09-14 16:05:26 +09:00
Shouichi Kamiya
51ac8b9f6f Enable Minitest/LiteralAsActualArgument
There are assertions that expected/actual arguments are passed in the
reversed order by mistake. Enabling the LiteralAsActualArgument rule
prevents this mistake from happening.

The existing tests were auto-corrected by rubocop with a bit of
indentation adjustment.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-09-13 10:09:32 +09:00
Rafael Mendonça França
699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Akhil G Krishnan
61a9c1a92a Ruby code block indentation issue fix
[skip ci] indentation fix

[skip ci] review changes added

[skip ci] indentation fix
2023-09-07 01:14:48 +05:30
Ben Sheldon
b1b7debaa3
Fix Active Job log message to correctly report a job failed to enqueue when the adapter raises an ActiveJob::EnqueueError 2023-09-02 07:52:43 -07:00
Adrianna Chang
27c5c7cd99
Merge pull request #48920 from fidalgo/fidalgo/update-assert_enqueued_with-documentation
[docs] Update assert_enqueued_with documentation with keyword arguments example
2023-08-29 10:36:22 -04:00
Rafael Mendonça França
53a3a95d01
Merge PR #48010 2023-08-21 17:39:03 +00:00
Hartley McGuire
ff6e885d59
Remove uneeded requires of core_ext/string/filters
`actionpack/lib/action_dispatch/routing.rb`
- added: 013745151be062aa4d0fc1f2a008a7303fdb6e04
- removed: 93034ad7fea7e00562103a7cd0acfab19bbfadf9

`activejob/lib/active_job/log_subscriber.rb`
- added: b314ab555e0d85e6efb41be94fb5f3a157bb12fe
- removed: 5ab2034730feacfc2caee418f8c0b55191d27427

`activemodel/lib/active_model/errors.rb`
- added: cf7fac7e29bb2816412c949fdaed3d61a923eb23
- removed: 9de6457ab0767ebab7f2c8bc583420fda072e2bd

`activerecord/lib/active_record/core.rb`
- added: b3bfa361c503e107aff4dee5edf79bd7fd3d3725
- removed: e1066f450d1a99c9a0b4d786b202e2ca82a4c3b3

`activesupport/lib/active_support/core_ext/module/introspection.rb`
- added: 358ac36edf1695fcbec0aa21f126a3d8b83d4b5a
- removed: 167b4153cac0069a21e0bb9689cb16f34f6abbaa

`activesupport/lib/active_support/duration.rb`
- added: 75924c4517c8f87712d3f59c11f10152ed57b9d8
- removed: a91ea1d51048342d13fc73f9b09ce4cfd086bb34

`railties/lib/rails/commands/server/server_command.rb`
- added: f2173648938b418d120f5a68d8f3862d8ae9dace
- removed: 553b86fc751c751db504bcbe2d033eb2bb5b6a0b

`railties/lib/rails/command/base.rb`
- added: 6813edc7d926965e5644cd8befaf229a35b9d8ca
- removed: b617a561d865a65cfc140caa0e3c4af4350bfcef
2023-08-16 17:39:25 -04:00
Jonathan del Strother
074d431493
Fix invalid durations in ActiveJob serialization
Durations that were round-tripped through ActiveJob::Arguments.serialize
would appear fine at a first glance, but trying to perform
duration-math on them would fail:

```
irb(main):001:0> d = ActiveJob::Arguments.deserialize(ActiveJob::Arguments.serialize([1.year]))[0]
=> 1 year
irb(main):002:0> d + 1.day
activesupport-6.1.4.4/lib/active_support/duration.rb:242:in `+': undefined method `merge' for [[:years, 1]]:Array (NoMethodError)
```
2023-08-13 11:27:16 +01:00
Paulo Fidalgo
9dbac2cedc
Update assert_enqueued_with documentation with keyword arguments example
This commit adds an example to the `assert_enqueued_with` method documentation,
demonstrating how to use it with keyword arguments.
The example clarifies that keyword arguments should be specified as a hash inside an array,
providing guidance for developers writing tests for jobs that use keyword arguments.
2023-08-11 09:54:59 +02:00
Yasuo Honda
d867313fbc
Merge pull request #48626 from ghiculescu/active-job-async-test
Active Job: `async` adapter should always run jobs immediately if `immediate` set
2023-07-03 09:37:56 +09:00
Alex Ghiculescu
639dab59dc Active Job: async adapter should always run jobs immediately if immediate set
This is an internal fix, not user facing. I noticed it while working on https://github.com/rails/rails/pull/48585.

The `async` adapter has an `immediate` option, which should only be used in tests. This option should tell the adapter to run jobs inline. This works correctly with `perform_later`, but it does not work with `enqueue_at`, which is what other internal mechanisms such as `retry_job` use.

This PR fixes this bug.
2023-07-03 09:02:51 +10:00
Alex Ghiculescu
2385b6e4e5 Fix incorrect arguments for Active Job test job
This is an internal fix, not user facing.

Currently the `LoggingJob` does not accept more than one argument. But there's [a few tests](f46d3452ae/activejob/test/cases/test_helper_test.rb (L518-L537)) that call it with multiple arguments and assert that it is queued correctly. Those tests pass because the job is not performed, but if the job was performed, they'd fail.

This PR just fixes `LoggingJob` to accept a splat of arguments, and adds a test to ensure that it works correctly.
2023-07-02 16:25:09 +10:00
Alex Ghiculescu
ba70a5be86 Make perform_enqueued_jobs compatible with all Active Job adapters 2023-06-28 20:08:08 +10:00
Vipul A M
5c5b78dfa7
Fix a few typos in changelogs [ci skip] (#48573) 2023-06-25 14:56:20 +05:30
Alex Baldwin
719e49485f Fix error ActiveJob passed class with permitted?
Resolves #48561
Co-authored-by: Sampat Badhe <sampatbadhe@gmail.com>
2023-06-23 10:51:46 -04:00
zzak
dd89f600f7
🔗 Remove RDoc auto-link from Rails module everywhere 2023-06-23 10:49:30 +09:00
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
Rob Cardy
659d41110f
This method lets job authors define a block which will be run when a job is about to be discarded.
This has utility for gems/modules included on jobs, which can tie into this behaviour and run something when a job fails.
after_discard respects the existing retry behaviour, but will run even if a retried exception is handled in a block.
2023-05-08 14:28:42 -04: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