Raise ValidationError("Incorrect cron expression:\ Iter = croniter(cron_expression, datetime.now()) Help_texts = Ĭleaned_data = super(ScheduledReportForm, self).clean()Ĭron_expression = cleaned_data.get("cron_expression") We are going to hide the last_run_at and next_run_at from the user as it would be irrelevant to them.įrom django.forms import ModelForm, ValidationError We will be creating a custom form so that we can validate that the cron expression entered by the user is valid. The administrator can schedule the reports from the admin interface by entering a cron expression, based on which the reports will be sent out. Scheduled_report = models.ForeignKey(ScheduledReport, related_name='reportrecep') Stores all the recipients of the given scheduled report Scheduled_report = models.ForeignKey(ScheduledReport, Report = models.ForeignKey(Report, related_name='report') ![]() Many to many mapping between reports which will be sent out in a Super(ScheduledReport, self).save(*args, **kwargs)Ĭlass ScheduledReportGroup(models.Model): Self.next_run_at = iter.get_next(datetime) Iter = croniter(self.cron_expression, self.last_run_at) Next_run_at = models.DateTimeField(null=True, blank=True)Ĭron_expression = models.CharField(max_length=200)įunction to evaluate "next_run_at" using the cron expression, so that it is updated once the report is sent. Last_run_at = models.DateTimeField(null=True, blank=True) Subject = models.CharField(max_length=200) class ScheduledReport(models.Model):Ĭontains email subject and cron expression,to evaluate when the email has to be sent We need the administrator of the app to customize the reports scheduling using cron expressions, to evaluate the cron expressions we are using croniter. # Django starts so that shared_task will use this app. # This will make sure celery is always imported when To ensure this import your celery instance in project/project/init.pyįrom _future_ import absolute_import, unicode_literals Now we need to make sure that celery is loaded when your Django application starts. # Load task modules from all registered Django app configs.Īpp.autodiscover_tasks(lambda: settings.INSTALLED_APPS) # the configuration object to child processes.Īpp.config_from_object('nf:settings') # Using a string here means the worker don't have to serialize ![]() Os.tdefault('DJANGO_SETTINGS_MODULE', 'ttings') # set the default Django settings module for the 'celery' program. ![]() Specify which broker you will use, we are using django's broker for developmentĬELERY_RESULT_BACKEND = ':DatabaseBackend'ĬELERYBEAT_SCHEDULER = ""Īssuming this is your project structure, we will create a Celery instance in the project folder called celeryapp.py.ĭefine your celery instance in project/project/celeryapp.py Adding Django celery configuration in settings.py:
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |