Skip to content

Instantly share code, notes, and snippets.

@joejulian
Created March 30, 2017 05:49
Show Gist options
  • Save joejulian/a73eedb40c55e35a5a69f921b23214ba to your computer and use it in GitHub Desktop.
Save joejulian/a73eedb40c55e35a5a69f921b23214ba to your computer and use it in GitHub Desktop.
from time import sleep
import sys
def sleepex(data):
# Set some defaults in case this filter is called without
# being in a loop
delay=1.25 # seconds
attempt=1
if 'delay' in data.keys():
delay=data['delay']
if 'attempts' in data.keys():
attempt=data['attempts']
# Sleep for delay to the power of attempt. This produces
# an exponential backoff. Subtract 1 delay that will be
# done by ansible itself.
sleep(delay**attempt-delay)
# Always return True as this isn't actually testing anything
return True
class FilterModule(object):
''' Query filter '''
def filters(self):
return {
'sleepex': sleepex
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment