Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Add TTL command line argument to modify etcd ttl for service announce…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
a5huynh committed Jun 20, 2015
1 parent 4cdb765 commit 2ca5145
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ customized deployment onto clusters.
| --etcd-port | ETCD cluster peer port. **Default:** 4001
| --prefix | The etcd folder in which to announce running services. **Default:** /services
| --timeout | The number of seconds to wait until the next health check. **Default:** 10
| --ttl | ETCD ttl in seconds for the service announcement. **Default:** 60


12 changes: 8 additions & 4 deletions sidekick.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @Author: ahuynh
# @Date: 2015-06-10 16:51:36
# @Last Modified by: ahuynh
# @Last Modified time: 2015-06-19 13:56:05
# @Last Modified time: 2015-06-19 17:05:53
'''
The sidekick should essentially replace job of the following typical
bash script that is used to announce a service to ETCD.
Expand Down Expand Up @@ -71,8 +71,11 @@
parser.add_argument( '--timeout', action='store', type=int, default=10,
help='Private or public IP of the instance that is running this container.' )

parser.add_argument( '--ttl', action='store', type=int, default=60,
help='ETCD ttl for the service announcement' )

def announce_services( services, etcd_folder, etcd_client, timeout ):

def announce_services( services, etcd_folder, etcd_client, timeout , ttl ):
for key, value in services:
logger.info( 'Health check for {}'.format( key ) )

Expand All @@ -86,7 +89,7 @@ def announce_services( services, etcd_folder, etcd_client, timeout ):
etcd_client.delete( full_key )
else:
# Announce this server to ETCD
etcd_client.set( full_key, value['uri'] )
etcd_client.write( full_key, value['uri'], ttl=ttl )
except etcd.EtcdException as e:
logging.error( e )

Expand Down Expand Up @@ -214,7 +217,8 @@ def main():
announce_services( matching.items(),
etcd_folder,
etcd_client,
args.timeout )
args.timeout,
args.ttl )

if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions tests/test_sidekick.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @Author: ahuynh
# @Date: 2015-06-18 20:15:30
# @Last Modified by: ahuynh
# @Last Modified time: 2015-06-19 13:58:46
# @Last Modified time: 2015-06-19 17:06:28
import unittest

from collections import namedtuple
Expand All @@ -18,7 +18,7 @@ class MockEtcd( object ):
def delete( self, value ):
pass

def set( self, value ):
def write( self, value, ttl ):
pass


Expand Down Expand Up @@ -48,7 +48,7 @@ def setUp( self ):
def test_announce_services( self ):
''' Test `announce_services` functionality '''
services = find_matching_container( [self.container], self.args )
announce_services( services.items(), 'test', self.etcd_client, 0 )
announce_services( services.items(), 'test', self.etcd_client, 0, 0 )

def test_check_health( self ):
''' Test `check_health` functionality '''
Expand Down

0 comments on commit 2ca5145

Please sign in to comment.