Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@task(name='simple_example', base=QueueOnce)
def simple_example():
return "simple"
@task
def run_sample_sprinkle(**kwargs):
SampleSprinkle.create_sprinkles(**kwargs)
@task
def celery_send_mail(subject, message, from_email, to_email):
send_mail(subject, message, from_email, [to_email])
@task
def _chordfinisher(*args, **kwargs):
"""
Needs to run at the end of a chord to delay the variant parsing step.
http://stackoverflow.com/questions/
15123772/celery-chaining-groups-and-subtasks-out-of-order-execution
"""
return "FINISHED VARIANT FINDING."
@celery.task(ignore_result=True)
def log_event(user_agent, referer, user_ip, created_at, event_type, **kwargs):
"""Log user activity events to the specified 'usage logging'
ElasticSearch index.
:param user_agent: the user's raw user agent string
:type user_agent: str
:param referer: the contents of the HTTP referer request header
:type referer: str or None
:param user_ip: the user's IP address
:type user_ip: str
:param crated_at: the datetime when the event was created (in UTC)
:type created_at: datetime.datetime
:event_type: the name of the event type; available event types are
specified under ``available_event_types``
:param kwargs: any additional arguments will be passed on to the
function responsible for processing the event
@celery.task(bind=True)
def execute_task(self, task, workflow_id, data=None):
""" Celery task that runs a single task on a worker.
Args:
self (Task): Reference to itself, the celery task object.
task (BaseTask): Reference to the task object that performs the work
in its run() method.
workflow_id (string): The unique ID of the workflow run that started this task.
data (MultiTaskData): An optional MultiTaskData object that contains the data
that has been passed down from upstream tasks.
"""
start_time = datetime.utcnow()
store_doc = DataStore(**self.app.user_options['config'].data_store,
auto_connect=True).get(workflow_id)
store_loc = 'log.{}.tasks.{}'.format(task.dag_name, task.name)
@task(ignore_result=True)
def add_notification_for_action(action_id):
action = Action.objects.get(id=action_id)
query = _full_ct_query(action, actor_only=False)
# Don't send notifications to a user about actions they take.
query &= ~Q(user=action.actor)
# execute the above query, iterate through the results, get every user
# assocated with those Follow objects, and fire off a notification to
# every one of them. Use a set to only notify each user once.
users_to_notify = set(f.user for f in Follow.objects.filter(query))
# Don't use bulk save since that wouldn't trigger signal handlers
for u in users_to_notify:
Notification.objects.create(owner=u, action=action)
errors.append(e)
except Exception, e:
_logger.exception(e)
errors.append(e)
# Don't do anything else since we still want to process all the other consumers
error = None
if len(errors) > 0:
error = PulpCodedException(error_code, **error_kwargs)
error.child_exceptions = errors
return TaskResult({}, error, spawned_tasks)
associate = task(ConsumerGroupManager.associate, base=Task, ignore_result=True)
create_consumer_group = task(ConsumerGroupManager.create_consumer_group, base=Task)
delete_consumer_group = task(ConsumerGroupManager.delete_consumer_group, base=Task,
ignore_result=True)
update_consumer_group = task(ConsumerGroupManager.update_consumer_group, base=Task)
unassociate = task(ConsumerGroupManager.unassociate, base=Task, ignore_result=True)
bind = task(ConsumerGroupManager.bind, base=Task)
unbind = task(ConsumerGroupManager.unbind, base=Task)
def validate_existing_consumer_group(group_id):
"""
Validate the existence of a consumer group, given its id.
Returns the consumer group db collection upon successful validation,
raises an exception upon failure
@param group_id: unique id of the consumer group to validate
@type group_id: str
@return: consumer group db collection
@rtype: L{pulp.server.db.connection.PulpCollection}
Exceptions are logged and discarded.
:param path: An absolute path.
:type path: str
"""
try:
if os.path.isfile(path) or os.path.islink(path):
os.unlink(path)
else:
shutil.rmtree(path)
except OSError, e:
_logger.error(_('Delete path: %(p)s failed: %(m)s'), {'p': path, 'm': str(e)})
delete_all_orphans = task(OrphanManager.delete_all_orphans, base=Task)
delete_orphans_by_id = task(OrphanManager.delete_orphans_by_id, base=Task, ignore_result=True)
delete_orphans_by_type = task(OrphanManager.delete_orphans_by_type, base=Task, ignore_result=True)
@task
def build_locale_sitemap(locale):
"""
For the given locale build the appropriate sitemap file and
returns the locale, the file names written and timestamp of the
build.
"""
now = datetime.utcnow()
timestamp = '%s+00:00' % now.replace(microsecond=0).isoformat()
directory = os.path.join(settings.MEDIA_ROOT, 'sitemaps', locale)
if not os.path.isdir(directory):
os.makedirs(directory)
# Add any non-document URL's, which will always include the home page.
other_urls = [
{