[Pulp-list] Simple ping service - solution
Lukas Zapletal
lzap+fed at redhat.com
Tue Feb 22 16:35:54 UTC 2011
Hello
here comes my solution. It pings the database, increments the counter,
measures the lag and also shows the version number.
Example output:
# curl -k -u admin:admin https://xxx/pulp/api/services/ping/
{
"db_version": 2,
"ping_duration_ms": "1.68",
"ping_count": 35
}
The code:
class PingAction(JSONController):
@JSONController.error_handler
def GET(self):
"""
Dummy call that just prints time.
@return: db_version - current DB version number
"""
_props_db = get_object_db('properties', ['key'])
# insert the first entry if there is no such document
if _props_db.find_one({"key": "ping_service_count"}) == None:
_props_db.insert({"key": "ping_service_count", "value": 0})
# increment the counter and return
_start_time = time.time()
_props_db.update({"key": "ping_service_count"},
{"$inc": {"value": 1}})
count = _props_db.find_one(
{"key": "ping_service_count"})['value']
# return the response
return self.ok({
"db_version": VERSION,
"ping_count": count,
"ping_duration_ms": str(round((time.time() -
_start_time) * 1000, 2)),
})
Attaching the patch.
Comments?
--
Later,
Lukas "lzap" Zapletal
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-New-dummy-webservice-ping.patch
URL: <http://listman.redhat.com/archives/pulp-list/attachments/20110222/57f35009/attachment.ksh>
More information about the Pulp-list
mailing list