Commit Graph

745 Commits

Author SHA1 Message Date
Ryuta Kamizono
e50b0e3ab3 Fixup CHANGELOGs [ci skip] 2021-07-21 10:08:08 +09:00
Wojciech Wnętrzak
e2db5f205a
Added possibility to check on :priority in test helper methods 2021-07-15 07:46:21 +02:00
Alex Ghiculescu
4b42beb3b8 Log a warning when assertions are incorrectly nested and errors are raised
Follow up to https://github.com/rails/rails/pull/37313

- Adds regression tests
- Logs a warning in cases where assertions are nested in a way that's likely to be confusing
2021-07-12 10:37:43 -05:00
Dirkjan Bussink
0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02:00
Ashik Salman
6a6c6ca207 Added more regression for activejob Range serializer. 2021-05-18 16:29:34 +05:30
Andrew White
61fb58f6a7
Add Range to list of supported arguments for jobs 2021-05-16 08:44:59 +01:00
Felipe Sateler
5bb5453cd7 Add Range serializer for ActiveJob
Missing Range support means users need to add start/finish pair
of arguments instead of simply passing a Range object.
2021-05-15 23:22:26 -04:00
John Bampton
de3b207aa6 chore: fix grammar and spelling 2021-04-15 16:57:01 +10:00
Rafael Mendonça França
4354e3ae49
Don't define methods using the method modifier in the same line as the method
Our style guide use block method modifiers, not inline method modifiers.
2021-04-12 18:49:54 +00:00
Jean Boussier
3f59640016 Stop checking if ruby2_keywords is defined 2021-04-11 13:42:02 +02:00
Jean Boussier
8a3fcad2d2 Use ... argument forwarding instead of ruby2_keywords when possible 2021-03-19 16:53:06 +01:00
Jonathan Hefner
167f5c8065 Fix inline code markup [ci-skip]
RDoc Markup does not support backticks the way Markdown does to mark up
inline code.  Additionally, `<tt>` must be used to mark up inline code
that includes spaces or certain punctuation characters (e.g. quotes).
2021-02-14 11:20:35 -06:00
Ryuta Kamizono
39e49edaf9 Remove the code for older Rubies RUBY_VERSION < "2.7" in the codebase 2021-02-07 12:20:18 +09:00
Ryuta Kamizono
f8b354bf3b Fix typo s/adapaters/adapters/ [ci skip] 2021-02-07 05:41:07 +09:00
Daniel Morton
ee60ce5606 Communicate enqueue failures to callers of perform_later
There is presently no clean way of telling a caller of `perform_later`
the reason why a job failed to enqueue. When the job is enqueued
successfully, the job object itself is returned, but when the job can
not be enqueued, only `false` is returned. This does not allow callers
to distinguish between classes of failures.

One important class of failures is when the job backend experiences a
network partition when communicating with its underlying datastore. It
is entirely possible for that network partition to recover and as such,
code attempting to enqueue a job may wish to take action to reenqueue
that job after a brief delay. This is distinguished from the class of
failures where due a business rule defined in a callback in the
application, a job fails to enqueue and should not be retried.

This PR changes the following:

- Allows a block to be passed to the `perform_later` method. After the
  `enqueue` method is executed, but before the result is returned, the
  job will be yielded to the block. This allows the code invoking the
  `perform_later` method to inspect the job object, even in failure
  scenarios.

- Adds an exception `EnqueueError` which job adapters can raise if they
  detect a problem specific to their underlying implementation or
  infrastructure during the enqueue process.

- Adds two properties to the job base class: `successfully_enqueued` and
  `enqueue_error`. `enqueue_error` will be populated by the `enqueue`
  method if it rescues an `EnqueueError` raised by the job backend.
  `successfully_enqueued` will be true if the job is not rejected by
  callbacks and does not cause the job backend to raise an
  `EnqueueError` and will be `false` otherwise.

