Commit Graph

421 Commits

Author SHA1 Message Date
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
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
Vipul A M
4432d471b8 Set timezone on a Job initialization to make it conform more with perform_later when doing JobClass.perform_now.
Fixes #39529
2020-06-04 09:53:42 +05:30
Jonathan Hefner
b16c38ab6a Support procs for assert_{enqueued,performed}_with
PR #33995 added support for specifying the `args` argument of
`assert_enqueued_with` and `assert_performed_with` as a matcher proc.
In doing so, it added undocumented support for specifying the other
arguments as matcher procs as well.  This commit officially documents
that support, and adds tests to ensure the behavior.
2020-05-07 15:36:41 -05:00
Rafael Mendonça França
684db54462
Add back the support to pass at as a proc in the job assertions 2020-05-01 12:22:57 -04:00
Étienne Barrié
f123e5e40a Fix perform_enqueued_jobs without a block with other helpers
assert_enqueued_with with a block ignores all the jobs enqueued before
the block for its assertions by counting the number of jobs and dropping
the n first elements from the Array, but since we're now mutating the
Array in perform_enqueued_jobs without a block, it's broken.

This uses another implementation which is correct when the array is
mutated, by getting a duplicated array of jobs, then removing them from
the original array.

Similarly assert_enqueued_jobs with a block was using counts only, now
keeps track of the specific jobs to count them at the end.
2020-04-13 13:13:38 -04:00
Rafael Mendonça França
d16396e1ce
Merge pull request #38605 from dmitry/issue-38584
While using perform_enqueued_jobs enqueued jobs must be stored as well
2020-04-08 17:21:57 -04:00
Jonathan Hefner
056b252010 Fix random CI fail due to auto-updating timestamp
Example failure: https://buildkite.com/rails/rails/builds/68074#0fe7ca54-fcce-4a47-85db-a784275c8f51/1115-1125

Each time a job is serialized, `enqueued_at` is updated.  Thus, separate
serializations of the same job can have different `enqueued_at`
timestamps if the serializations do not occur within the same second.
2020-04-06 23:31:29 -05:00
Étienne Barrié
c6d621d132 Remove jobs from queue when performing in tests
This makes sure jobs don't run twice if `perform_enqueued_jobs` is
called twice without a block.

This also mimics the behavior of using `perform_enqueued_jobs` with a
block, where at the end of the block performed jobs are not in
`enqueued_jobs` but instead in `performed_jobs`.
2020-03-16 15:09:33 -04:00
Étienne Barrié
78aa157d79 Add assertions to show test was mistaken 2020-03-16 14:09:34 -04:00
utilum
06dcc3c927 Fix warning: method redefined 2020-03-13 18:19:14 +01:00
Edouard CHIN
17e304def8 AJ perform_enqueued_jobs shouldn't perform job retries:
- ### Problem

  If we use `perform_enqueued_jobs` without a block, a job that
  uses a retry mechanism to reeenqueue itself would get performed
  right away.
  This behaviour make sense when using `perform_enqueued_jobs` with
  a block.

  However I'm expecting `perform_enqueued_jobs` without a block to
  perform jobs that are **already** in the queue not the ones that
  will get enqueued afterwards.

  ### Solution

  Dup the array of jobs given to avoid future mutation.
2020-03-09 19:46:11 -04:00
Edouard CHIN
13cb5b78a8 Fix AJ TestAdapter#performed_jobs not properly counting job:
- ### Problem

  If we use `perform_enqueued_jobs` without a block,
  a job that raises an error wouldn't be appended to
  the list of `performed_jobs`.

  ### Solution

  Push the job in the array before it is actually performed.
2020-03-09 19:46:11 -04:00
Aditya Narsapurkar
3aacd855cd parent 6d0895a4894724e1a923a514daad8fb3c9ac2c28
author Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1582316102 +0530
committer Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1583159505 +0530

parent 6d0895a4894724e1a923a514daad8fb3c9ac2c28
author Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1582316102 +0530
committer Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1583159327 +0530

Randomize jitter
- This PR attempts to fix a problem with ActiveJob jitter where the `determine_jitter_for_delay` value may not always be randomized. Especially when the jitter delay multplier is between 1 and 2 it always returns 0.
- With this change, we pass a range to `Kernel.rand` beginning with 0 to the `jitter_multiplier`. With positive float values, the return value will be a random float number from the range.
- Includes test cases to verify random wait time when the jitter_multiplier is between 1 and 2.
- Updated relevant test cases stubbing the `Kernel.rand` method, refactored some by removing unwanted stubs for `Kernel.rand` method where jitter is falsey.

Fixed rubocop issue - used assert_not_equal instead of refute_equal in test case

Fixed rubocop issue - used assert_not_equal instead of refute_equal in test case

Fixed rubocop issue - used assert_not_equal instead of refute_equal in test case

Review updates - separated test cases for random wait time with default and exponentially retrying jobs
- Another test case added to make sure negative wait time does not affect the randomization

Review updates
- Instead of using Kernel.rand with range, used simple multiplication with Kernel.rand for calculating delay for jitter
- Updates to the tests according to changes
2020-03-05 07:45:33 -08:00
Wojciech Wnętrzak
d12a31b193
Add support for que name to Que adapter.
Co-authored-by: Brad Nauta <bradnauta@gmail.com>
2020-03-04 13:50:13 +01:00
Edouard CHIN
0cdeee428e Fix AJ wrong deprecation message on after_callbacks_if_terminated:
- ### Problem

  In some cirumstances, the deprecation message to warn that AJ won't
  run `after_(enqueue/perform)` callbacks when the chain is halted
  by a `throw(:abort)` will be thrown even though no `throw(:abort)`
  was thrown.

  ```ruby
    run_callback(:foo) do
      ...
    end
  ```

  There is two possible way for the callback body to not be executed:

  1) `before` callback throw a `abort`
  2) `before` callback raises an error which is rescued by an
     around callback (See associated test in this commit for
     an example)

  When 2) happen we don't want to output a deprecation message,
  because what the message says isn't true and doesn't apply.

  ### Solution

  In order to differentiate between 1) and 2), I have added
  a `halted_callback_hook` which is called by ActiveSupport callback
  whenever the callback chain is halted.
