-
Notifications
You must be signed in to change notification settings - Fork 900
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
MiqServer#recently_active can handle values in the future #22962
Conversation
changes query of recently active from: ```sql -- MiqServer.where(:last_heartbeat => 10.minutes.ago.utc...Time.now.utc).first SELECT "miq_servers".* FROM "miq_servers" WHERE "miq_servers"."last_heartbeat" >= $1 AND "miq_servers"."last_heartbeat" < $2 ORDER BY "miq_servers"."id" ASC LIMIT $3 ``` to ```sql -- MiqServer.where(:last_heartbeat => 10.minutes.ago.utc..).first SELECT "miq_servers".* FROM "miq_servers" WHERE "miq_servers"."last_heartbeat" >= $1 ORDER BY "miq_servers"."id" ASC LIMIT $2 ``` Implications ============ This makes development environments (rails s) easier since we can set the heartbeat in the future. This is necessary to run workflows with rails console / simulate_queue_worker because ```ruby MiqServer.last.update(:last_heartbeat => 1.day.from_now.utc) before: MiqServer.where(:last_heartbeat => 10.minutes.ago.utc...Time.now.utc).exist? => false MiqRegion.my_region.remote_ws_url => nil after: MiqServer.where(:last_heartbeat => 10.minutes.ago.utc..).exist? => true MiqRegion.my_region.remote_ws_url => http://localhost:4000/ ```
Checked commit kbrock@4a57c46 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
@kbrock what is your last_heartbeat in that example? Is it |
@agrare I changed the example to make this more clear. MiqServer.last.update(:last_heartbeat => 1.day.from_now.utc) For this example, I'm running in This also fixes issues in production if clocks on machines are a little out of sync. (even thought this is not the intent/purpose) |
@kbrock do we have sufficient tests for this? I'm surprised you didn't need to fix a test for this change. |
@jrafanie heartbeat sets to The edge case that the time is set in the future (due to time drift or intentional) is not defined behavior. |
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 think this is fine. I think remote_ws_miq_server
or remote_ui_miq_server
returning no value because one or two servers has their time out of sync is NOT a good place for the problem to manifest itself. I would rather let these things go through and let session fail because it looks to be in the future. I think that's easier to diagnose and handle.
Overview
When running
manageiq-providers-workflow
workflows, the api url passed to floe is fromremote_ws_url
.This value becomes
nil
unlessMiqServer#heartbeat
is run every 10 minutes.In a server this is automatically handled, but in development (i.e.:
rails c
andsimulate_queue_worker
) this task falls upon the developer.Goal
Make it unnecessary in development to call
MiqServer#heartbeat
every 10 minutes.Before
After
Discussion
This is not the only solution, but seemed the least invasive.