Commit Graph

829 Commits

Author SHA1 Message Date
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
Ryuta Kamizono
c46475ed62 Fix keyword arguments warnings caused by #37278
https://buildkite.com/rails/rails/builds/63817#de061bf7-9b91-484d-bdeb-c974f6bed01d/987-994
2019-10-13 22:01:09 +09:00
Orien Madgwick
493edf044f Add bug tracker/documentation/mailing list URIs to the gemspecs 2019-10-11 20:47:19 -04:00
Jean Boussier
a707072ffa Implicitly assert no exception is raised in block assertions 2019-10-07 11:01:24 +02:00
Kasper Timm Hansen
eca6c273fe
[ci skip] switch eg. to proper e.g. 2019-10-07 02:18:36 +02:00
George Claghorn
149da8815c Remove errant default option 2019-09-24 14:08:09 -04: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
George Claghorn
efbab35929 Delegate ActiveJob::Base#queue_adapter to class 2019-09-23 16:55:36 -04:00
George Claghorn
820cc8012b
Move ActiveJob::Exceptions#instrument to ActiveJob::Instrumentation 2019-09-23 16:13:54 -04:00
George Claghorn
2c14a0f16d
Extract ActiveJob::Instrumentation 2019-09-23 12:29:52 -04:00
Mike Perham
0e64348cca
Allow Sidekiq access to the underlying Job class
Currently `wrapped` is a String.  Instead pass Class so that Sidekiq can get access to the ActiveJob and its configuration without having to constantize.  I verified that `JobClass.to_s` == `"JobClass"` so serialization to JSON should not be affected.

```ruby
> JSON.dump({"wrapped" => SomeJob})
=> "{\"wrapped\":\"SomeJob\"}"
```

By having access to the ActiveJob class, Sidekiq can get access to any `sidekiq_options` which have been set on that ActiveJob type and serialize those options into Redis.

https://github.com/mperham/sidekiq/blob/master/Changes.md#60
2019-09-16 10:17:14 -07: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
Akira Matsuda
438e93f7fd Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-07 03:19:51 +09:00
Jean Boussier
e623ccf921 Intern ActiveJob queue_name
Memory profiling shows that the queue name is always duplicated

```
Retained String Report
-----------------------------------
  ...
217  "default"
200  /tmp/bundle/ruby/2.6.0/bundler/gems/rails-59e746d4d07b/activejob/lib/active_job/queue_name.rb:52
```
2019-09-03 16:16:39 +02: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
c45c84db72 Add CHANGELOG entry for ActiveJob change
In #36864 we made a change to an ActiveJob test helper to add a new
parameter for testing jobs delayed into the future.

