Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@task
def plugin_ticks(frequency):
log = plugin_ticks.get_logger()
for name, plugin in plugin_registry.iteritems():
if hasattr(plugin['instance'], 'tick_%s'%frequency):
log.debug('Queueing tick_%s task for plugin %s', frequency, name)
plugin_tick.apply_async(args=[frequency, name])
@task
def import_application(app_pk, app_uuid, owner_pk, is_manual_import, is_first_import):
"""
Executed from views.application_register to import packages/versions
in the backend. This is to speedup the UI and offload the AppServer.
@app_pk - int - the application ID
@app_uuid - string - the application UUID
@owner_pk - int - the application owner ID
@is_manual_import - bool - if importing manually
@is_first_import = boot - True if importing for the first time.
"""
# using cache to pass the data parameter to avoid
# reaching SQS message size limit
task_cache = cache_module.get_cache('taskq')
data = task_cache.get(app_uuid)
@task(rate_limit='6/m', ignore_result=True)
def create_screenshot_from_production_link(production_link_id):
try:
prod_link = ProductionLink.objects.get(id=production_link_id)
except ProductionLink.DoesNotExist:
# guess it was deleted in the meantime, then.
return
if prod_link.production.screenshots.count():
# don't create a screenshot if there's one already
if prod_link.is_unresolved_for_screenshotting:
prod_link.is_unresolved_for_screenshotting = False
prod_link.save()
return
if prod_link.has_bad_image:
return # don't create a screenshot if a previous attempt has failed during image processing
@task()
def import_tracks(filesXML, project, trln, request, fileOutputProgress):
"""Import tracks into a selected project"""
numNodes = 0
numSkeletons = 0
#obtan project object
try:
pp = Project.objects.get(title=project.name) #we expect only one
project_id = pp.pk #primary key to insert nodes
except Project.DoesNotExist:
project_id = []
pass
user_id = request.user.id
@task
def handle_delete(sender_content_type_pk, instance_pk):
"""Async task to delete a model from the index.
:param instance_pk:
:param sender_content_type_pk:
"""
from gum.indexer import indexer, NotRegistered
try:
sender_content_type = ContentType.objects.get(pk=sender_content_type_pk)
sender = sender_content_type.model_class()
instance = sender.objects.get(pk=instance_pk)
except ObjectDoesNotExist:
logger.warning("Object ({}, {}) not found".format(sender_content_type_pk, instance_pk))
return None
try:
mapping_type = indexer.get_mapping_type(sender)
mapping_type.delete_document(instance)
@task(ignore_result=True)
def bulk_archive_forms(domain, couch_user, uploaded_data):
# archive using Excel-data
response = archive_forms_old(domain, couch_user.user_id, couch_user.username, uploaded_data)
for msg in response['success']:
logger.info("[Data interfaces] %s", msg)
for msg in response['errors']:
logger.info("[Data interfaces] %s", msg)
html_content = render_to_string('data_interfaces/archive_email.html', response)
send_HTML_email(_('Your archived forms'), couch_user.email, html_content)
@task(name='queue.tasks.mul')
def mul(a,b,callback=None):
r = np.sum(a*b)
if callback:
subtask(callback).delay(r)
@task(serializer='pickle', queue='send_report_throttled', ignore_result=True)
def send_report_throttled(notification_id):
send_report(notification_id)
@task(name="social_auth_account_approved", ignore_result=True)
def send_account_approved_email(user):
"""Sends user email once account is approved by admin"""
subject = '[MyTardis] User account Approved'
message = (
"Hi %s , \n\nWelcome to Store.Monash. "
"Your account has been approved. "
"Please use the \"Sign in with Google\" button on the login page to "
"log in to Store.Monash. "
"If you have an existing Monash account and would like to "
"migrate your data and settings to your new account, "
"follow the instructions on\n\n"
"Thanks,\n"
"MyTardis\n"
% user.username)
try:
from_email = getattr(settings, 'OPENID_FROM_EMAIL', None)
@task(name='tasks.clear_old_links')
def clear_old_links():
'''This task deletes all dynamic links that are more
than one day old'''
logger.debug("Task execute: clearing old dynamic links")
yesterday = date.today()-timedelta(days=1)
Dynpath.objects.filter(created__lt=yesterday).delete()