Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@db_periodic_task(crontab(minute='*/60'))
def updateFinancialItems():
'''
Every hour, create any necessary revenue items and expense items for
activities that need them.
'''
if not getConstant('general__enableCronTasks'):
return
logger.info('Creating automatically-generated financial items.')
if getConstant('financial__autoGenerateExpensesEventStaff'):
createExpenseItemsForEvents()
if getConstant('financial__autoGenerateExpensesVenueRental'):
createExpenseItemsForVenueRental()
if getConstant('financial__autoGenerateRevenueRegistrations'):
createRevenueItemsForRegistrations()
@db_periodic_task(crontab(minute='0,30'))
def scan_public_contracts(scan_all=False):
if (
datetime.time(hour=10, minute=55) <=
datetime.datetime.now(datetime.timezone.utc).time() <=
datetime.time(hour=11, minute=20)
):
return
all_regions = ESI.request('get_universe_regions').data
all_contract_ids = set()
for region in all_regions:
number_of_page = ESI.head(
'get_contracts_public_region_id',
region_id=region
).header['X-Pages'][0]
@db_periodic_task(crontab(day_of_week=0, hour=8, minute=0)) # send 8am every Sunday
def send_summary_emails():
email_count = 0
recipient_count = 0
groups = Group.objects.annotate(member_count=Count('members')).filter(member_count__gt=0)
for group in groups:
from_date, to_date = emails.calculate_group_summary_dates(group)
if not group.sent_summary_up_to or group.sent_summary_up_to < to_date:
email_recipient_count = 0
context = prepare_group_summary_data(group, from_date, to_date)
if context['has_activity']:
@db_periodic_task(crontab(minute='*'))
def send_enqueued_mails():
for m in MailSender.objects.all():
client = m.character.get_client()
while True:
mails = (
Mail.objects
.filter(Q(sender__isnull=True) | Q(sender=m))
.order_by('-priority', 'created')
)
if not mails.exists():
break
mail = mails[0]
@db_periodic_task(crontab(minute='*/60'))
def updateSeriesRegistrationStatus():
'''
Every hour, check if the series that are currently open for registration
should be closed.
'''
from .models import Series
if not getConstant('general__enableCronTasks'):
return
logger.info('Checking status of Series that are open for registration.')
open_series = Series.objects.filter().filter(**{'registrationOpen': True})
for series in open_series:
series.updateRegistrationStatus()
@db_periodic_task(crontab(minute=0)) # we check every hour
def daily_pickup_notifications():
stats_utils.periodic_task('pickups__daily_pickup_notifications')
for group in Group.objects.all():
with timezone.override(group.timezone):
if timezone.localtime().hour is not 20: # only at 8pm local time
continue
for data in fetch_pickup_notification_data_for_group(group):
prepare_pickup_notification_email(**data).send()
stats.pickup_notification_email(
group=data['group'],
**{k: v.count() for k, v in data.items() if isinstance(v, QuerySet)}
)
@db_periodic_task(crontab(minute=0)) # every hour
def record_group_stats():
stats_utils.periodic_task('group__record_group_stats')
points = []
for group in Group.objects.all():
points.extend(stats.get_group_members_stats(group))
points.extend(stats.get_group_stores_stats(group))
write_points(points)
@db_periodic_task(crontab(minute='*/60'))
def clearExpiredTemporaryRegistrations():
'''
Every hour, look for TemporaryRegistrations that have expired and delete them.
To ensure that there are no issues that arise from slight differences between
session expiration dates and TemporaryRegistration expiration dates, only
delete instances that have been expired for one minute.
'''
from .models import TemporaryRegistration
if not getConstant('general__enableCronTasks'):
return
if getConstant('registration__deleteExpiredTemporaryRegistrations'):
TemporaryRegistration.objects.filter(expirationDate__lte=timezone.now() - timedelta(minutes=1)).delete()
call_command('clearsessions')
@db_periodic_task(crontab(hour=2, minute=0)) # 2am every day
def process_inactive_users():
now = timezone.now()
count_users_flagged_inactive = 0
inactive_threshold_date = now - timedelta(days=settings.NUMBER_OF_DAYS_UNTIL_INACTIVE_IN_GROUP)
for membership in GroupMembership.objects.filter(
lastseen_at__lte=inactive_threshold_date,
inactive_at=None,
):
# only send emails if group itself is marked as active
if membership.group.status == GroupStatus.ACTIVE.value:
email = prepare_user_inactive_in_group_email(membership.user, membership.group)
email.send()
membership.inactive_at = now
membership.save()
@db_periodic_task(crontab(minute='0', hour='0'))
def create_models():
for t in ModuleType.objects.all():
try:
create_model_for_type(t)
except Exception:
pass