This commit adds a CHANGELOG entry for that change as well as fixing a
circular argument error.
2019-08-07 19:55:16 +02: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
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04: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
Eileen M. Uchitelle
8c6fedffa1
Merge pull request #35873 from prathamesh-sonpatki/enqueuing-fixes
Fix the deprecation warning about `config.active_job.return_false_on_aborted_enqueue`
2019-04-05 11:45:48 -04:00
प्रथमेश Sonpatki
a8328f61b6
Add Active Job release notes [ci skip] (#35872) 2019-04-05 15:42:01 +05:30
Prathamesh Sonpatki
c35f7b5115
Fix the deprecation warning about config.active_job.return_false_on_aborted_enqueue
- It will return false in Rails 6.1 not 6.0. Also fixed the default
  value which is true for new applications.
2019-04-05 15:40:34 +05:30
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
Ryuta Kamizono
51ab5cb043 Follow up tweaks b89a3e7e638a50c648a17d09c48b49b707e1d90d [ci skip]
* use backticks instead of `+`
* and more (e.g. missed replacing `Array#excluding` and
`Enumerable#excluding` in b89a3e7e638a50c648a17d09c48b49b707e1d90d)
2019-03-31 09:52:02 +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
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Kasper Timm Hansen
0fc1397784
Merge pull request #35559 from ashishprajapati/ashishprajapati/important_textual_improvements
Added missing guide links in documentation and minor wording fix
2019-03-09 22:54:21 +01:00
ashishprajapati
e3ef12b310 Added missing guide links in README documentation and minor wording fix [ci skip] 2019-03-10 03:17:01 +05:30
Abhay Nikam
027e492b6f Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
Abhay Nikam
476abd403b Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
alkesh26
7048d5cb10 [ci skip] activejob typo fix. 2019-02-25 14:48:39 +05:30
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
Olivier Lacan
e77293786c Document queue_as block arguments and their use
Currently, we only document the use case for ActiveJob's `queue_as` block
arguments in [Rails Guides][1]. It seems necessary to document them in the API
docs as well considering how useful and powerful this option is.

[1]: https://edgeguides.rubyonrails.org/active_job_basics.html#queues

[ci skip]
2019-02-11 17:36:44 -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
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
Kasper Timm Hansen
647d7e6167
Revert "Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json""
I reverted the wrong commit. Damn it.

This reverts commit f66a977fc7ae30d2a07124ad91924c4ee638a703.
2019-01-08 22:19:22 +01:00
Kasper Timm Hansen
f66a977fc7
Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"
We had a discussion on the Core team and we don't want to expose this information
as a JSON endpoint and not by default.

It doesn't make sense to expose this JSON locally and this controller is only
accessible in dev, so the proposed access from a production app seems off.

This reverts commit 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38, reversing
changes made to b6e4305c3bca4c673996d0af9db0f4cfbf50215e.
2019-01-08 22:16:58 +01:00
Rosa Gutierrez
acbbd4ab8d Ensure 0 is always the default for the individual exception counters in ActiveJob
Some adapters like Resque that use Redis, convert the Ruby hash with a
default value, Hash.new(0), into a regular hash without a default value
after serializing, storing and deserializing. This raises an error when
we try to access a missing exception key. A simple solution is not to
rely on the hash's default value, and provide a default as alternative
when accessing it instead.
2019-01-08 12:08:06 +01:00
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
Arun Agrawal
50e3680768 Bump license years for 2019 2018-12-31 10:24:38 +07: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
Ryuta Kamizono
d5197d59a1 Use native Array#append, Array#prepend, Hash#transform_keys, and Hash#transform_keys!
Since Rails 6 requires Ruby 2.5.

https://github.com/ruby/ruby/blob/ruby_2_5/NEWS

Follow up #34754.
2018-12-20 23:22:46 +09:00
Kasper Timm Hansen
1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
yuuji.yaginuma
2e7e9fe1dc Do not require webpacker in Active Job integration tests
Because `skip-javascript` option is specified for the dummy application
used in the integration tests.
bdc96802a7/activejob/test/support/integration/helper.rb (L14)
2018-12-08 13:24:22 +09:00
Rafael Mendonça França
884310fdd0
Improve deprecation message for enqueue returning false
And make sure new applications in Rails 6.0 has this config enabled.

Also, improve test coverage and add a CHANGELOG entry.
2018-12-05 13:52:44 -05: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
jacobherrington
308d637550 Change queueing to queuing in docs and comments [skip ci]
My spellchecker flagged this as an incorrect spelling, upon further
research it appears to be a point of contention in English. Either way
might work.

After further examination queuing is much more common in the Rails
codebase so making this change will serve to standardize the spelling.
2018-11-18 22:36:44 -06:00
Alberto Almagro
36ea629fae Make PERMITTED_TYPES private
The constant `PERMITTED_TYPES` is only used by the private method
`serialize_argument` and it already has the `# :nodoc:` annotation as
the other constants in the class.

Complements e899e22
2018-11-12 20:44:59 +01:00
Alberto Almagro
7c9e69dba1 Document missing supported types [ci skip]
This commit adds missing types to the supported types list, which
was extended in #30941
2018-11-11 23:02:54 +01:00
Ryuta Kamizono
e899e228e4 Restore private_constant which is lost accidentally in #30941
https://github.com/rails/rails/pull/30941/files#diff-fc90ec41ef75be8b2259526fe1a8b663L53
2018-11-09 20:05:29 +09:00
Gannon McGibbon
e74fdbe00c Amend CVE note and security guide section wordings
Reword first sentence of dep management and CVE section of
security guide. Also, reword and move gemspec notes above deps.

[ci skip]
2018-11-06 18:06:57 -05:00
Gannon McGibbon
1c11688b56 Add CVE note to security guide and gemspecs
[ci skip]
2018-11-06 14:25:36 -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
bogdanvlviv
0925d7340e
Clarify docs of ActiveJob::TestHelper [ci skip]
I found a few sentences that should be updated as well.
See https://github.com/rails/rails/pull/33571#discussion_r209435886

Follow up #33571
2018-10-16 00:26:18 +03: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
Orhan Toy
6865f73b91 [ci skip] Fix link to Concurrent::ThreadPoolExecutor docs 2018-10-11 13:29:34 +02:00
Alan Wu
1042950b34 Remove unnecessary use of included in ActiveJob::Core
Using `included` to define `attr_acessor` and `attr_writer` is causing
these methods to not show up in the documentation.
2018-10-05 14:51:41 -07:00
Yasuo Honda
aa3dcabd87 Add Style/RedundantFreeze to remove redudant .freeze
Since Rails 6.0 will support Ruby 2.4.1 or higher
`# frozen_string_literal: true` magic comment is enough to make string object frozen.
This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.

* Exclude these files not to auto correct false positive `Regexp#freeze`
 - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
 - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'

It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.

* Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required

 - 'actionpack/test/controller/test_case_test.rb'
 - 'activemodel/test/cases/type/string_test.rb'
 - 'activesupport/lib/active_support/core_ext/string/strip.rb'
 - 'activesupport/test/core_ext/string_ext_test.rb'
 - 'railties/test/generators/actions_test.rb'
2018-09-29 07:18:44 +00:00
Mohit Natoo
9fa4342970 Documentation clarity in ActiveJob::TestHelper [ci skip] (#33571)
* Documentation clarity in ActiveJob::TestHelper [ci skip]

* Documentation for options

[Mohit Natoo + Rafael Mendonça França]
2018-09-28 12:10:26 -04:00
Ryuta Kamizono
886d38e63e
Merge pull request #33570 from mohitnatoo/queue_adapter_name_doc
Documentation for queue_adapter_name method in ActiveJob::QueueAdapter

[ci skip]
2018-09-28 18:35:48 +09: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
Kasper Timm Hansen
baffadaec9
Extract instrument method.
Similar to Action View's and Action Controller's instrument helpers.
2018-09-23 20:44:42 +02:00
yuuji.yaginuma
b18f2fe96d Fix "warning: shadowing outer local variable - job" 2018-09-22 09:14:08 +09: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
ca875d0c02 Update arguments.rb [ci skip]
Fix typo `Instrinsic` -> `Intrinsic`
2018-09-13 22:14:27 +05:30
bogdanvlviv
5a212939c2
Add changelog entries for #33849 [ci skip]
Since these changes related to the public API, I think we should add
changelog entries.

Related to #33838, #33849
2018-09-13 16:58:56 +03:00
Rafael França
b79f3cc96b
Merge pull request #33849 from ricardotk002/include-helpers-action-dispatch-integration-test
Include test helpers in ActionDispatch::IntegrationTest
2018-09-12 19:19:17 -04:00
Ricardo Díaz
64a9759aff Include test helpers when ActionDispatch::IntegrationTest is loaded
As @dhh brings up, the point of `ActionDispatch::IntegrationTest` is to
allow users to test the integration of all the pieces called by a
controller. Asserting about the emails and jobs queued is part of that
task.

This commit includes the `ActionMailer::TestHelper` and
`ActiveJob::TestHelper` modules when the ActionMailer and ActiveJob
railties are initialized respectively.
2018-09-12 16:58:14 -05:00
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
Eileen M. Uchitelle
12b32d8049
Merge pull request #33826 from tgturner/activejob-retry-attempts
retry_on argument `attempts` clarification
2018-09-09 15:22:18 -04:00
Graham Turner
86aa8f8c56 clarifies documentation around the attempts arugment to retry_on 2018-09-09 09:46:20 -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
Steve S
26dc9bc8ee
Add hooks to ActiveJob around retries and discards 2018-08-29 13:28:55 -04:00
Matthew Draper
068fe7dc90
Merge pull request #33718 from kddeisz/permit-list
Finish converting whitelist and blacklist references
2018-08-29 14:07:37 +09:30
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
Kevin Deisz
7c9751d7fe
Permit list usage cleanup and clearer documentation 2018-08-27 09:51:46 -04:00
Kevin Deisz
0efecd913c
Convert remaining usage of whitelist and blacklist 2018-08-24 16:16:41 -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
b8576425ee
DRY in assert_enqueued_jobs 2018-08-20 13:05:29 +03:00
bogdanvlviv
b7beb5d4e5
Fix formatting of ActiveJob::TestHelper api docs 2018-08-20 13:05:29 +03: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
2bf8b4eb0e
Add changelog entry about adding :queue option to job assertions and helpers
Note that it removes changelog entry of #33265 since the entry in this commits
includes that too.
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
e0cf042fa2
Fix perform_enqueued_jobs
Set
````
queue_adapter.perform_enqueued_jobs = true
queue_adapter.perform_enqueued_at_jobs = true
queue_adapter.filter = only
queue_adapter.reject = except
queue_adapter.queue = queue
```
if block given.
Execution of `flush_enqueued_jobs` doesn't require that.
2018-08-20 13:05:22 +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
bogdanvlviv
f169752163
Add example perform_enqueued_jobs without block to api docs [ci skip]
Follow up #33626
2018-08-16 09:29:30 +03: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
Mohit Natoo
2d57f2f2f2 Documentation for queue_adapter_name method in ActiveJob::QueueAdapter [ci skip] 2018-08-10 02:02:58 +05:30
Mohit Natoo
39d87a4b7b perform_or_enqueue instead of enqueue_or_perform 2018-08-09 20:33:43 +05:30
Paul McMahon
7b9c19d94b Rails guides are now served over https
http links will be redirected to the https version, but still better to
just directly link to the https version.
2018-07-24 11:29:31 +09:00
Kasper Timm Hansen
7b3ead3b26
[ci skip] Fixup changelog. Trim title. Mention benefit. 2018-07-20 21:40:53 +02:00
zvkemp
2a1884bfe5 Wrap ActiveJob::Enqueue in evented ActiveSupport::Notification 2018-07-17 15:05:12 -07:00
alpaca-tc
a07354d9eb ActiveJob::Base no longer dependents on Serializers 2018-07-03 21:48:26 +09:00
Kasper Timm Hansen
dca5596f99
Revert "Merge pull request #33234 from alpaca-tc/autoload_activejob_arguments"
It breaks Active Job when run in isolation. E.g. bin/test test/cases/logging_test.rb:
https://travis-ci.org/rails/rails/jobs/398779028

Consider Rafaels suggestion of reviewing the eager loading instead:
https://github.com/rails/rails/pull/33234#issuecomment-401027419

This reverts commit cb0fdaacb277bd0595bfd73178329922aa24477e, reversing
changes made to a0a1abb3c7942084111d87ae95837a83bcc794f6.
2018-07-01 13:22:44 +02: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
Rafael Mendonça França
03fd2f3810
Revert "Merge pull request #33243 from evopark/fix/action-mailer-test-helper-no-block"
This reverts commit 9d6bbf4e0b2d2b2e2fccd87a778de2893bb28a25, reversing
changes made to 5a1ea09062eaed78e21253a128d433a1beb745ad.

This method only works with block.
2018-06-28 15:08:01 +02:00
Marcus Ilgner
3919cb398b
Fix ActionMailer assert_enqueued_email_with
The documentation for assert_enqueued_email_with states that it's
supposed to work without a block yet it calls assert_enqueued_with
which doesn't check whether a block was passed before calling `yield`
2018-06-28 11:01:55 +02:00
alpaca-tc
ff2fbe2708 Autoload ActiveJob::Arguments 2018-06-27 14:53:49 +09:00
alpaca-tc
391015e238 ActiveJob::Arguments is no longer used in file 2018-06-27 14:53:37 +09:00
bogdanvlviv
f1e625f853
Add changelog entry for 3110cae [ci skip]
Since it is changes of the public API, it seems valuable to add a mention
about it to the changelog file.

Follow up 3110caecbebdad7300daaf26bfdff39efda99e25
2018-06-27 00:47:48 +03:00
George Claghorn
3110caecbe Allow passing multiple exceptions to retry_on/discard_on 2018-06-25 18:16:58 -04:00
bogdanvlviv
d6702b7ab2
Fix name of the second parameter of block executed by discard_on and retry_on
[ci skip]

Follow up #32854 and ba07b5fc12a740d41d288bea6347f15f4948483c.
2018-05-29 07:11:33 +00:00
Oscar Amado
ef90adfd27 update README link: md instead rdoc [ci skip] 2018-05-24 17:49:35 +02:00
Oscar Amado
d795e94c45 correct link to activejob readme [ci skip] 2018-05-24 16:39:38 +02:00
utilum
a48f6a5d9f Enable warnings in all test tasks
Also normalize AJ task use t, like all other Rails test tasks.
2018-05-23 23:05:03 +02: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
Ryuta Kamizono
e4a0a04883 Strip duplicated suffixes more strictly
In the previous code incorrectly removes intermediate words.
2018-04-22 14:30:07 +09:00
Yoshiyuki Hirano
8e2c91df4a Fix duplicated suffix for JobGenerator 2018-04-22 12:09:04 +09:00
Jared Rader
48a1d63777 fix spelling in docs for ActiveJob::Serializers::ObjectSerializer#deserialize 2018-04-13 06:59:50 -07: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
Jeremy Green
538463bce7 Add documentation about not accepting PRs for new adapters (#32298) 2018-03-19 14:46:07 -04:00
Rafael Mendonça França
ba0ae542ca
Remove changelog header for unreleased version
We only add the header when releasing to avoid some conflicts.

[ci skip]
2018-03-13 15:20:57 -04:00
bogdanvlviv
dd075657d0
Fix CHANGELOGs [ci skip]
- Add missing dots.
- Remove reference to itself on GitHub.
  Usually, we add references to fixed issues only in a changelog.

Follow up #32223
2018-03-12 08:44:50 +02:00
bogdanvlviv
6a1e7292bc
Remove passing extra arguments to ActiveJob Callbacks 2018-02-23 00:58:00 +02: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
Jeremy Daer
d4eb0dc89e Rails 6 requires Ruby 2.4.1+
Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug.

References #32028
2018-02-17 15:34:57 -08:00
bogdanvlviv
67391879f6
Fix error message about unknown ActiveJob argument serializer 2018-02-17 17:48:10 +02:00
bogdanvlviv
30528cda9e
Fix docs of ActiveJob custom argument serializers
Add `:nodoc:` to `ActiveJob::Serializers`
Add `:doc:` to `ActiveJob::Serializers::ObjectSerializer#klass`
Express `ActiveJob::Serializers::ObjectSerializer#klass` as private method
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 França
21cc0432e4
Merge pull request #32002 from y-yagi/fix_set_serializer
Fix custome serializer setting
2018-02-17 00:09:23 -05:00
Rafael Mendonça França
0ea8e7db1a Remove support to Ruby 2.2
Rails 6 will only support Ruby >= 2.3.
2018-02-16 18:52:10 -05:00
Yuji Yaginuma
3cc93de6ad Fix custome serializer setting
The serializer should be set up in `after_initialize` so that it work
properly even if the user specifies serializer with initializers.

Also, since `custom_serializers` is `Array`, it needs to be flattened
before setting the value.
2018-02-16 14:56:05 +09:00
Rafael Mendonça França
25a14bf2bd Add CHANGELOG entry 2018-02-14 13:13:51 -05: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
71721dc1c9 Improve documentation on custom serializers 2018-02-14 13:10:08 -05:00
Rafael Mendonça França
a5f7357a3d Add configuration to set custom serializers 2018-02-14 13:10:08 -05:00
Rafael Mendonça França
2fe467091b No need to require a autoloaded constant 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
9bc8b4bbde Define the interface of a Serializer 2018-02-14 13:10:07 -05:00
Rafael Mendonça França
803f4385c6 Remove unnecessary qualified constant lookups 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 Mendonça França
1c383df324 Start Rails 6.0 development!!!
🎉🎉🎉
2018-01-30 18:51:17 -05:00
Ryuta Kamizono
cdb15ba7cd Fix CHANGELOG format [ci skip]
* Add backticks
* Expand tabs
* Fix indentation
2018-01-24 09:24:49 +09: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
Ryuta Kamizono
5a50146888 Consolidate queue_adapter= and interpret_adapter
Since #25037, `queue_adapter=` simply delegates to `interpret_adapter`
only.
2018-01-05 17:18:56 +09:00
Yoshiyuki Hirano
b20354afcc Bump license years for 2018 2017-12-31 22:36:55 +09: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
Yoshiyuki Hirano
cd049112cb [ci skip] Add a space to comment in SidekiqAdapter
* I think it's better to have a leading space after the `#`
  denoting the start of the comment.
2017-12-14 04:50:49 +09:00
Aidan Haran
66f34a8ea5
Merge branch 'master' into custom-discarded-job-handling 2017-12-09 13:41:02 +00:00
Yoshiyuki Hirano
649f19cab1 Fix example code in ActiveJob::Core [ci skip]
1) It seems that it raise error on example code in `ActiveJob::Core`.

Before:

```ruby
class DeliverWebhookJob < ActiveJob::Base
  def serialize
    super.merge('attempt_number' => (@attempt_number || 0) + 1)
  end

  def deserialize(job_data)
    super
    @attempt_number = job_data['attempt_number']
  end

  rescue_from(Timeout::Error) do |exception|
    raise exception if @attempt_number > 5
    retry_job(wait: 10)
  end

  def perform
    raise Timeout::Error
  end
end
```

Then it run `DeliverWebhookJob.perform_now` in `rails console`. And raise error:

NoMethodError: undefined method `>' for nil:NilClass
from /app/jobs/deliver_webhook_job.rb:12:in `block in <class:DeliverWebhookJob>'

So I thought it's necessary to fix it.

After:

```ruby
class DeliverWebhookJob < ActiveJob::Base
  attr_writer :attempt_number

  def attempt_number
    @attempt_number ||= 0
  end

  def serialize
    super.merge('attempt_number' => attempt_number + 1)
  end

  def deserialize(job_data)
    super
    self.attempt_number = job_data['attempt_number']
  end

  rescue_from(Timeout::Error) do |exception|
    raise exception if attempt_number > 5
    retry_job(wait: 10)
  end

  def perform
    raise Timeout::Error
  end
end
```

Then it run `DeliverWebhookJob.perform_now` in `rails console`. And it does'nt raise error NoMethodError.

2) Use `Timeout::Error` instead of `TimeoutError` (`TimeoutError` is deprecated).
2017-12-05 15:40:22 +09:00
Rafael Mendonça França
2837d0f334
Preparing for 5.2.0.beta2 release 2017-11-28 14:41:02 -05:00
Fatos Morina
37cf9b3466 Fix typos and add a few suggestions 2017-11-28 19:27:43 +01:00
Rafael Mendonça França
cceeeb6e57
Preparing for 5.2.0.beta1 release 2017-11-27 14:50:03 -05: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
Rafael Mendonça França
8dd76a7a6f
Use .tt extension to all the template files
Make clear that the files are not to be run for interpreters.

