Skip to content

Commit

Permalink
Removed celery and redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ManavTriv committed May 2, 2024
1 parent fc1e1e4 commit 6ac24a6
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 126 deletions.
4 changes: 4 additions & 0 deletions 02b4dedb-9076-43ac-95e8-5d9d8c30b8e3_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": "02b4dedb-9076-43ac-95e8-5d9d8c30b8e3",
"malicious": false
}
4 changes: 4 additions & 0 deletions 5771d496-b0d5-4fcf-ba45-43903b27747d_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": "5771d496-b0d5-4fcf-ba45-43903b27747d",
"malicious": false
}
16 changes: 0 additions & 16 deletions docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion endpoints.http
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
GET {{baseUrl}}/api/v1/customers/testing/emails?start=2024-03-22T02:29:03+00:00

### Get information for a particular email.
GET {{baseUrl}}/api/v1/customers/testing/emails/ac05ffd6-c35e-463e-bb0e-cdd98e73f71e
GET {{baseUrl}}/api/v1/customers/testing/emails/62f600b1-fbff-4bab-bba1-b3d82b270966

### Post a new email scan request.
POST {{baseUrl}}/api/v1/customers/testing/emails
Expand Down
Binary file modified instance/db.sqlite
Binary file not shown.
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,9 @@ resource "aws_appautoscaling_policy" "app-cpu" {
target_value = 20
}
}

# ----------------- QUEUE ----------------- #

resource "aws_sqs_queue" "scan_queue" {
name = "scan"
}
4 changes: 4 additions & 0 deletions spamoverflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def create_app(config_overrides=None):
# Load the models
from spamoverflow.models import db
from spamoverflow.models.email import Email

db.init_app(app)

# Create the database tables
Expand All @@ -24,3 +25,6 @@ def create_app(config_overrides=None):
app.register_blueprint(api)

return app



Binary file modified spamoverflow/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed spamoverflow/tasks/__pycache__/ical.cpython-310.pyc
Binary file not shown.
Binary file removed spamoverflow/tasks/__pycache__/scan.cpython-310.pyc
Binary file not shown.
Binary file removed spamoverflow/tasks/__pycache__/spamscan.cpython-310.pyc
Binary file not shown.
67 changes: 0 additions & 67 deletions spamoverflow/tasks/scan.py

This file was deleted.

Binary file modified spamoverflow/views/__pycache__/routes.cpython-310.pyc
Binary file not shown.
45 changes: 3 additions & 42 deletions spamoverflow/views/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import uuid
import re
from sqlalchemy import func
from celery.result import AsyncResult
from spamoverflow.tasks import scan

"""
# Get the directory of the spamhammer and set up spamhammer executable
current_directory = os.path.dirname(os.path.abspath(__file__))
parent_directory = os.path.abspath(os.path.join(current_directory, os.pardir))
binary_name = 'spamhammer.exe'
binary_path = os.path.join(parent_directory, binary_name)
"""


api = Blueprint('api', __name__, url_prefix='/api/v1')

Expand Down Expand Up @@ -182,15 +179,8 @@ def create_email(customer_id):
db.session.add(email)
db.session.commit()

# Create a task for a worker to pick up
scan_url = f"{request.host_url}api/v1/email/scan"
response = requests.post(scan_url, json={"id": id, "email_json": email_json})

#if response.status_code == 202:
# Successfully started the background task
# return jsonify(email.to_dict()), 201
process_email(id, email_json)

#process_email(id, email_json)
return jsonify(email.to_dict()), 201

except Exception as e:
Expand Down Expand Up @@ -295,33 +285,4 @@ def health():
return jsonify({'status': 'Service is healthy'}), 200
except Exception as e:
return jsonify({'error': 'Service is not healthy: {}'.format(str(e))}), 500

@api.route('/email/scan', methods=['POST'])
def create_scan():
data = request.json
task = scan.create_scan.delay(data)

result = {
'task_id': task.id,
'task_url': f'{request.host_url}api/v1/email/scan/{task.id}/status'
}

return jsonify(result), 202

@api.route('/email/scan/<task_id>/status', methods=['GET'])
def get_task(task_id):
task_result = AsyncResult(task_id)
result = {
"task_id": task_id,
"task_status": task_result.status,
"result_url": f'{request.host_url}api/v1/email/scan/{task_id}/result'
}
return jsonify(result), 200

@api.route('/email/scan/<task_id>/result', methods=['GET'])
def get_calendar(task_id):
task_result = AsyncResult(task_id)
if task_result.status == 'SUCCESS':
return task_result.result, 200, {'Content-Type': 'text/calendar'}
else:
return jsonify({'error': 'Task not finished'}), 404

0 comments on commit 6ac24a6

Please # to comment.