Skip to content

Commit

Permalink
add check for debug mode in celery tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Suryansh5545 committed Aug 11, 2023
1 parent 595ec30 commit 53e8a4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
42 changes: 23 additions & 19 deletions apps/base/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@
from storages.backends.sftpstorage import SFTPStorage
from django.core.files import File
from django.core.files.base import ContentFile
from django.conf import settings

@shared_task
def export_all_data():
ticket_data = TicketResource().export()
transaction_data = TransactionResource().export()
check_in_data = CheckInResource().export()
storage = SFTPStorage()
if settings.DEBUG:
print("Exporting data to SFTP server task")
else:
ticket_data = TicketResource().export()
transaction_data = TransactionResource().export()
check_in_data = CheckInResource().export()
storage = SFTPStorage()

# Define the remote file path on the SFTP server
ticket_data_path = 'ticket_data.csv'
transaction_data_path = 'transaction_data.csv'
check_in_data_path = 'check_in_data.csv'
# Define the remote file path on the SFTP server
ticket_data_path = 'ticket_data.csv'
transaction_data_path = 'transaction_data.csv'
check_in_data_path = 'check_in_data.csv'

# Save the CSV data to SFTP storage
ticket_csv = ContentFile(ticket_data.csv)
transaction_csv = ContentFile(transaction_data.csv)
check_in_csv = ContentFile(check_in_data.csv)
if ((storage.exists(ticket_data_path)) or (storage.exists(transaction_data_path)) or (storage.exists(check_in_data_path))):
storage.delete(ticket_data_path)
storage.delete(transaction_data_path)
storage.delete(check_in_data_path)
# Save the CSV data to SFTP storage
ticket_csv = ContentFile(ticket_data.csv)
transaction_csv = ContentFile(transaction_data.csv)
check_in_csv = ContentFile(check_in_data.csv)
if ((storage.exists(ticket_data_path)) or (storage.exists(transaction_data_path)) or (storage.exists(check_in_data_path))):
storage.delete(ticket_data_path)
storage.delete(transaction_data_path)
storage.delete(check_in_data_path)

storage.save(ticket_data_path, ticket_csv)
storage.save(transaction_data_path, transaction_csv)
storage.save(check_in_data_path, check_in_csv)
storage.save(ticket_data_path, ticket_csv)
storage.save(transaction_data_path, transaction_csv)
storage.save(check_in_data_path, check_in_csv)

8 changes: 0 additions & 8 deletions settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,4 @@
}
}

SFTP_STORAGE_HOST = getenv("SFTP_STORAGE_HOST", "sftp_storage_host")
SFTP_STORAGE_ROOT = getenv("SFTP_STORAGE_ROOT", "sftp_storage_root")
SFTP_STORAGE_PARAMS = {
'port': getenv("SFTP_STORAGE_PORT", "sftp_storage_port"),
'username': getenv("SFTP_STORAGE_USERNAME", "sftp_storage_username"),
'password': getenv("SFTP_STORAGE_PASSWORD", "sftp_storage_password"),
}

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

0 comments on commit 53e8a4f

Please sign in to comment.