Skip to content

Commit

Permalink
Add DELETE to /messages to purge actor inbox; this resolves #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Stubbs committed Dec 18, 2018
1 parent 28b6ac8 commit f814e00
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions actors/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,14 +778,16 @@ def get_hypermedia(actor, exc):
return ok(result, msg="Logs retrieved successfully.")


def get_messages_hypermedia(actor):
return {'_links': {'self': '{}/actors/v2/{}/messages'.format(actor.api_server, actor.id),
'owner': '{}/profiles/v2/{}'.format(actor.api_server, actor.owner),
},
}


class MessagesResource(Resource):

def get(self, actor_id):
def get_hypermedia(actor):
return {'_links': {'self': '{}/actors/v2/{}/messages'.format(actor.api_server, actor.id),
'owner': '{}/profiles/v2/{}'.format(actor.api_server, actor.owner),
},
}
logger.debug("top of GET /actors/{}/messages".format(actor_id))
# check that actor exists
id = Actor.get_dbid(g.tenant, actor_id)
Expand All @@ -799,7 +801,25 @@ def get_hypermedia(actor):
result = {'messages': len(ch._queue._queue)}
ch.close()
logger.debug("messages found for actor: {}.".format(actor_id))
result.update(get_hypermedia(actor))
result.update(get_messages_hypermedia(actor))
return ok(result)

def delete(self, actor_id):
logger.debug("top of DELETE /actors/{}/messages".format(actor_id))
# check that actor exists
id = Actor.get_dbid(g.tenant, actor_id)
try:
actor = Actor.from_db(actors_store[id])
except KeyError:
logger.debug("did not find actor: {}.".format(actor_id))
raise ResourceError(
"No actor found with id: {}.".format(actor_id), 404)
ch = ActorMsgChannel(actor_id=id)
ch._queue._queue.purge()
result = {'msg': "Actor mailbox purged."}
ch.close()
logger.debug("messages purged for actor: {}.".format(actor_id))
result.update(get_messages_hypermedia(actor))
return ok(result)

def validate_post(self):
Expand Down

0 comments on commit f814e00

Please sign in to comment.