This will allow developers to do something like the following:

    MyJob.perform_later do |job|
      unless job.successfully_enqueued?
        if job.enqueue_error&.message == "Redis was unavailable"
          # invoke some code that will retry the job after a delay
        end
      end
    end
2021-02-05 16:32:43 -05:00
Rafael Mendonça França
1b455e2e9d
Rails 6.2 is now Rails 7.0
We have big plans for the next version of Rails and that
require big versions.
2021-02-04 16:47:16 +00:00
Rafael Mendonça França
6487836af8
Rails 7 requires Ruby 2.7 and prefer Ruby 3+
The code cleanup is comming in later commits but this
already remove support to Ruby < 2.7.
2021-02-04 16:34:53 +00:00
Pedro Chambino
d318af93c5
Add missing require to ActiveJob::TestHelper
Following PR #40780, it now fails after requiring active_job:

    irb(main):001:0> require 'active_job'
    => true
    irb(main):002:0> ActiveJob::VERSION::STRING
    => "6.1.1"
    irb(main):003:0> ActiveJob::TestHelper
    [redacted]
    NameError (uninitialized constant ActiveSupport::Testing)
2021-02-02 11:50:54 +00:00
Rafael Mendonça França
bea721aa91
Merge remote-tracking branch 'origin/main' into skip-logging-rescuable-exceptions 2021-02-02 01:09:06 +00:00
Rafael Mendonça França
efa64bb295
Refactor the code to keep instrumentation and log inside the modules
Use inheritance to keep the behavior in the right modules.

The order of Instrumentation and Logging had to change to be
flipped to keep the current behavior.
2021-02-02 01:07:24 +00:00
Étienne Barrié
142ae54e54 Allow jobs to rescue all exceptions
Before this commit, only StandardError exceptions can be handled by
rescue_from handlers.

This changes the rescue clause to catch all Exception objects, allowing
rescue handlers to be defined for Exception classes not inheriting from
StandardError.

This means that rescue handlers that are rescuing Exceptions outside of
StandardError exceptions may rescue exceptions that were not being
rescued before this change.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2021-01-23 08:35:51 -05:00
Rafael Mendonça França
077c66d5d6
Rename master to main in all code references 2021-01-19 20:46:33 +00:00
Ryuta Kamizono
2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
HU Hailin
b8baeb44ae change the perform instrumentation to wrap perform_now instead of the perform method. 2020-12-31 11:13:03 +09:00
HU Hailin
0c6f32a9f9 Skip logging rescuable exceptions which are defined in rescue_from/retry_on/discard_on.
Update activejob/CHANGELOG.md

Co-authored-by: Rafael França <rafael@franca.dev>
2020-12-31 11:12:58 +09:00
Rafael Mendonça França
68b471c4dd
Make sure job instrumentation keep return value
The implementaiton of `instrument` in `ActiveJob::Instrumentation` was
not keeping the API of `ActiveSupport::Notification.instrument` and
returning the value of the block.

Fixes #40931.
2020-12-28 05:30:30 +00:00
Rafael França
96db850d51
Merge pull request #40780 from mikker/mikker-assert-nothing-raised-fix
Include ActiveSupport::Testing::Assertions in ActiveJob::TestHelpers
2020-12-18 17:12:38 -05: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
Mikkel Malmberg
a9f78ebc16
Whitespace 2020-12-10 11:53:34 +01:00
Mikkel Malmberg
5cb90b1b71
Include ActiveSupport::Testing::Assertions in ActiveJob::TestHelpers
After upgrading to Rails 6.1 I'm getting a `undefined method `assert_nothing_raised'` using `ActiveJob::TestHelpers` and `assert_enqueued_jobs` in RSpec.

Adding this module fixes it, however not knowing the internals too well, I'm unsure whether it's the right fix.
2020-12-10 11:47:17 +01:00
Rafael França
a8f0fcc6ad
Merge pull request #40754 from yahonda/revert_workarounds_for_ruby_17220
Revert 'sleep 1' workarounds since Ruby issue 17220 has been addressed
2020-12-08 13:59:33 -05:00
KapilSachdev
a908d06c85
feat(rubocop): Add Style/RedundantRegexpEscape
- This cop will help in removing unnecessary escaping inside Regexp literals.
2020-12-08 18:57:09 +00:00
Yasuo Honda
aa026ee105 Revert "Work around getaddrinfo deadlock in forked process"
This reverts commit 7cf8e30902119b22c5f9fa1f4d80185ba3f3a5f7.
2020-12-06 23:01:56 +09:00
Yasuo Honda
8ae1738a14 Revert "Merge pull request #40451 from yahonda/sneakers"
This reverts commit 3b9807f3de9d4231cb914946f53f164fbd6d0b7a, reversing
changes made to 7e2d8434ed42d6fbf7f4743d033d50ad92ebe4da.
2020-12-06 23:01:41 +09:00
Yasuo Honda
fa3d47018b Revert "Merge pull request #40453 from yahonda/resque_start_workers"
This reverts commit 1fddc8023ec1e7f65e9b0c299ade1084dc7a3bf4, reversing
changes made to 1f5a4d1d5e68106eaa897e49a874bef24bf4c63c.
2020-12-06 23:01:19 +09:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Rafael Mendonça França
a173a65730
Merge pull request #39472
Closes #39472.
2020-12-01 00:40:52 +00:00
Rafael França
90fa01b4c0
Merge pull request #40626 from jonathanhefner/executor-wrap-db-seeds
Wrap evaluation of db/seeds.rb with the executor
2020-11-24 15:01:22 -05:00
Jonathan Hefner
648da12519 Wrap evaluation of db/seeds.rb with the executor
Before #34953, when using the `:async` Active Job queue adapter, jobs
enqueued in `db/seeds.rb`, such as Active Storage analysis jobs, would
cause a hang (see #34939).  Therefore, #34953 changed all jobs enqueued
in `db/seeds.rb` to use the `:inline` queue adapter instead.  (This
behavior was later limited to only take effect when the `:async` adapter
was configured, see #35905.)  However, inline jobs in `db/seeds.rb`
cleared `CurrentAttributes` values (see #37526).  Therefore, #37568
changed the `:inline` adapter to wrap each job in its own thread, for
isolation.  However, wrapping a job in its own thread affects which
database connection it uses.  Thus inline jobs can no longer execute
within the calling thread's database transaction, including seeing any
uncommitted changes.  Additionally, if the calling thread is not wrapped
with the executor, the inline job thread (which is wrapped with the
executor) can deadlock on the load interlock.  And when testing (with
`connection_pool.lock_thread = true`), the inline job thread can
deadlock on one of the locks added by #28083.

Therefore, this commit reverts the solutions of #34953 and #37568, and
instead wraps evaluation of `db/seeds.rb` with the executor.  This
eliminates the original hang from #34939, which was also due to running
multiple threads and not wrapping all of them with the executor.  And,
because nested calls to `executor.wrap` are ignored, any inline jobs in
`db/seeds.rb` will not clear `CurrentAttributes` values.

Alternative fix for #34939.
Reverts #34953.
Reverts #35905.
Partially reverts #35896.

Alternative fix for #37526.
Reverts #37568.

Fixes #40552.
2020-11-18 16:26:20 -06:00
Eugene Kenny
65d7aa5811 Reset Time.zone to avoid leaking into other tests
https://buildkite.com/rails/rails/builds/72478#93358e11-6e26-4588-a791-26f9512157c2/1074-1087
https://buildkite.com/rails/rails/builds/72747#10657eba-2359-47ca-9914-49a48b3f2d3c/967-976
https://buildkite.com/rails/rails/builds/72795#3f4bff27-3f42-4678-b643-08cc811c8954/999-1012
2020-11-15 01:02:22 +00:00
Ryuta Kamizono
53331b478d Fix typos [ci skip] 2020-11-09 15:23:39 +09:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Rafael França
45a1bcea9b
Merge pull request #39532 from vipulnsward/fix-tz-perform-now
Set timezone on a Job initialization to make it conform more with perform_later when doing JobClass.perform_now
2020-10-30 16:42:29 -04:00
Guo Xiang Tan
bda10bf3a8
Recover precision when serializing Time, TimeWithZone and DateTime. 2020-10-30 19:58:13 +00:00
Rafael Mendonça França
fd24cf1c5d
Return false when enqueuing a job is aborted 2020-10-30 00:25:31 +00:00
Yasuo Honda
a0561d746d Workaround Active Job integration test with resque against ruby 3.0.0dev
This pull request workarounds Active Job integration test with `resque` reported at https://buildkite.com/rails/rails/builds/72277#410533b8-0676-4ad2-900f-fa8131f9833f/1826
This fix is similar to 7cf8e30 and rails/rails#40451 which is due to https://bugs.ruby-lang.org/issues/17220

- Steps to reproduce

```
- Install Docker
$ git clone https://github.com/rails/rails
$ cd rails
$ git clone https://github.com/rails/buildkite-config .buildkite/
$ RUBY_IMAGE=rubylang/ruby:master-nightly-bionic docker-compose -f .buildkite/docker-compose.yml build base && CI=1 docker-compose -f .buildkite/docker-compose.yml run activejob runner activejob 'AJ_ADAPTER=resque AJ_INTEGRATION_TESTS=true bin/test test/integration/queuing_test.rb  --seed 36344'
```

- Without this commit

```
$ RUBY_IMAGE=rubylang/ruby:master-nightly-bionic docker-compose -f .buildkite/docker-compose.yml build base && CI=1 docker-compose -f .buildkite/docker-compose.yml run activejob runner activejob 'AJ_ADAPTER=resque AJ_INTEGRATION_TESTS=true bin/test test/integration/queuing_test.rb  --seed 36344'
... snip ...
+++ activejob: AJ_ADAPTER=resque AJ_INTEGRATION_TESTS=true bin/test test/integration/queuing_test.rb  --seed 36344
Using resque
/usr/local/lib/ruby/gems/3.0.0/gems/resque-scheduler-4.4.0/lib/resque/scheduler/lock/base.rb:50: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
Run options: --seed 36344

