Skip to content
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

Disable cron for "Stopped" services #16

Merged
merged 4 commits into from
Mar 12, 2017
Merged

Disable cron for "Stopped" services #16

merged 4 commits into from
Mar 12, 2017

Conversation

jmloeffler
Copy link
Contributor

I took a stab at #9. First, I updated the metadata.go since the rancher metadata api had changed slightly and broke this (NewClientAndWait no longer returns a pointer). In the second commit, I made it so that GetCronSchedules looks up the service in the cattle service to get the service state. If the state is inactive it ignores it and allows it to be removed from the schedule. The scheduling used to happen in metadata.go but it didn't make sense for metadata.go to depend on cattle.go so I introduced a new scheduler.go. This now contains all of the scheduling logic, leaving metadata.go and cattle.go as thin wrappers around those respective rancher services.

I tested this with Rancher releases 1.1.2 and 1.2.0 and it seems to work ok for both.

I'm new to go, so please let me know if there are any changes you want.

@smazurov
Copy link
Contributor

smazurov commented Dec 8, 2016

I don't think there is a need for changing it from a pointer - you might've pulled up a newer version (or had one locally), but vendor.json wasn't updated.

Otherwise, this looks good, I'll check it out locally in a bit (few days).

@smazurov
Copy link
Contributor

Not sure if you got the above message @jmloeffler

@jmloeffler
Copy link
Contributor Author

Yes. Sorry. I misunderstood and thought that I was to await feedback after you checked things out. I'll take another look at the pointer change I made and report back with a new commit or more info.

@jmloeffler
Copy link
Contributor Author

I added a commit that I think reverts/fixes the pointer issues. I am a little confused about go vendoring, however. It looked like you were using govendor so I did a govendor sync after deleting my local copy of go-rancher-metadata and it pulled the root of the project but not the metadata folder. I wound up having to issue a govendor fetch github.com/rancher/go-rancher-metadata/metadata@beb180ef575f061 e28e9dca169d2c01a7e12d780 to make it build properly but this updated the vendor.json file. I didn't commit that because I assumed I was doing something wrong. I'm hoping you can clarify for me what I was doing wrong with govendor.

@smazurov
Copy link
Contributor

OK i found the problem, in the vendor file I was not referencing the go-rancher-metata/metadata folder, and on my system it was building fine due to existence of it in my $GOPATH/src, I fixed the issue in cd4ac09, try rebasing it on top of that. Sorry about that!

}

cattleService, err := m.CattleClient.GetServiceByUUID(service.UUID)
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would combine, if err == nil && cattleService.State == "inactive" {}


return &schedules, nil
// GetServices returns the services from the metadata client
func (m *Client) GetServices() ([]metadata.Service, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might not be used anywhere now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still being called from here to get the original list of services with the cron label.
https://github.com/jmloeffler/rancher-cron/blob/master/scheduler/scheduler.go#L34

Jason Loeffler and others added 4 commits December 23, 2016 15:14
Added logic to look up the service in the cattle api and ignore it if it is stopped/inactive.
This required calling into the cattle api for looking up the service state.
It didn't make sense for the metadata wrapper to depend on the cattle wrapper so I broke logic out into a new scheduler.
@jmloeffler
Copy link
Contributor Author

I rebased and fixed the excessive nesting based on your feedback. The metadata client call is still being used so I left that in place. Let me know if you think more changes are needed. Thanks for clarifying the govendor stuff. There seems to be a lot of different ways to do vendoring in Go so I assumed I was just doing something wrong.

@jmloeffler
Copy link
Contributor Author

@smazurov Did you see my last update? I think this probably takes care of #9 unless you see more things that you'd like changed.

@haswalt
Copy link

haswalt commented Mar 1, 2017

@smazurov any update on this? Looks like a good feature to merge in

@smazurov
Copy link
Contributor

smazurov commented Mar 2, 2017

yeah for sure, this is good to go, i need to take a closer look at it, and a few other PRs and features and get a 1.0 out. I have some time set aside this week, so I do hope to get to it soon. I 100% appreciate the contribution!

@smazurov smazurov merged commit a9fa796 into SocialEngine:master Mar 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants