Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@periodic_task(crontab(minute='*/2'))
def every_other_minute():
tprint('This task runs every 2 minutes.', 35)
@huey.periodic_task(crontab(hour='3', minute=str(30 + random.randrange(-30, +30))))
def download_wsusscan_crontab():
descr = make_dl_task_descr()
return download_wsusscan(task_descr=descr)
from app.persistence.events_manager import get_all_events, add_scrambles_to_scramble_pool
from app.util.events.resources import get_event_resource_for_name, EVENT_COLL
from . import huey
from .admin_notification import notify_admin, AdminNotificationType
# -------------------------------------------------------------------------------------------------
ScramblePoolTopOffInfo = namedtuple('ScramblePoolTopOffInfo', ['event_id', 'event_name', 'num_scrambles'])
# In dev environments, run the task to check the scramble pool every minute.
# In prod, run it every hour (frequently enough so that new events get populated with scrambles quickly)
if app.config['IS_DEVO']:
CHECK_SCRAMBLE_POOL_SCHEDULE = crontab(minute="*/1") # Once every minute
else:
CHECK_SCRAMBLE_POOL_SCHEDULE = crontab(hour="*/1", minute="0") # Once every hour
# -------------------------------------------------------------------------------------------------
@huey.periodic_task(CHECK_SCRAMBLE_POOL_SCHEDULE)
def check_scramble_pool():
""" A periodic task to check the pre-generated pool of scrambles for all events. If the pool
is too low for any event, enqueue a task to generate more scrambles for those events. """
event_scramble_msgs = list()
for event in get_all_events():
# Don't pre-generate COLL scrambles. The fact we need a specific COLL each week, and that
# rotates weekly, makes this more difficult than it needs to be. We'll just generate them
# on the fly during competition generation, since it's fast anyway
if event.name == EVENT_COLL.name:
@db_periodic_task(crontab(minute='0', hour='*/12'))
def read_all_assets():
for x in EveUser.objects.filter(scope_read_assets=True):
read_assets_for_character(x)
@db_periodic_task(crontab(minute="*"))
def dispatch_push_tasks():
generic_push_targets = GenericPushTarget.objects.filter(status=GenericPushTarget.STATUS_ACTIVE).all()
brewers_friend_push_targets = BrewersFriendPushTarget.objects.filter(status=BrewersFriendPushTarget.STATUS_ACTIVE).all()
brewfather_push_targets = BrewfatherPushTarget.objects.filter(status=BrewfatherPushTarget.STATUS_ACTIVE).all()
# Run through the list of generic push targets and trigger a (future) data send for each
for target in generic_push_targets:
if timezone.now() >= (target.last_triggered + datetime.timedelta(seconds=target.push_frequency)):
target.last_triggered = timezone.now()
target.save()
# Queue the generic_push_target_push task (going to do it asynchronously)
generic_push_target_push(target.id)
# Run through the list of Brewer's Friend push targets and trigger a (future) data send for each
for target in brewers_friend_push_targets:
@db_periodic_task(crontab(minute='*'))
def sendReminderEmails():
if not getConstant('general__enableCronTasks'):
return
reminders_needed = EventReminder.objects.filter(**{
'time__lte': timezone.now(),
'completed':False,
'notifyList__isnull': False})
if reminders_needed:
for note in reminders_needed:
for user in note.notifyList.all():
sent = sendReminderEmailToUser(user,note)
if sent:
# Mark reminder as sent so it won't be sent twice.
note.completed = True