Question 20
Suppose you are building an application which requires sending emails to all the users stored in the database at regular intervals. Given below are the two approaches to satisfy the requirement.
Approach 1:
@celery.taskdef send_bulk_emails(): all_users = User.query.all() // Get all the user objects from thedatabase for user in all_users: // send email to the user
send_bulk_emails.delay() // invokes celery taskApproach 2:
@celery.taskdef send_email(email): // send email to the user
all_users = User.query.all() // Get all the user objects from the databasefor user in all_users: send_email.delay(user.email) // invokes celery taskChoose the correct statement(s).
Approach 1 will take more time than approach 2, if more than 2 celery workers are available.
Approach 2 will take more time than approach 1, if more than 2 celery workers are available.
Both the approaches will take same time (approx), if only 1 celery worker is available.
None of these