Skip to content

Commit

Permalink
linting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zimventures committed Jul 7, 2023
1 parent 0f6b4cb commit 8422ee8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions chirps/scan/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Celery tasks for the scan application."""
from logging import getLogger
import re
from logging import getLogger

from celery import shared_task
from django.utils import timezone
Expand All @@ -10,19 +10,19 @@

logger = getLogger(__name__)


@shared_task
def scan_task(scan_id):
"""Main scan task."""

logger.info('Starting scan', extra={'id': scan_id})
logger.info('Starting scan', extra={'id': scan_id})

try:
scan = Scan.objects.get(pk=scan_id)
except Scan.DoesNotExist:
logger.error('Scan record not found', extra={'id': scan_id})

scan_task.update_state(state='FAILURE',
meta={'error': f'Scan record not found ({scan_id})'})
scan_task.update_state(state='FAILURE', meta={'error': f'Scan record not found ({scan_id})'})
return

# Need to perform a secondary query in order to fetch the derrived class
Expand Down
11 changes: 8 additions & 3 deletions chirps/target/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Models for the target appliation."""
from logging import getLogger

import pinecone
from django.contrib.auth.models import User
from django.db import models
Expand All @@ -12,6 +13,8 @@
from .custom_fields import CustomEncryptedCharField

logger = getLogger(__name__)


class BaseTarget(PolymorphicModel):
"""Base class that all targets will inherit from."""

Expand All @@ -33,6 +36,7 @@ def __str__(self) -> str:
"""String representation of this model."""
return str(self.name)


class RedisTarget(BaseTarget):
"""Implementation of a Redis target."""

Expand Down Expand Up @@ -79,15 +83,15 @@ def decrypted_api_key(self):
decrypted_value = self.api_key
return decrypted_value
except UnicodeDecodeError:
return "Error: Decryption failed"
return 'Error: Decryption failed'
return None

def search(self, query: str, max_results: int) -> list[str]:
"""Search the Pinecone target with the specified query."""
pinecone.init(api_key=self.api_key, environment=self.environment)

# Assuming the query is converted to a vector of the same dimension as the index. We should re-visit this.
query_vector = convert_query_to_vector(query) # pylint: disable=undefined-variable
query_vector = convert_query_to_vector(query) # pylint: disable=undefined-variable

# Perform search on the Pinecone index
search_results = pinecone.fetch(index_name=self.index_name, query_vector=query_vector, top_k=max_results)
Expand All @@ -100,7 +104,7 @@ def test_connection(self) -> bool:
pinecone.init(api_key=self.api_key, environment=self.environment)
pinecone.deinit()
return True
except Exception as err: # pylint: disable=broad-exception-caught
except Exception as err: # pylint: disable=broad-exception-caught
logger.error('Pinecone connection test failed', extra={'error': err})
return False

Expand Down Expand Up @@ -130,4 +134,5 @@ def search(self, query: str, max_results: int) -> list[str]:
logger.info('Mantium target search complete', extra={'id': self.id})
return documents


targets = [RedisTarget, MantiumTarget, PineconeTarget]

0 comments on commit 8422ee8

Please sign in to comment.