2020-03-03 16:17:55 -04:00
dmitry
7e6e6eb56f While using perform_enqueued_jobs enqueued jobs must be stored as well #38584 2020-02-28 13:32:06 +01:00
Edouard CHIN
d35cf4c05d Fix ActiveJob Test adapter not respecting retry attempts:
- ### Problem

  Given the below example the test adapter will retry the job
  indefinitely:

  ```ruby
    class BuggyJob < ActiveJob::Base
      retry_on(Exception,  attempts: 2)

      def perform
        raise "error"
      end
    end

    BuggyJob.perform_later
    perform_enqueued_jobs
  ```

  The problem is that when the job get retried, the
  `exception_executions` variable is not serialized/deserialized,
  resulting in ActiveJob to not be able to determine how many time
  this job was retried.

  The solution in this PR is to deserialize the whole job in the test
  adapter, and reserialize it before retrying.

  Fix #38391
2020-02-10 17:59:20 -04:00
Ryuta Kamizono
fc67857596 Fix keyword arguments warnings in Active Job
Related #38053, #38187, #38105, #38260.

This is a reattempt to fix keyword arguments warnings in Active Job.

Now Ruby (master) has `Hash.ruby2_keywords_hash{?,}` and that will be
backported to 2.7.1.

https://github.com/ruby/ruby/pull/2818
https://bugs.ruby-lang.org/issues/16486

I've emulated that for 2.7.0 and older versions.
2020-01-21 05:53:23 +09:00
Ryuta Kamizono
99f18b618b Revert "Merge pull request #38260 from kamipo/fix_kwargs_warning_for_activejob"
This reverts commit 80e72c5eb7d4f79cc8eaa63237e5a60dff48f4f4, reversing
changes made to 0dad1e3e770273631e5ab454d2d3003d90060e17.
2020-01-21 05:26:44 +09:00
Ryuta Kamizono
950b39482d Fix keyword arguments warnings in Active Job
Related #38053, #38187, #38105.

This is a reattempt to fix keyword arguments warnings in Active Job.

Now Ruby (master) has `Hash.ruby2_keywords_hash{?,}` and that will be
backported to 2.7.1.

https://github.com/ruby/ruby/pull/2818
https://bugs.ruby-lang.org/issues/16486

I've emulated that for 2.7.0 and older versions.
2020-01-19 12:09:54 +09:00
Edouard CHIN
ca61139fae Fix wrong logging message in AJ in case a job returns a falsey value:
- I made a change in 0d3aec49695 to output a log if a job was aborted
  in a before callbacks. I didn't take in consideration that a job
  could return a falsy value and thus it would wrongly log
  that the job was aborted.

  This fixes the problem by checking if the callback chain was halted
  rather than the return value of the job.
2020-01-03 17:14:56 +01:00
Edouard CHIN
2cd05dda2b Fix regression where AJ#perform_now doesn't return the job's value:
- Fix #38040
2020-01-03 17:14:56 +01:00
Edouard CHIN
be60970be7 Set AJ return_false_on_aborted_enqueue true in the test suite:
- Since this is going to be the default in 6.1, let's set it in the
  test suite to avoid deprecation warning.
  Otherwise one has to do `AS::Deprecation.silence { }` everytime we
  add a new test.

  Fix #38107
