Skip to content

Commit

Permalink
improve database_service
Browse files Browse the repository at this point in the history
  • Loading branch information
felippemr committed Apr 9, 2016
1 parent 4382edc commit af3b246
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/database_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
import logging
import settings
from nameko.rpc import rpc
from nameko.runners import ServiceRunner

logging.basicConfig()
logging.basicConfig(
filename='logs/database_rpc_service.txt',
level=logging.INFO
)
LOG = logging.getLogger("DatabaseEnQueueService")
LOG.setLevel(logging.DEBUG)



class DatabaseService(object):
Expand All @@ -16,10 +20,10 @@ def create_database(self, engine, name, cpu, mem):
call_args = bytes(json.dumps(
{"engine": engine, "name": name, "cpu": cpu, "mem": mem}
), 'utf-8')
LOG.debug("Args Converted")
LOG.info("Args Converted")

settings.CREATE_DATABASE_QUEUE.put(call_args)
LOG.debug("Queue updated")
LOG.info("Queue updated")

return "Create request sent to queue"

Expand All @@ -28,9 +32,27 @@ def destroy_database(self, engine, name, cpu, mem):
call_args = bytes(json.dumps(
{"engine": engine, "name": name, "cpu": cpu, "mem": mem}
), 'utf-8')
LOG.debug("Args Converted")
LOG.info("Args Converted")

settings.DESTROY_DATABASE_QUEUE.put(call_args)
LOG.debug("Queue updated")
LOG.info("Queue updated")

return "Destroy request sent to queue"

def main():
config = {
'_log': LOG,
'AMQP_URI': 'amqp://guest:guest@localhost'
}
runner = ServiceRunner(config)
runner.add_service(DatabaseService)

runner.start()

try:
runner.wait()
except (KeyboardInterrupt, SystemExit):
runner.kill()

if __name__ == '__main__':
main()

0 comments on commit af3b246

Please sign in to comment.