* Changing incorrect license in some source files. * Changing CreateService to mimic CreateJob by setting the batch size to the instance count. * Changing Getcerts to GetCerts to match the style of the rest of the codebase. * Overhauled error handling. Backoff now recognizes temporary errors and continues to retry if it finds one. * Changed thrift function call wrapper to be more explicitly named and to perform more safety checks. * Moved Jitter function from realis to retry. * API code is now more uniform and follows a certain template. * Lock added whenever a thrift call is made or when a modification is done to the connection. Note that calling ReestablishConn externally may result in some race conditions. We will move to make this function private in the near future. * Added test for Realis session thread safety. Tested ScheduleStatus monitor. Tested monitor timing out. * Returning nil whenever there is an error return so that there are no ambiguities. * Using defer with unlock so that the lock is still released if a panic is invoked.
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
/**
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package realis
|
|
|
|
// Using a pattern described by Dave Cheney to differentiate errors
|
|
// https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
|
|
type timeout interface {
|
|
Timeout() bool
|
|
}
|
|
|
|
func IsTimeout(err error) bool {
|
|
temp, ok := err.(timeout)
|
|
return ok && temp.Timeout()
|
|
}
|
|
|
|
type TimeoutErr struct {
|
|
error
|
|
timeout bool
|
|
}
|
|
|
|
func (t *TimeoutErr) Timeout() bool {
|
|
return t.timeout
|
|
}
|
|
|
|
func NewTimeoutError(err error) *TimeoutErr {
|
|
return &TimeoutErr{error: err, timeout: true}
|
|
}
|
|
|
|
type temporary interface {
|
|
Temporary() bool
|
|
}
|
|
|
|
func IsTemporary(err error) bool {
|
|
temp, ok := err.(temporary)
|
|
return ok && temp.Temporary()
|
|
}
|
|
|
|
type TemporaryErr struct {
|
|
error
|
|
temporary bool
|
|
}
|
|
|
|
func (t *TemporaryErr) Temporary() bool {
|
|
return t.temporary
|
|
}
|
|
|
|
// Retrying after receiving this error is advised
|
|
func NewTemporaryError(err error) *TemporaryErr {
|
|
return &TemporaryErr{error: err, temporary: true}
|
|
}
|
|
|
|
// Nothing can be done about this error
|
|
func NewPermamentError(err error) TemporaryErr {
|
|
return TemporaryErr{error: err, temporary: false}
|
|
}
|