2019-12-28 16:56:54 +01:00
Cliff Pruitt
db0bc5e6d5 Disable ActiveJob retry jitter when given zero/falsey value (#38003)
* Add failing ActiveJob exceptions test for "disable retry jitter"

Thanks to @kaspth for the starting point.

* Update ActiveJob retry jitter to correctly use zero value

* Simplify "disable retry jitter" test

We don't need to repeat this many times. Fewer is shorter.

* Refactor determine_delay with jitter

* Fix indentation

* Close the curtains and give JITTER_DEFAULT some privacy

* Use .zero? instead of == to check jitter value

* Add ActiveJob test for explicit zero jitter

Co-authored-by: Kasper Timm Hansen <hey@kaspth.com>
Co-authored-by: Cliff Pruitt <cliff.pruitt@cliffpruitt.com>
2019-12-17 15:23:52 -03:00
Kasper Timm Hansen
d258bfe8ac
Consolidate and give context to after callback deprecation
The existing message only mentioned one type of before/after callback,
but the config was named generally. That mismatch is confusing and users
wouldn't necessarily know what the total effect of the config would be.

So instead of handwriting the deprecation warning in the specific instances,
consolidate it in one place and give the appropriate context. That context
is the above, but also that users shouldn't update their app config,
they should uncomment the line in the new defaults file, which now also
has more context.

I'm not totally convinced that we can't move this to when
`after_enqueue`/`after_perform` is called in the job class. Doesn't
seem worth it to blare this after every job enqueue/perform, when we
the score at boot time.

cc @Edouard-chin
2019-12-15 03:20:07 +01:00
Edouard CHIN
9eb4b4ed01 Fix deprecation being thrown at boot time:
-
  ### Problem

  In rails/rails@bbfab0b33a I introduced a change which outputs
  a deprecation whenever a class inherits from ActiveJob::Base.

  This has the negative effect to trigger a massive amount of
  deprecation at boot time especially if your app is eagerloaded
  (like it's usually the case on CI).

  Another issue with this approach was that the deprecation will
  be output no matter if a job define a `after_perform` callbacks
  i.e.
  ```ruby
    class MyJob < AJ::Base
      before_enqueue { throw(:abort) }
    end

    # This shouldn't trigger a deprecation since no after callbacks are defined
    # The change in 6.2 will be already safe for the app.
  ```

  ### Solution

  Trigger the deprecation only when a job is abort
  (during enqueuing or performing) AND a `after_perform`
  callback is defined on the job.
2019-12-13 03:25:03 +01:00
Kasper Timm Hansen
5ded839cfb
Strip default_ prefix from retry_jitter config to match conventions 2019-12-13 01:42:58 +01:00
Cliff Pruitt
e2cdffce3d Add config option for ActiveJob::Base.default_retry_jitter 2019-12-10 12:11:46 -05:00
Edouard CHIN
bbfab0b33a Don't run AJ after_enqueue / after_perform when chain is halted:
- ### Problem

  ```ruby
    MyJob < ApplicationJob
      before_enqueue { throw(:abort) }
      after_enqueue { # enters here }
    end
  ```
  I find AJ behaviour on after_enqueue and after_perform callbacks
  weird as they get run even when the callback chain is halted.
  It's counter intuitive to run the after_enqueue callbacks even
  though the job wasn't event enqueued.

  ### Solution

  In Rails 6.2, I propose to make the new behaviour the default
  and stop running after callbacks when the chain is halted.
  For application that wants this behaviour now or in 6.1
  they can do so by adding the `config.active_job.skip_after_callbacks_if_terminated = true`
  in their configuration file.
2019-12-09 17:17:23 +01:00
Edouard CHIN
0d3aec4969 Fix ActiveJob logging when callback chain is halted:
- ### Problem

  ActiveJob will always log "Enqueued MyJob (Job ID) ..." even
  if the job doesn't get enqueued through the adapter.
  Same problem happens when performing a Job, "Performed MyJob (Job ID) ..." will be logged even when job wasn't performed at all.
  This situation can happen either if the callback chain is terminated
  (before_enqueue throwing an `abort`) or if an exception is raised.

  ### Solution

  Check if the callback chain is aborted/exception is raised, and  log accordingly.
2019-12-09 16:17:55 +01:00
Anthony Ross
5f7621878d Add jitter to :exponentially_longer
Prior to this change, exponentially_longer had adverse consequences
during system-wide downstream failures.  This change adds a random value to the
back off calculation in order to prevent the thundering herd
problem, whereby all retry jobs would retry at the same time.

Specifically this change adds a jitter option to retry_on to enable users of it to
scope the randomness calculation to a reasonable amount.  The default is
15% of the exponential back off calculation.
2019-11-27 16:03:11 -08:00
Rafael Mendonça França
ce085f62d4
Add an option to disable logging for jobs with sensitive arguments
class SensitiveJob < ApplicationJob
      self.log_arguments = false

      def perform(my_sensitive_argument)
      end
    end

When dealing with sensitive arugments as password and tokens it is
now possible to configure the job to not put the sensitive argument
in the logs.

Closes #34438.
2019-11-08 13:53:23 -05:00
Gannon McGibbon
9bfb73a5f6
Merge pull request #37568 from gmcgibbon/run_inline_jobs_in_theor_own_thread
Run inline jobs in separate threads
2019-11-01 20:45:18 -04:00
Gannon McGibbon
8319f9ecea Run inline jobs in separate threads 2019-11-01 20:14:40 -04:00
Edouard CHIN
b7a3f31797 The AJ_ADAPTER env needs to be set:
- ActiveJob integration test can't be run otherwise because of
  5bbf047deb/activejob/test/support/integration/jobs_manager.rb (L8)
2019-10-30 20:03:04 +01:00
Matthew Draper
7437b6a361 Tidy up the build output for Active Job adapters 2019-10-23 20:47:50 +10:30
Jean Boussier
a707072ffa Implicitly assert no exception is raised in block assertions 2019-10-07 11:01:24 +02:00
Carlos Antonio da Silva
a08a069acd Fix queue adapter class delegation to point to self.class
Using `self` works by essentially pointing to the included class, in
this case `ActiveJob::Base`, so that'd end up delegating to
`ActiveJob::Base.queue_adapter` instead.
2019-09-23 21:59:59 -03:00
Lucas Mansur
89df4f2e0c Stop queue_name_prefix from being global
Changes in `queue_name_prefix` no longer affects unrelated jobs.
2019-09-13 18:30:19 -03:00
George Claghorn
e8b3a46d2e Move ActiveJob::LogSubscriber into its own file 2019-09-13 14:53:29 -04:00
Kevin Deisz
fbebeabd6d
Serialize classes and modules with ActiveJob
This commit allows ActiveJob to serialize classes and modules without a custom serializer. This allows for workflows like:

```
class EmailJob < ApplicationJob
  queue_as :default
  def perform(template_class, *arguments)
    template_class.new(*arguments).send!
  end
end

module Email
  class FooTemplate ... end
  class BarTemplate ... end
end

EmailJob.perform_later(Email::FooTemplate, ...)
EmailJob.perform_later(Email::BarTemplate, ...)
```

Currently this is only achieveable through a custom serializer or through constantizing in each instance.
2019-09-09 16:45:12 -04:00
Eugene Kenny
5545f6a771 Fix Active Job Sidekiq integration tests
The `Sidekiq::Logging` module was removed in Sidekiq 6.0 in favour of
`Sidekiq.logger=`.

https://github.com/mperham/sidekiq/wiki/Logging#api-changes

> The old Sidekiq::Logging class was removed in Sidekiq 6.0. You should
> not be accessing any Sidekiq internal classes to use the logger. Use
> `logger` directly in your Worker or use `Sidekiq.logger` elsewhere.
2019-09-01 23:31:21 +02:00
Gareth du Plooy
060a1fb338 Log active_job potential matches when asserting
Adds logging of potential matches when calling `assert_enqueued_with` and `assert_performed_with` to provide more information on test failures.
2019-08-12 15:16:12 -05:00
John Crepezzi
647317d17e Add at option to perform_enqueued_jobs test helper
Currently, the `perform_enqueued_jobs` helpers will also immediately
perform jobs that are scheduled via `set(wait:)` to run in the future.
This commit adds a new argument to `perform_enqueued_jobs` to make it
only run jobs scheduled at or before the passed in `Time`. This allows
testing the side effects of immediate job execution separate of jobs
delayed in the future.
2019-08-06 16:31:48 +02:00
Rafael Mendonça França
dd16e208a6
Require time extensions in the job that depends on time 2019-08-02 00:52:02 -04:00
Akira Matsuda
af2129b4c7 Use try only when we're unsure if the receiver would respond_to the method 2019-08-01 17:58:00 +09:00
Vlado Cingel
10d0f48ad8 Ability to test activejobs with relative delay
`assert_enqueued_with` and `assert_performed_with` were not able to
properly test jobs with relative delay. `:at` option was asserted for
equality and test will always fail cause small fraction of time will
pass between job call and assertion.

This commit fixes that by droping microseconds from `:at` argument
assertions.
2019-07-26 00:41:15 +02:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
John Hawthorn
5d9359bbc3 Use ActiveJob 5.2 retry logic for old jobs
Rails 6 introduces retries per-exception, instead of a global count of
retries. Because ActiveJob 5.2 doesn't serialize the execution count
per-exception, when ActiveJob 6.0 picks up an "old" job it can't know
the exception count in the new format.

This can also be an issue if AJ 6.0 serializes a new job with
exception_executions which is later picked up by AJ 5.2, which would
clear exception_executions (since it has no knowledge of it).

Previously we handled this by resetting exception_executions, if it
wasn't defined on a job, which could result in the worst case retrying
the job 2x the times we should.

This commit changes how we handle loading a legacy job: instead of
resetting exception_executions, we instead will always use the global
executions count.

This way, jobs which only have one retry_on (and didn't have a behaviour
change in AJ 6) are backwards-and-forwards-compatible with counts
respected exactly.

Jobs with multiple retry_on will revert to the AJ5.2 behaviour if they
were ever run under AJ5.2.
2019-04-22 14:53:38 -07:00
Gannon McGibbon
9057e64151
Merge pull request #35738 from gmcgibbon/aj_assert_drop_usec_docs
ActiveJob time argument assertion documentation
2019-04-20 12:36:58 +09:00
Patrik Bóna
3a7fa10603 Use individual execution counters when calculating retry delay
Individual execution counters were introduced in #34352. However
`#determine_delay` which is used to calculate retry delay still uses the
global counter. This commit fixes it.
2019-04-12 17:47:08 +02:00
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
Gannon McGibbon
dbd1db91d9 Fix assert_performed_with time tests 2019-03-25 01:31:48 -04:00
Gannon McGibbon
7f038621df Drop microseconds in job argument assertions 2019-03-22 17:04:56 -04:00
Cory Gwin @gwincr11
31021c780f
Adding enque time tracking and logging
Motivation:
  - Currently we have 2 seperate monkey patches in place for tracking
  enqueded time for 2 seperate workers. It seems that activejob could be
  a source of truth for how long an item has been enqued so that we can
  easily use it for consistent monitoring across workers/apps to ensure
  that jobs are running at an acceptable speed.

Changes:
  - Add an enqueded at attribute and serilization tooling.
  - Add a method to get how long a job has been enqueded for.
  - Add a logging item to show how long a job was enqued prior to the
  perform method firing.
2019-02-13 19:20:41 -05:00
Matthew Draper
287920ca7d Respect ENV variables when finding DBs etc for the test suite
If they're not set we'll still fall back to localhost, but this makes it
possible to run the tests against a remote Postgres / Redis / whatever.
2019-02-06 01:20:06 +10:30
alkesh26
e356200ca1 activejob typo fixes. 2019-01-29 21:15:12 +05:30
Rosa Gutierrez
154057b4f7 Rewrite ActiveJob exception tests so it runs with the real adapters
Previously, by extending ActiveJob::TestCase, the test adapter provided
for tests was being used always, in all executions where supposedly
different adapters were being used. As a consequence, some bugs visible
only for some adapters might have gone undetected. This commit changes
that, skipping queue adapters for which we can't test scheduling jobs
with a delay.
2019-01-08 12:07:38 +01:00
Rosa Gutierrez
88349cee3c Support in-flight jobs stored before individual execution counters for retry_on (#34731)
Also, make tests and examples for individual execution counters
clearer, as it wasn't entierly clear what would happen in this case:

```
retry_on CustomException, OtherException, attempts: 3
```

The job would be retried at most 3 times in total, for both
CustomException and OtherException. To have the job retry 3 times at
most for each exception individually, the following retry_on
declarations are necessary:

```
retry_on CustomException, attempts: 3
retry_on OtherException, attempts: 3
```
2019-01-05 13:54:38 +13:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
Rafael França
299a213a73
Merge pull request #33992 from kirs/enqueue-return-false
Make AJ::Base#enqueue return false if the job wasn't enqueued
2018-12-05 11:24:19 -05:00
Rafael Mendonça França
72300f9742 Do not deserialize GlobalID objects that were not generated by Active Job
Trusting any GlobaID object when deserializing jobs can allow
attackers to access information that should not be accessible to them.

Fix CVE-2018-16476.
2018-11-27 15:28:41 -05:00
Rafael França
f0330b6202
Merge pull request #34376 from composerinteralia/default_queue_name
Allow using queue prefix with a default queue name
2018-11-23 17:08:40 -05:00
Alberto Almagro
95d9c3b3d6 Keep executions for each specific exception (#34352)
* Keep executions for each specific declaration

Fixes #34337

ActiveJob used the global executions counter to control the number of
times a job should be retried. The problem with this approach was that
in case a job raised different exceptions during its executions they
weren't retried the number of times defined by their `attemps` number.

**Example:**

Having the following job:
```ruby
class BuggyJob < ActiveJob::Base
  retry_on CustomException, attemps: 3
  retry_on OtherException, attempts: 3
end
```
If the job raised `CustomException` in the first two executions and then
it raised `OtherException`, the job wasn't retried anymore because the
global executions counter was already indicating 3 attempts.

With this patch each `retry_on` declaration has its specific counter so
that the first two executions that raise `CustomException` don't affect
the retries count that future exceptions may have.

* Revert "clarifies documentation around the attempts arugment to retry_on"

This reverts commit 86aa8f8c5631f77ed9a208e5107003c01512133e.
2018-11-23 11:31:14 -08:00
Edouard CHIN
cdb16ac576 Allow all ActiveJob assertion helper to accept Proc in their only kw:
- That feature is useful to enqueue or assert that jobs got enqueued
  or performed based on dynamic conditions.
  We will be able to leverage that feature to fix all ActionMailer
  assertion helper issue when a Mailer define a custom delivery job
  (see next commit).
2018-11-21 23:14:43 +01:00
Bernie Chiu
945fdd7692 Permit ActionController::Parameters for serializable Hash 2018-11-19 17:38:29 -05:00
Daniel Colson
b517347be1
Allow using queue prefix with a default queue name
Fixes #34366

Currently setting queue_name_prefix will not combine a prefix with the
default_queue_name; it will only affect queue names set with `queue_as`.
With this PR the prefix will affect the default_queue_name as well.

Closes #19831

Currently setting default_queue_name doesn't actually affect the
queue_name default (although default_queue_name does get used if you
pass a falsey `part_name` to `queue_as`). This PR would get
default_queue_name working as expected as well.

Because the queue_name default is now a lambda wrapping the
default_queue_name, rather than the default_queue_name itself, I had to
update one test to use the instance method `#queue_name` (which
`instance_exec`s the value) instead of the class method. I think this
change is OK, since only the instance method is documented.

There was a question about whether we want a `default_queue_name`
configuration. If we want to get rid of it, I would also be happy to
open a PR for that instead. It has been around for a while now, but it
also hasn't really worked for a while now.

r? @matthewd
since you had an opinion about this before
2018-11-03 22:39:18 -04:00
Gannon McGibbon
1f7bd2a171 Restore HWIA support to AJ::Arguments.deserialize
Restore HashWithIndifferentAccess support to
ActiveJob::Arguments.deserialize.
2018-10-30 17:10:33 -05:00
Rafael França
f4876545ff
Merge pull request #33972 from bogdanvlviv/follow-up-33897
Improve `enqueue_retry.active_job` message
2018-10-30 16:53:06 -04:00
Kir Shatrov
ee9fc12024 Make AJ::Base#enqueue return false if the job wasn't enqueued 2018-10-28 15:02:44 -04:00
Rafael França
d76d66fb55
Merge pull request #34204 from XrXr/aj-test-helper-args
Include deserialized arguments in jobs returned by AJ test helpers
2018-10-24 15:49:10 -04:00
yuuji.yaginuma
7eba11373c Remove an extra @mutex.synchronize
Since `@mutex.synchronize` is enforced in the `ensure_connection!` method,
there is no need to do so on the caller side.
c1b47f9c5d/lib/sneakers/publisher.rb (L22-L26)

Due to this, `ThreadError(deadlock; recursive locking)` has occurred.
2018-10-19 12:38:21 +09:00
yuuji.yaginuma
096cb88ce7 Return a non zero code when can not connect to backend on CI 2018-10-19 07:45:47 +09:00
Alan Wu
3ebc229034 Include deserialized arguments in jobs returned by AJ test helpers
`assert_enqueued_with` and `assert_performed_with` return a instantiated
instance of the matching job for further assertion (#21010).

Before this commit the `arguments` method on the returned instance
returns a serialized version of the arguments.
2018-10-12 12:15:16 -04:00
Edouard CHIN
4d75f58991 Add a way to check for subset of arguments when performing jobs:
- When calling `assert_performed_with`/`assert_enqueued_with`, the
  +args+ needs to match exactly what the job get passed.

  Some jobs can have lot of arguments, or even a simple hash argument
  has many key. This is not convenient to test as most tests doesn't
  need to check if the arguments matches perfectly.

  This PR make it possible to only check if a subset of arguments were
  passed to the job.
2018-09-26 18:45:52 -04:00
Rafael Mendonça França
f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
bogdanvlviv
b0f2f5e348
Improve enqueue_retry.active_job message
Since #33751 was added `enqueue_retry.active_job` instrumentation to
the `retry_on` method, then #33897 moved the instrumentation to `retry_job`
method in order to ensure that this method publish `enqueue_retry.active_job`
notification too.
See related discussion https://github.com/rails/rails/pull/33751#discussion_r214140008

Since `enqueue_retry.active_job` moved to `retry_job`, there is no guarantee
that payload of `enqueue_retry.active_job` would have `:error`.
See test `LoggingTest#test_enqueue_retry_logging_on_retry_job` as
example of that case.

Related to https://github.com/rails/rails/pull/33897#discussion_r219707024

I think we can improve notification of `enqueue_retry.active_job`:

- If there is no `event.payload[:error]`, then publish like
  "Retrying RescueJob in 3 seconds." only.
- If `event.payload[:wait]` is `nil`, then publish
  "Retrying RescueJob in 0 seconds." instead of "Retrying RescueJob in nil seconds."
- If there is `event.payload[:error]`, then publish
  "Retrying RescueJob in 3 seconds, due to a DefaultsError.".
- Change the type of the message from `error` to `info.`

Also, this commit removes part of messages - "The original exception was #{ex.cause.inspect}."
of `enqueue_retry.active_job`, `retry_stopped.active_job`, and `discard.active_job` since I
haven't found it useful. Please let me know whether you agree with that?
2018-09-25 01:34:20 +03:00
Rafael França
f3c359800a
Merge pull request #33906 from dark-panda/ignore-psqlrc-when-using-psql
Ignore psqlrc files when executing psql commands
2018-09-20 16:31:44 -04:00
Sharang Dashputre
14e278f876 Make assert_<enqueued|performed>_with() compare hashes ignoring order of keys
The test helpers now treat `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` as equals
2018-09-21 00:09:40 +05:30
Rafael França
1b90f614b1
Merge pull request #33897 from bogdanvlviv/follow-up-33751
Follow up #33751
2018-09-18 14:35:39 -04:00
J Smith
69e0e0acf9 Ignore psqlrc files when executing psql commands
psqlrc files can affect the execution of commands in ways that can hold
up execution by blocking or otherwise cause unexpected side effects and
should best be ignored when using psql programmatically.
2018-09-17 12:13:42 -03:00
bogdanvlviv
237ef95338
Print correct rake command on running AJ integration tests
Currently when executing `bundle exec rake test:integration` under `activejob/`
derectory, it prints helpful info like:
```
(snip)
*** rake aj:integration:async ***
(snip)
*** rake aj:integration:delayed_job ***
(snip)
 ```
but  there is no defined `:aj` scope  in `activejob/Rakefile`,
so I think output should be like:
```
(snip)
*** rake test:integration:async ***
(snip)
*** rake test:integration:delayed_job ***
(snip)
 ```

By the way `rake test:integration` doesn't work if execute it without
prepending `bundle exec` to that command. It is probably what we should
fix too.
2018-09-17 08:19:12 +03:00
bogdanvlviv
b6b5a7ac52
retry_job should publish enqueue_retry.active_job notification
Also this commit removes `:wait` from payload of
`retry_stopped.active_job`.

Related to https://github.com/rails/rails/pull/33751#discussion_r214140008
Follow up #33751

/cc @kaspth, @rafaelfranca
2018-09-16 17:46:24 +03:00
Sharang Dashputre
9203d2b3e1
Update test_helper_test.rb
Fix typo `wiht` -> `with`
2018-09-12 15:35:22 +05:30
Rafael França
66ab9c74dd
Merge pull request #33823 from stoodfarback/aj_backburner_fix_priority
ActiveJob Backburner adapter: fix priority
2018-09-10 17:50:37 -04:00
yuuji.yaginuma
9d848d8545 Add missing perform_enqueued_jobs to error logging test
Without `perform_enqueued_jobs`, job are not executed and assertion is not done.
2018-09-09 13:46:43 +09:00
stoodfarback
fc4e7d44c8 ActiveJob Backburner adapter: fix priority
The priority wasn't being passed from ActiveJob to Backburner, despite
priority being supported. This also brings it inline with the docs,
which mark Backburner as supporting priorities in the "Backend Features"
table: https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html
2018-09-07 21:55:05 -07:00
Rafael França
5bbaae0d20
Merge pull request #33751 from steves/add_retry_notifications_to_aj
Add hooks to ActiveJob around retries and discards
2018-08-30 13:39:51 -05:00
Steve S
3bf33d7c2c
Move ActiveJob retry and discard logging into log subscriber 2018-08-30 13:07:37 -04:00
Rafael Mendonça França
a8fff60814
Add test to make sure the custom object key can't be serialized 2018-08-28 16:31:15 -04:00
utilum
96ac7e4cde Remove duplicate test
This patch corrects a duplicate method name introduced in #33635.

Also fixes typo in method names.
2018-08-22 01:41:09 -07:00
bogdanvlviv
2ec60fb818
Allow assert_performed_with to be called without a block.
Example:
```
def test_assert_performed_with
  MyJob.perform_later(1,2,3)

  perform_enqueued_jobs

  assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high')
end
```

Follow up #33626.
2018-08-20 13:05:29 +03:00
bogdanvlviv
11634e8ef8
Fix assert_performed_jobs and assert_no_performed_jobs
Execution of `assert_performed_jobs`, and `assert_no_performed_jobs`
without a block should respect passed `:except`, `:only`, and `:queue` options.
2018-08-20 13:05:29 +03:00
bogdanvlviv
de4420da44
Allow :queue option to assert_no_performed_jobs.
If the `:queue` option is specified, then only the job(s) enqueued to a specific
queue will not be performed.

Example:
```
def test_assert_no_performed_jobs_with_queue_option
  assert_no_performed_jobs queue: :some_queue do
    HelloJob.set(queue: :other_queue).perform_later("jeremy")
  end
end
```
2018-08-20 13:05:29 +03:00
bogdanvlviv
d50fb21e4d
Allow :queue option to assert_performed_jobs.
If the `:queue` option is specified, then only the job(s) enqueued to a specific
queue will be performed.

Example:
```
def test_assert_performed_jobs_with_queue_option
  assert_performed_jobs 1, queue: :some_queue do
    HelloJob.set(queue: :some_queue).perform_later("jeremy")
    HelloJob.set(queue: :other_queue).perform_later("bogdan")
  end
end
```
2018-08-20 13:05:29 +03:00
bogdanvlviv
ec2e8f645e
Allow :queue option to perform_enqueued_jobs.
If the `:queue` option is specified, then only the job(s) enqueued to
a specific queue will be performed.

Example:
```
def test_perform_enqueued_jobs_with_queue
  perform_enqueued_jobs queue: :some_queue do
    MyJob.set(queue: :some_queue).perform_later(1, 2, 3) # will be performed
    HelloJob.set(queue: :other_queue).perform_later(1, 2, 3) # will not be performed
  end
  assert_performed_jobs 1
end
```

Follow up #33265

[bogdanvlviv & Jeremy Daer]
2018-08-20 00:20:06 +03:00
yuuji.yaginuma
e49fb7921e Increment execution count before deserialize arguments
Currently, the execution count increments after deserializes arguments.
Therefore, if an error occurs with deserialize, it retries indefinitely.

In order to prevent this, the count is moved before deserialize.
Fixes #33344.
2018-08-18 11:22:41 +09:00
Kevin Deisz
ec16301488
Allow perform_enqueued_jobs to be called without a block.
Performs all of the jobs that have been enqueued up to this point in the test.
2018-08-15 15:00:40 -04:00
zvkemp
2a1884bfe5 Wrap ActiveJob::Enqueue in evented ActiveSupport::Notification 2018-07-17 15:05:12 -07:00
bogdanvlviv
22c7d5650c
Allow queue option to assert_no_enqueued_jobs
It can be asserted that no jobs are enqueued to a specific queue:
```ruby
def test_no_logging
  assert_no_enqueued_jobs queue: 'default' do
    LoggingJob.set(queue: :some_queue).perform_later
  end
end
```
2018-06-30 18:30:55 +03:00
Ryuta Kamizono
b3653aee94
Merge pull request #33257 from utilum/ruby-warnings
Fix Ruby warnings tickled by the test suite
2018-06-30 17:58:02 +09:00
utilum
e862ee86b7 Fix Ruby warnings tickled by the test suite 2018-06-30 10:20:45 +02:00
bogdanvlviv
58271f6314
Clarify activejob/lib/active_job/test_helper.rb
Rename `in_block_job` to `enqueued_job` since this variable can refer not only
to jobs that were created in the block.
See #33258.

Return back accidentally removed test to activejob/test/cases/test_helper_test.rb
See #33258.

Fix name of tests.
2018-06-29 19:46:55 +03:00
bogdanvlviv
4382fcbc22
Allow call assert_enqueued_with and assert_enqueued_email_with with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
  MyJob.perform_later(1,2,3)
  assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')

  MyJob.set(wait_until: Date.tomorrow.noon).perform_later
  assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```

Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
  ContactMailer.welcome.deliver_later
  assert_enqueued_email_with ContactMailer, :welcome
end

def test_email_with_arguments
  ContactMailer.welcome("Hello", "Goodbye").deliver_later
  assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```

Related to #33243
2018-06-29 15:37:02 +03:00
George Claghorn
3110caecbe Allow passing multiple exceptions to retry_on/discard_on 2018-06-25 18:16:58 -04:00
Kasper Timm Hansen
ba07b5fc12
Rename exception variable to error.
Follows the change from 6fac9bd, so the naming is consistent.
2018-05-21 15:43:16 +02:00
yuuji.yaginuma
6fac9bd599 Pass the error instance as the second parameter of block executed by discard_on
I'm not sure what originally wanted to pass to the argument.
However, as long as see the document added along with the commit, it seems just
to be mistaken that trying to pass the error instance.
https://github.com/rails/rails/pull/30622/files#diff-59beb0189c8c6bc862edf7fdb84ff5a7R64

Fixes #32853
2018-05-12 13:55:25 +09:00
Rafael Mendonça França
5b9cd1a579
Make sure that when serialing an just deserialized job arguments are there
When a job was just deserialized `arguments` is `nil` and the serialized
arguments are in the `@serialized_arguments` variable. If we try to
serialize this job again the arguments are going to be `nil` instead of
what was serialized.

The test we had was not checking this case because it was deserializing
the job in the same object that had the arguments.

To fix this, when the `@serialized_arguments` are present we return it
instead of the result of the `arguments` serialized.
2018-05-01 13:33:50 -04:00
Alberto Almagro
6ef720791d Remove support for Qu gem.
Reasons are that the Qu gem wasn't compatible since Rails 5.1,
gem development was stopped in 2014 and maintainers have
confirmed its demise. See issue #32273
2018-03-19 21:27:16 +01:00
Andrew White
a9d1167b1f Add support for timezones to Active Job
Record what was the current timezone in effect when the job was
enqueued and then restore when the job is executed in same way
that the current locale is recorded and restored.
2018-02-22 14:14:42 +00:00
Rafael França
b7b73de0df
Merge pull request #32026 from bogdanvlviv/improve-30941
Improve ActiveJob custom argument serializers #30941
2018-02-20 13:35:34 -05:00
yuuji.yaginuma
7d2b8f3ac9 Fix "warning: BigDecimal.new is deprecated" 2018-02-18 09:59:58 +09:00
bogdanvlviv
67391879f6
Fix error message about unknown ActiveJob argument serializer 2018-02-17 17:48:10 +02:00
bogdanvlviv
d2c094aa50
Add argument serializer TimeWithZoneSerializer
The serializer serializes an instance of `ActiveSupport::TimeWithZone`.
The serializer deserializes value to `ActiveSupport::TimeWithZone` if possible.
2018-02-17 17:48:10 +02:00
Rafael Mendonça França
b59c7c7e69 Add tests to serialize and deserialze individually
This will make easier to be backwards compatible when changing the
serialization implementation.
2018-02-14 13:10:08 -05:00
Rafael Mendonça França
69645cba72 Simplify the implementation of custom argument serializers
We can speed up things for the supported types by keeping the code in the
way it was.

We can also avoid to loop trough all serializers in the deserialization by
trying to access the class already in the Hash.

We could also speed up the custom serialization if we define the class
that is going to be serialized when registering the serializers, but
that will remove the possibility of defining a serialzer for a
superclass and have the subclass serialized using it.
2018-02-14 13:10:08 -05:00
Rafael Mendonça França
d9a5c7011f Add serializers for Time, Date and DateTime 2018-02-14 13:10:08 -05:00
Rafael Mendonça França
d2d98d6946 Allow serializers to be used either as classes or objects 2018-02-14 13:10:08 -05:00
Rafael Mendonça França
b098584f63 Add symbol and duration serializers 2018-02-14 13:10:08 -05:00
Rafael Mendonça França
ea61533245 Only add one more custom key in the serialized hash
Now custom serialziers can register itself in the serialized hash using
the "_aj_serialized" key that constains the serializer name.

This way we can avoid poluting the hash with many reserved keys.
2018-02-14 13:10:07 -05:00
Rafael Mendonça França
ec686a471e Simplify the implementation of custom serialziers
Right now it is only possible to define serializers globally so we don't
need to use a class attribute in the job class.
2018-02-14 13:10:07 -05:00
Evgenii Pecherkin
3785a57299 Remove non-default serializers 2018-02-14 13:10:07 -05:00
Evgenii Pecherkin
e360ac1231 Introduce serializers to ActiveJob 2018-02-14 13:10:07 -05:00
Rafael França
4cfd40a580
Merge pull request #30622 from aidanharan/custom-discarded-job-handling
Allow for custom handling of exceptions that are discarded
2018-01-23 17:07:25 -05:00
yuuji.yaginuma
ce98cd0d0d Explicitly require sidekiq/cli
Currently, sidekiq integration test + Ruby 2.5.0-rc1 show exception as follows.

```
#<Thread:0x000000000670bec0@/home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.0.5/lib/sidekiq/util.rb:23 run> terminated with exception (report_on_exception is true):
/home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.1.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `block in load_missing_constant': uninitialized constant Sidekiq::CLI (NameError)
	from /home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.1.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
	from /home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.1.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `rescue in load_missing_constant'
	from /home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.1.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:42:in `load_missing_constant'
	from /home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.0.5/lib/sidekiq/launcher.rb:65:in `heartbeat'
	from /home/travis/build/rails/rails/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.0.5/lib/sidekiq/launcher.rb:123:in `start_heartbeat'
```

https://travis-ci.org/rails/rails/jobs/317187279#L2152

The reason for this is that `Sidekiq::CLI` has not been loaded.
Sidekiq integration test launches a Sidekiq instance within
another Ruby process. In such a case, need to require 'sidekiq/cli'
in that launch code.

Ref: https://github.com/mperham/sidekiq/pull/3692#issuecomment-352032251
2017-12-16 11:02:26 +09:00
Yasuo Honda
e4a6a23aa7 Suppress warning: BigDecimal.new is deprecated
`BigDecimal.new` has been deprecated in BigDecimal 1.3.3
 which will be a default for Ruby 2.5.

Refer
533737338d

* This commit has been made as follows:

```
cd rails
git grep -l BigDecimal.new | grep -v guides/source/5_0_release_notes.md | grep -v activesupport/test/xml_mini_test.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g"
```
- `activesupport/test/xml_mini_test.rb`
Editmanually to remove `.new` and `::`

- guides/source/5_0_release_notes.md
This is a Rails 5.0 release notes.
2017-12-15 01:19:57 +00:00
Ryuta Kamizono
245c1dafa8 Enable Layout/LeadingCommentSpace to not allow cosmetic changes in the future
Follow up of #31432.
2017-12-14 17:30:54 +09:00
Aidan Haran
66f34a8ea5
Merge branch 'master' into custom-discarded-job-handling 2017-12-09 13:41:02 +00:00
Jacek Lachowski
b1fbb6688c Improve DelayedJob wrapper logging
ActiveJob wraps every adapter into its own class, that is later passed
into DelayedJob which is responsible for displaying all the logs.

This change improves the logging so we can easily trace executed
jobs and see meaningful information in the logs.
2017-11-24 10:40:16 +01:00
yuuji.yaginuma
8e964556e7 Make sidekiq and resque integration tests work in CI
Since 8f2490b, the integration test of sidekiq and resque is not working
in CI.
https://travis-ci.org/rails/rails/jobs/301276197#L2055
https://travis-ci.org/rails/rails/jobs/301276197#L2061

Because 8f2490b removed password from `redis-server`.
So must also remove passwords from these tests.
2017-11-13 21:02:40 +09:00
yuuji.yaginuma
1ecdd7e8a7 Return a non zero code when can not connect to redis in CI 2017-11-13 21:02:33 +09:00
bogdanvlviv
0835527d6b
rails new runs rails active_storage:install
Omit `rails activestorage:install` for jdbcmysql, jdbc and shebang tests

AppGeneratorTest#test_config_jdbcmysql_database

  rails aborted!
  LoadError: Could not load 'active_record/connection_adapters/mysql_adapter'.
  Make sure that the adapter in config/database.yml is valid.
  If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add
  the necessary adapter gem to the Gemfile.
  (compressed)
  bin/rails:4:in `<main>'
  Tasks: TOP => activestorage:install => environment
  (See full trace by running task with --trace)

AppGeneratorTest#test_config_jdbc_database

  rails aborted!
  LoadError: Could not load 'active_record/connection_adapters/jdbc_adapter'.
  Make sure that the adapter in config/database.yml is valid.
  If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add
  the necessary adapter gem to the Gemfile.
  (compressed)
  bin/rails:4:in `<main>'
  Tasks: TOP => activestorage:install => environment
  (See full trace by running task with --trace)

AppGeneratorTest#test_shebang_is_added_to_rails_file

  /home/ubuntu/.rbenv/versions/2.4.1/bin/ruby: no Ruby script found in input (LoadError)

Prevent PendingMigrationError in tests

 * Run `bin/rails db:migrate RAILS_ENV=test` in test_cases before start tests to prevent PendingMigrationError
 * FileUtils.rm_r("db/migrate")
 * --skip-active-storage

Fix failed tests in `railties/test/railties/engine_test.rb`

Related to #30111

Imporve `SharedGeneratorTests#test_default_frameworks_are_required_when_others_are_removed`

 - Explicitly skip active_storage
 - Ensure that skipped frameworks are commented
 - Ensure that default frameworks are not commented

Fix error `Errno::ENOSPC: No space left on device - sendfile`

Since `rails new` runs `rails active_storage:install`
that boots an app.

Since adding Bootsnap 0312a5c67e35b960e33677b5358c539f1047e4e1
during booting an app, it creates the cache:

   264K    tmp/cache/bootsnap-load-path-cache
   27M     tmp/cache/bootsnap-compile-cache

* teardown_app must remove app
2017-11-06 21:29:14 +00:00
Shuhei Kitagawa
c40b4428e6 removed unnecessary returns 2017-10-28 17:20:38 +09:00
Ryuta Kamizono
a254454deb Merge pull request #30750 from k2nr/fix-active-job
Yield with an error instance instead of error class
2017-10-13 12:58:48 +09:00
Kazunori Kajihiro
34d7b05d27 Test exception message to ensure an exception instance is yielded 2017-10-13 11:55:36 +09:00
Jeremy Daer
53c516d88d
redis-rb 4.0 support
* Use `gem 'redis', '~> 4.0'` for new app Gemfiles
* Loosen Action Cable redis-rb dep to `>= 3.3, < 5`
* Bump redis-namespace for looser Redis version dep
* Avoid using the underlying `redis.client` directly
* Use `Redis.new` instead of `Redis.connect`
2017-10-08 15:37:54 -07:00
Aidan Haran
3291fa3630 Allow for custom handling of exceptions that are discarded 2017-09-16 19:59:32 +01:00
yuuji.yaginuma
0868cac0ef Use ActiveJob::Base.queue_adapter_name to get adapter name
Since 673606a, it holds adapter name.
2017-08-17 06:55:55 +09:00
Matthew Draper
788f46d486 Wait for the Delayed Job worker thread to finish 2017-08-13 22:03:40 +09:30
Kazuhiro NISHIYAMA
7f89d4e8bf Use File::NULL instead of "/dev/null" 2017-07-31 21:58:42 +09:00
yuuji.yaginuma
292be1b7de Use ArgumentError instead of own error class
If the argument is invalid, I think that it is more intuitive to use
`ArgumentError` than its own error class.
2017-07-20 07:38:26 +09:00
posthumanism
4458b76756 Add except option for ActiveJob::TestHelper methods 2017-07-18 07:48:03 +09:00
Koichi ITO
aa28c5ca65 [Active Job] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00