Fixes #23847.
Fixes #30690.
Closes #23878.
2017-11-13 15:23:28 -05: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
Rafael França
280fb08fc7 Merge pull request #30955 from prathamesh-sonpatki/rm-changelog-entry
Remove CHANGELOG entry for the change that was backported to 5-1-stable [ci skip]
2017-10-23 13:09:41 -04:00
Prathamesh Sonpatki
95de5033cd
Remove CHANGELOT entry for the change that was backported to 5-1-stable [ci skip]
- It was backported in
  0eae8dd4b8
  and is present in Rails 5.1.3
2017-10-23 20:04:31 +05:30
Akira Matsuda
feb6ecd313 [Active Job] require_relative => require
This basically reverts fef234f1f0a238c2277459652861144ae89501ff
2017-10-21 22:48:28 +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
Kazunori Kajihiro
4a13c1e1d2 Yield with an error instance instead of error class 2017-09-29 18:15:56 +09:00
Aidan Haran
3291fa3630 Allow for custom handling of exceptions that are discarded 2017-09-16 19:59:32 +01:00
Yoshiyuki Hirano
c7cd470bb3 Update activejob doc [ci skip] 2017-08-30 05:08:36 +09:00
Yoshiyuki Hirano
3a11e0586e Update MIT licenses link [ci skip] 2017-08-22 08:46:02 +09:00
Yoshiyuki Hirano
948c2c48df Use ssl in guide and comment [ci skip] 2017-08-19 08:23:37 +09: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
yuuji.yaginuma
2966f9598e Fix warning: circular argument reference
This fixes the following warnings:

```
rails/activejob/lib/active_job/test_helper.rb:119: warning: circular argument reference - except
rails/activejob/lib/active_job/test_helper.rb:166: warning: circular argument reference - except
```
2017-07-19 08:56:41 +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
yuuji.yaginuma
46725b33a9 Make sidekiq and resque integration tests work in CI
Since f55ecc6, the integration test of sidekiq and resque is not working
in CI.
https://travis-ci.org/rails/rails/jobs/251783876

Because f55ecc6 required a password to access redis.
Therefore, handling by passing passwords when connecting to redis.
2017-07-10 07:42:17 +09:00
Kir Shatrov
14ece5e429 Use frozen-string-literal in ActiveJob 2017-07-09 20:50:52 +03:00
Akira Matsuda
fef234f1f0 [Active Job] require => require_relative 2017-07-01 18:38:05 +09:00
Rafael França
cf8c46938b Merge pull request #29588 from greysteil/add-gemspec-links
Add source code and changelog links to gemspecs
2017-06-28 11:24:02 -04:00
Grey Baker
3e6ce1cd69 Add source code and changelog links to gemspecs 2017-06-28 10:06:01 +01:00
utilum
b58d73fc57 ActiveJob::Core#serialize stores provider_job_id (fixes #26581). 2017-06-27 07:08:55 +02:00
yuuji.yaginuma
12b3c60388 Remove needless gitignore
The dummy application is created under the tmp directory. Nothing is
created in the `test/dummy` directory.
40bdbce191/activejob/test/support/integration/helper.rb (L9)

I guess that this comment makes it unnecessary.
https://github.com/rails/rails/pull/16541#r16986711
2017-06-26 21:39:09 +09:00
bogdanvlviv
6673cf7071
Use require_relative instead of require with full path 2017-06-14 12:10:17 +03:00
Genadi Samokovarov
b6b0c99ff3 Use mattr_accessor default: option throughout the project 2017-06-03 13:52:48 +03:00
David Heinemeier Hansson
1c275d812f Add option for class_attribute default (#29270)
* Allow a default value to be declared for class_attribute

* Convert to using class_attribute default rather than explicit setter

* Removed instance_accessor option by mistake

* False is a valid default value

* Documentation
2017-05-29 18:01:50 +02:00
yuuji.yaginuma
82e646f3d0 Bring back delayed_job to test list
`delayed_job_active_record` 4.1.2 supports Rails 5.1.
Ref: https://github.com/collectiveidea/delayed_job_active_record/pull/138
2017-05-28 21:39:18 +09:00
Mohit Natoo
4b04f56146 Removed string inquiry.
fixed indentation.

rebased with master.
2017-05-26 19:25:53 +07:00
Mohit Natoo
673606a962 Provides friendlier way to access queue adapters of a job.
- removed predicate method. Used only reader.
2017-05-26 19:00:34 +07:00
bogdanvlviv
40bdbce191
Define path with __dir__
".. with __dir__ we can restore order in the Universe." - by @fxn

Related to 5b8738c2df003a96f0e490c43559747618d10f5f
2017-05-23 00:53:51 +03:00
dixpac
4f39556577 Improving docs for callbacks execution order [ci skip]
When define callbacks latest definition on the same callback/method
overwrites previous ones.
2017-05-21 18:45:59 +02:00
Ryuta Kamizono
89389428b5 Cleanup CHANGELOGs [ci skip]
* Remove trailing spaces.
* Add backticks around method and command.
* Fix indentation.
2017-04-30 02:41:44 +09:00
yuuji.yaginuma
8ae20e6582 Add missing require
Without this, unit test fails.

```
bundle exec ruby -w -Ilib:lib:test test/cases/logging_test.rb
Using inline
Run options: --seed 41246

# Running:

SE......S....

Finished in 0.052938s, 245.5696 runs/s, 831.1585 assertions/s.

  1) Error:
LoggingTest#test_job_error_logging:
NameError: uninitialized constant LoggingTest::RescueJob
    test/cases/logging_test.rb:130:in `rescue in test_job_error_logging'
    test/cases/logging_test.rb:129:in `test_job_error_logging'

13 runs, 44 assertions, 0 failures, 1 errors, 2 skips

You have skipped tests. Run with --verbose for details.
```
2017-04-21 08:02:26 +09:00
Steven Bull
452f9ee0bc Add error logging to Active Job
Active Job logging instrumentation is changed to log errors (with
backtrace) when a job raises an exception in #perform. This improves
debugging during development and test with the default configuration.

Prior to Rails 5, the default development configuration ran jobs with
InlineAdapter, which would raise exceptions to the caller and be
shown in the development log. In Rails 5, the default adapter was
changed to AsyncAdapter, which would silently swallow exceptions
and log a "Performed SomeJob from Async..." info message. This could
be confusing to a developer, as it would seem that the job was
performed successfully.

This patch removes the "Performed..." info message from the log
and adds an error-level "Error performing SomeJob..." log message
which includes the exception backtrace for jobs that raise an
exception within the #perform method. It provides this behavior for
all adapters.
2017-03-27 17:10:24 -07:00
Matthew Draper
6c08d480f1 Start Rails 5.2 development 2017-03-22 10:11:39 +10:30
David Heinemeier Hansson
85c2b7565f Revert #27850 following test breakage (#28427) 2017-03-15 17:46:28 +01:00
Rafael França
cfa2664894 Merge pull request #28112 from bolek/include-job_id-in-all-active-job-logs
Include JobID in all ActiveJob info logs
2017-02-23 16:18:01 -05:00
Rafael Mendonça França
f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
Bolek Kurowski
85c62a2c3d Include JobID in all ActiveJob info logs
Currently we provide the Job ID in logs only related to enqueuing a job.

This adds the job id to the remaining ActiveJob logs when:
 - a job started performing
 - a job ended performing

Providing the job id in those logs will ease searching logs by job id.
2017-02-22 17:11:28 -05:00
Jon Moss
e342f4e60d Remove extra spaces
[ci skip]
2017-02-21 12:02:14 -05:00
yuuji.yaginuma
70e8fed5a3 remove ActiveSupport.halt_callback_chains_on_return_false from everywhere 2017-02-08 17:24:49 +09:00
Akira Matsuda
c684f4f3da bin/test for Active Job and Action Cable tests
According to the commit comment on 54d84cbb77a7fbc6359eda4eb40cc7da29c426e1, AJ/bin/test was intentionally not added,
but AJ tests doesn't actually do anything special other than specifying ENV['AJ_ADAPTER'],
which can be easily done via command line environment variable.
2017-02-02 16:27:42 +09:00
Yuji Yaginuma
80dc309821 correctly set test adapter when configure the queue adapter on a per job (#26690)
The `ActiveJob::TestHelper` replace the adapter to test adapter in
`before_setup`. It gets the target class using the `descendants`, but if
the test target job class is not loaded, will not be a replacement of
the adapter.
Therefore, instead of replacing with `before_setup`, modified to
replace when setting adapter.

Fixes #26360
2017-01-31 16:37:16 -05:00