Beispiel #1
0
def expire_activity_later(aid):
    """
    Later version of the above, to be called at the activity when datetime
    """
    logger.warning('expire_activity_later aid:%s' % str(aid))
    activity = Activity.objects.get(id=aid)
    if activity.status == Activity.EXPIRED:
        return 'Activity %s already expired' % str(aid)
    activity.expire()
    activity.save()
#    notification_tasks.no_confirms(aid)
    Metric.add_activity_metric(activity)
    return 'Activity later %s expired successfully' % str(aid)
Beispiel #2
0
def expire_activity_default(aid):
    """
    Called when the activity is due to expire and expires it
    Also adds the activity keener metrics to the Metric store
    """
    activity = Activity.objects.get(id=aid)
    if activity.status == Activity.EXPIRED:
        logger.warning('Activity %s already expired' % str(aid))
        return 'Activity %s already expired' % str(aid)
    if activity.is_confirmed() and not activity.when:
        return "Default expiry on %s not applied, as will be pulled by a later task" % str(aid)
    now = datetime.datetime.now()
    diff = activity.expiry - now
    if diff.total_seconds() <= 120: #If the activity is meant to be expired in teh next 2 mins we do it
        activity.expire()
        activity.save()
        Metric.add_activity_metric(activity)
#        notification_tasks.no_confirms(aid)
        return 'Activity default %s expired successfully' % str(aid)
    else:
        #Otherwise we don't and we set a new task to run at the correct time
        expire_activity_default.apply_async(args=[aid], eta=activity.expiry)