-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:uktrade/find-business-regulations i…
…nto ORPD-130-cookie-format
- Loading branch information
Showing
18 changed files
with
348 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# flake8: noqa | ||
import os | ||
import time | ||
|
||
import django | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") | ||
|
||
django.setup() | ||
|
||
from fbr.cache.legislation import Legislation | ||
from fbr.cache.public_gateway import PublicGateway | ||
from fbr.search.config import SearchDocumentConfig | ||
from fbr.search.utils.documents import clear_all_documents | ||
|
||
|
||
def rebuild_cache(): | ||
try: | ||
start = time.time() | ||
clear_all_documents() | ||
config = SearchDocumentConfig(search_query="", timeout=20) | ||
Legislation().build_cache(config) | ||
PublicGateway().build_cache(config) | ||
end = time.time() | ||
return {"message": "rebuilt cache", "duration": round(end - start, 2)} | ||
except Exception as e: | ||
return {"message": f"error clearing documents: {e}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import time | ||
|
||
from celery import shared_task | ||
|
||
from fbr.cache.legislation import Legislation | ||
from fbr.cache.public_gateway import PublicGateway | ||
from fbr.search.config import SearchDocumentConfig | ||
from fbr.search.utils.documents import clear_all_documents | ||
|
||
|
||
@shared_task() | ||
def rebuild_cache(): | ||
try: | ||
start = time.time() | ||
clear_all_documents() | ||
config = SearchDocumentConfig(search_query="", timeout=20) | ||
Legislation().build_cache(config) | ||
PublicGateway().build_cache(config) | ||
end = time.time() | ||
return {"message": "rebuilt cache", "duration": round(end - start, 2)} | ||
except Exception as e: | ||
return {"message": f"error clearing documents: {e}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from celery import Celery | ||
|
||
app = Celery("fbr_celery") | ||
|
||
# Load settings from Django or directly | ||
app.config_from_object("django.conf:settings", namespace="CELERY") | ||
|
||
# Auto-discover tasks in installed apps | ||
app.autodiscover_tasks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django_celery_beat.models import CrontabSchedule, PeriodicTask | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Setup periodic task for rebuilding cache" | ||
|
||
def handle(self, *args, **kwargs): | ||
# Create or get the crontab schedule | ||
schedule, created = CrontabSchedule.objects.get_or_create( | ||
minute="0", hour="1" | ||
) | ||
# Create the periodic task | ||
task, created = PeriodicTask.objects.get_or_create( | ||
crontab=schedule, | ||
name="Rebuild Cache Daily", | ||
task="fbr.cache.tasks.rebuild_cache", | ||
) | ||
if created: | ||
self.stdout.write( | ||
self.style.SUCCESS("Periodic task created successfully.") | ||
) | ||
else: | ||
self.stdout.write( | ||
self.style.WARNING("Periodic task already exists.") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name="fbr", | ||
version="0.1", | ||
packages=find_packages(), | ||
install_requires=[ | ||
# Add your package dependencies here | ||
"requests", | ||
"pandas", | ||
"django", | ||
"dj_database_url", | ||
], | ||
entry_points={ | ||
"console_scripts": [ | ||
# Define command-line scripts here if needed | ||
# e.g., 'my-command = fbr.module:function', | ||
], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.