.F

Failure:
QueuingTest#test_should_run_jobs_enqueued_on_a_listening_queue [/rails/activejob/test/integration/queuing_test.rb:14]:
Expected false to be truthy.

bin/test test/integration/queuing_test.rb:11

F

Failure:
QueuingTest#test_current_timezone_is_kept_while_running_perform_later [/rails/activejob/test/integration/queuing_test.rb:119]:
Expected false to be truthy.

bin/test test/integration/queuing_test.rb:110

.SSF

Failure:
QueuingTest#test_current_locale_is_kept_while_running_perform_later [/rails/activejob/test/integration/queuing_test.rb:102]:
Expected false to be truthy.

bin/test test/integration/queuing_test.rb:93

.F

Failure:
QueuingTest#test_should_run_job_enqueued_in_the_future_at_the_specified_time [/rails/activejob/test/integration/queuing_test.rb:76]:
Expected false to be truthy.

bin/test test/integration/queuing_test.rb:71

SSSSSS

Finished in 34.122641s, 0.4396 runs/s, 0.2344 assertions/s.
15 runs, 8 assertions, 4 failures, 0 errors, 8 skips

You have skipped tests. Run with --verbose for details.
$
```

- With this commit

```ruby
$ RUBY_IMAGE=rubylang/ruby:master-nightly-bionic docker-compose -f .buildkite/docker-compose.yml build base && CI=1 docker-compose -f .buildkite/docker-compose.yml run activejob runner activejob 'AJ_ADAPTER=resque AJ_INTEGRATION_TESTS=true bin/test test/integration/queuing_test.rb  --seed 36344'
... snip ...
+++ activejob: AJ_ADAPTER=resque AJ_INTEGRATION_TESTS=true bin/test test/integration/queuing_test.rb  --seed 36344
Using resque
/usr/local/lib/ruby/gems/3.0.0/gems/resque-scheduler-4.4.0/lib/resque/scheduler/lock/base.rb:50: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
Run options: --seed 36344

....SS...SSSSSS

Finished in 13.850658s, 1.0830 runs/s, 0.7220 assertions/s.
15 runs, 10 assertions, 0 failures, 0 errors, 8 skips

You have skipped tests. Run with --verbose for details.
$
```
2020-10-25 23:50:55 +09:00
Yasuo Honda
9f4818c55f Address Active Job integration test with sneakers against ruby 3.0.0dev
This pull request addresses Active Job integration test with `sneakers` reported at https://buildkite.com/rails/rails/builds/72257#20014e66-6e08-47ae-a827-b71de7148306/2017
This fix is similar to 7cf8e30902 which is due to https://bugs.ruby-lang.org/issues/17220

- Steps to reproduce
Install ruby 3.0.0dev using ruby-build or whatever then execute these steps.

```ruby
$ git clone https://github.com/rails/rails
$ cd rails/activejob
$ bundle install
$ bundle exec rake test:integration:sneakers
```

- Result without this commit

```ruby
$ ruby -v
ruby 3.0.0dev (2020-10-24T13:53:53Z master 148961adcd) [x86_64-linux]
$ cd activejob
$ bundle exec rake test:integration:sneakers
... snip ...
/home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/adapters/sneakers.rb:49:in `rescue in start_workers': Failed to start sneakers worker (RuntimeError)
	from /home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/adapters/sneakers.rb:41:in `start_workers'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/helper.rb:27:in `<top (required)>'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/helper.rb:12:in `require'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/helper.rb:12:in `<top (required)>'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/integration/queuing_test.rb:3:in `require'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/integration/queuing_test.rb:3:in `<top (required)>'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:17:in `require'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `select'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `<main>'
/home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/adapters/sneakers.rb:44:in `sleep': execution expired (Timeout::Error)
	from /home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/adapters/sneakers.rb:44:in `block in start_workers'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/3.0.0/timeout.rb:112:in `timeout'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/adapters/sneakers.rb:42:in `start_workers'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/support/integration/helper.rb:27:in `<top (required)>'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/helper.rb:12:in `require'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/helper.rb:12:in `<top (required)>'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/integration/queuing_test.rb:3:in `require'
	from /home/yahonda/src/github.com/rails/rails/activejob/test/integration/queuing_test.rb:3:in `<top (required)>'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:17:in `require'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `select'
	from /home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `<main>'
rake aborted!
Command failed with status (1): [ruby -w -I"lib:test" -I"/home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib" "/home/yahonda/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb" "test/integration/queuing_test.rb" ]
/home/yahonda/.rbenv/versions/3.0.0-dev/bin/bundle:23:in `load'
/home/yahonda/.rbenv/versions/3.0.0-dev/bin/bundle:23:in `<main>'
Tasks: TOP => test:integration:sneakers
(See full trace by running task with --trace)
$
```

- Result with this commit

```ruby
$ bundle exec rake test:integration:sneakers
... snip ...
15 runs, 6 assertions, 0 failures, 0 errors, 11 skips
```
2020-10-25 15:13:38 +09:00
Eugene Kenny
7cf8e30902 Work around getaddrinfo deadlock in forked process
See https://bugs.ruby-lang.org/issues/17220.

This will prevent every CI run from getting stuck and eventually timing
out after 30 minutes.
2020-10-16 01:00:12 +01:00
Akira Matsuda
09939f8657 Given method here (e.g. perform) should be public_sendable 2020-10-07 20:55:59 +09: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