-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Tasks with Params with CLI #428
Conversation
option, passing arguments as a set of <key>:<value> pairs: | ||
|
||
```bash | ||
$ bundle exec maintenance_tasks perform Maintenance::ParamsTask --arguments post_ids:1,2,3 content:"Hello, World!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love if the example Task in the README match the CLI call here and the task in the dummy app, but I can look into this later, it doesn't need to be in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's revisit this later. I'd like to ship custom value types in some form (even if not exactly what's in #414), so we can circle back to this example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to fix the exception in arguments_match_task_attributes
even if it doesn't impact anything too much, example repro:
diff --git i/test/models/maintenance_tasks/run_test.rb w/test/models/maintenance_tasks/run_test.rb
index 1d0449e..23de80f 100644
--- i/test/models/maintenance_tasks/run_test.rb
+++ w/test/models/maintenance_tasks/run_test.rb
@@ -6,3 +6,3 @@ class RunTest < ActiveSupport::TestCase
test "invalid if the task doesn't exist" do
- run = Run.new(task_name: "Maintenance::DoesNotExist")
+ run = Run.new(task_name: "Maintenance::DoesNotExist", arguments: { a: 0 })
refute_predicate run, :valid?
Other feedback but feel free to ignore and 🚢
7d6855a
to
8f70932
Compare
Follow up to #413
The final piece of supporting Tasks with custom parameters in the gem - this allows arguments to be specified via the CLI using an
--arguments
flag.As discussed here, the use of Strong Parameters in TasksController to permit only keys matching the Task's attributes is a bit problematic because it results in a 500 instead of alerting the user. We also wanted to apply this same behaviour to the CLI. As such, I moved the check on the argument keys out of the controller and into
task.rb
. However, I'm not sure if this is necessary - we could just allowActiveModel::UnknownAttributeError
to be raised onassign_attributes
and let that bubble up. Let me know if you think we're being overly defensive here!🎩 Instructions
cd test/dummy; bundle exec maintenance_tasks perform Maintenance::ParamsTask --arguments=post_ids:"1,2,3"
Should see the Task successfully enqueued. To see the Task perform successfully, you can change the Active Job queue adapter to be inline.
cd test/dummy; bundle exec maintenance_tasks perform Maintenance::ParamsTask --arguments=post_ids:"xyz"
Should see Validation failed: Arguments are invalid: :post_ids is invalid