-
Notifications
You must be signed in to change notification settings - Fork 897
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
MiqQueue#put_unless_exists
supports create_with
#14562
Conversation
53910c9
to
42b487d
Compare
42b487d
to
1b12183
Compare
This is starting scope creep - pulled out last commit into own PR (14569). this should simplify it (at least a little) |
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'm comfortable with this new pattern. @kbrock are going to change all the places where put_unless_exists
is being used?
app/models/miq_queue.rb
Outdated
msg.update_attributes!(:state => STATE_DEQUEUE, :handler => w) | ||
end | ||
w = MiqWorker.server_scope.find_by(:pid => Process.pid) || MiqServer.my_server | ||
msg.update_attributes!(:state => STATE_DEQUEUE, :handler => w) |
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.
ugh - I had this in a different PR
@gtanzillo Of the 31 instances of #before
MiqQueue.put_unless_exists(unique_params) do |msg|
msg.merge(create_params)
end
# after
MiqQueue.create_with(create_params).put_unless_exists(unique_params)
# or
MiqQueue.create_with(create_params).put_unless_exists(unique_params) do |msg|
_logger.debug("created a record #{msg.id}")
end There are some |
MiqQueue#put_unless_exists
MiqQueue#put_unless_exists
WIP:
|
1b12183
to
97a46b3
Compare
MiqQueue#put_unless_exists
MiqQueue#put_unless_exists
supports create_with
97a46b3
to
849a358
Compare
fixed cops - I'll pull out anything that isn't straight forward |
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.
Only really have one comment regarding to code, and it really is just asking for a clarification on the intent of the PR.
Overall, I think this is a fine way to do things going forward, and will (I assume) optimize things in the future when it is officially implemented. That said, while it doesn't make the interface any worse than what we had (I would agree with you that it is an improvement), the interface is still a bit confusing in the sense that it still requires two method calls to do what I think is perceived as an "atomic action".
Again, don't have a better solution than what you have here, and more bringing it up as it might still be a somewhat confusing mechanism.
app/models/miq_queue.rb
Outdated
:msg_timeout => TIMEOUT, | ||
:deliver_on => nil |
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.
Seems like this is the only actual code change to the application code, and effectively it was just removing something that was nil
regardless, right?
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.
Right, this is the only real change.
Added a slew of tests to ensure nothing was broken
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.
And to be honest, this is defaulting deliver_on
to a nil (which ruby already does)
In ActiveRecord, True, current implementation has the second as 2 different database queries, but that is what monkey patching / PRs is about |
@kbrock That is fair. I guess that goes to show you my lack of keeping up with the new |
(also role and server_guid, which we don't use)
849a358
to
7c464d1
Compare
Checked commits kbrock/manageiq@b713984~...7c464d1 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@kbrock Please also don't forget to check for put_unless_exists in the split out repos. Not sure they exist or not, but we can't forget those. |
Getting away from manipulating the put_unless_exists hash and instead AuthenticationMixin requires ManageIQ#14562 which allows deliver_on to work in miq_queue.create_with
Summary
MiqQueue#put_unless_exists
adds a unique message to theMiqQueue
.This PR change:
_unless_exists
part) and which are used for creation (put
part).SELECT
,INSERT
queries to a singleINSERT
statement. (all data in sql friendly hashes, and not looking at returning object)Before
We used a block that was clunky, nuanced, and preventing us from tuning the sql:
What does this do?
Metric#purge_hourly
already exists, then don't create one. Ignore the:args
value since it is a timestamp and probably won't match anyway.Metric#purge_hourly
does not already exist, then create one. The new record will include the:args
value provided.Stated another way:
:class_name
and:method_name
are part of the uniqueness constraint.:class_name
,:method_name
, and:args
are used for creation.After
We can leverage an active record mechanism
created_with
to convert these parameters into SQL. On one hand, it does not introduce any change toMiqQueue
, but it is more closely coupled with ActiveRecord:UPDATE: This PR only updates
MiqQueue
- ensuring that it works withcreate_with
for the parameters of interestrelated: #14676