Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make analysis of session a separate background task #395

Merged
merged 9 commits into from
Jul 31, 2020

Conversation

mzfr
Copy link
Collaborator

@mzfr mzfr commented Jul 18, 2020

This PR will separate the analysis and deletion of the session.

tanner/server.py Outdated Show resolved Hide resolved
@afeena
Copy link
Collaborator

afeena commented Jul 24, 2020

don't forget to cancel the task in cleanup_background_tasks

session = json.loads(session)
result = await self.create_stats(session, redis_client)
await self.queue.put(result)
await self.save_session(redis_client, pg_client)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need a separate save function or we can do everything in current function?

anyway, save should not be called after you put each session into the queue, it should be called once

@@ -95,7 +95,7 @@ async def delete_session(self, sess, redis_client, pg_client):
await sess.remove_associated_env()
try:
await redis_client.set(sess.get_uuid(), sess.to_json())
await self.analyzer.analyze(sess.get_uuid(), redis_client, pg_client)
# await self.analyzer.analyze(sess.get_uuid(), redis_client, pg_client)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented line

session = json.loads(session)
result = await self.create_stats(session, redis_client)
await self.queue.put(result)
await self.save_session(redis_client, pg_client)

async def save_session(self, redis_client, pg_client):
while not self.queue.empty():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have try for redis error, but not postgres errors

)
except aioredis.ProtocolError as redis_error:
self.logger.exception(
"Error with redis. Session will be returned to the queue: %s",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no queue anymore to return the session to

)
# This is the key which stores all the dorks.
# It matches the pattern of other keys.
except aioredis.errors.ReplyError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid this by using another pattern for sessions?

@afeena
Copy link
Collaborator

afeena commented Jul 29, 2020

@mzfr could you please fix the tests?

@mzfr
Copy link
Collaborator Author

mzfr commented Jul 29, 2020

@afeena Yes I am working on them, Trying to understnad why they are failing.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1381

  • 51 of 82 (62.2%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.4%) to 77.756%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tanner/server.py 7 19 36.84%
tanner/sessions/session_analyzer.py 44 63 69.84%
Files with Coverage Reduction New Missed Lines %
tanner/sessions/session_manager.py 1 73.42%
Totals Coverage Status
Change from base Build 1377: -0.4%
Covered Lines: 1566
Relevant Lines: 2014

💛 - Coveralls

@afeena afeena merged commit 336a87e into mushorg:develop Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants