Пример #1
0
def tick(request):
    queue = taskqueue.Queue('atpostspud-getspuds')
    task = taskqueue.Task(
        url='/socialengine/postspud/get_latest_at_post_spuds', method='GET')
    queue.add(task)
    return HttpResponse(json.dumps({'status': 'ok'}),
                        content_type='application/json')
Пример #2
0
def send_invoices(request):
    try:
        task = taskqueue.Task(url=reverse(invoices_task), params={"action": InvoiceActions.SEND})
        q = taskqueue.Queue("billing")
        q.add(task)
        return HttpResponse("Task Added")
    except Exception, e:
        return HttpResponse("FAILED: %s" % e.message)
Пример #3
0
def get_latest_at_post_spuds_view(request):
    dev = request.GET.get('dev', None)
    if dev:
        get_latest_at_post_spuds(dev)
    else:
        get_latest_at_post_spuds()
        queue = taskqueue.Queue('atpostspud-getspuds')
        queue.purge()
        return HttpResponse(json.dumps({'status': 'ok'}),
                            content_type='application/json')
Пример #4
0
 def get(self):
     current = self.request.get("current")
     to_delete = self.request.get("key")
     to_delete_key = ndb.Key(urlsafe=to_delete)
     being_deleted = to_delete_key.get()
     taskqueue.Queue().delete_tasks_by_name(
         being_deleted.get_task_name() +
         being_deleted.time.strftime("%m%d%Y%I%M"))
     to_delete_key.delete()
     self.redirect('/'.join(self.request.referer.split("/")[:3]) +
                   "?route=" + str(current))
Пример #5
0
 def post(self):
     payload = json.loads(self.request.body)
     urlsafe_entity_key = payload["urlsafe_entity_key"]
     notification_key = ndb.Key(urlsafe=urlsafe_entity_key)
     notification_utils.send_notification_for_event_key(notification_key)
     notification = notification_key.get()
     notification.is_in_task_queue = False
     notification.put()
     taskqueue.Queue().delete_tasks_by_name(notification.get_task_name())
     if notification.type == 0:
         notification.type = 2
         notification.put()
     else:
         notification_utils.add_notification_to_task_queue(notification)
Пример #6
0
def run_maintenance_task(request):
    base_name = 'maintenance-task'
    name = request.GET.get("name", base_name)
    task = taskqueue.Task(url=reverse(maintenance_task), name=name)
    q = taskqueue.Queue('maintenance')
    response = HttpResponse("Task Added")
    try:
        q.add(task)
    except TombstonedTaskError:
        response = HttpResponseRedirect(
            url_with_querystring(reverse(run_maintenance_task),
                                 name="%s-%s" % (base_name, get_unique_id())))
    except TaskAlreadyExistsError:
        response = HttpResponse("Task not added: TaskAlreadyExistsError")
    except DuplicateTaskNameError:
        response = HttpResponse("Task not added: DuplicateTaskNameError")

    return response
Пример #7
0
def log_connection_events(sender, signal_type, obj, **kwargs):
    from common.tz_support import utc_now
    from django.core.urlresolvers import reverse
    from google.appengine.api.taskqueue import taskqueue
    from analytics.models import AnalyticsEvent
    from common.util import log_event, EventType, notify_by_email
    from ordering.signals import SignalType
    from ordering.station_connection_manager import ALERT_DELTA, handle_dead_workstations

    last_event_qs = AnalyticsEvent.objects.filter(
        work_station=obj,
        type__in=[EventType.WORKSTATION_UP,
                  EventType.WORKSTATION_DOWN]).order_by('-create_date')[:1]
    station = obj.station

    if signal_type == SignalType.WORKSTATION_ONLINE:
        if last_event_qs:
            # send workstation reconnect mail
            last_event = last_event_qs[0]
            if last_event.type == EventType.WORKSTATION_DOWN and (
                    utc_now() - last_event.create_date
            ) >= ALERT_DELTA and station.show_on_list:
                msg = u"Workstation is up again:\n\tid = %d station = %s" % (
                    obj.id, obj.dn_station_name)
                notify_by_email(u"Workstation Reconnected", msg=msg)
        elif station.show_on_list:
            # send "new workstation" mail
            msg = u"A new workstation just connected: id = %d station = %s" % (
                obj.id, obj.dn_station_name)
            notify_by_email(u"New Workstation", msg=msg)

        log_event(EventType.WORKSTATION_UP, station=station, work_station=obj)

    elif signal_type == SignalType.WORKSTATION_OFFLINE:
        log_event(EventType.WORKSTATION_DOWN,
                  station=station,
                  work_station=obj)

        if station.show_on_list:
            # add task to check if workstation is still dead after ALERT_DELTA
            task = taskqueue.Task(url=reverse(handle_dead_workstations),
                                  countdown=ALERT_DELTA.seconds + 1,
                                  params={"workstation_id": obj.id})
            taskqueue.Queue('log-events').add(task)
Пример #8
0
    def _log(self, level, message, *args, **kwargs):
        """ Logs the message to the normal logging module and also queues a Task to create an _FantasmLog

        @param level:
        @param message:
        @param args:
        @param kwargs:

        NOTE: we are not not using deferred module to reduce dependencies, but we are re-using the helper
              functions .serialize() and .run() - see handler.py
        """
        if not (self.level <= level <= self.maxLevel):
            return

        namespace = kwargs.pop('namespace', None)
        tags = kwargs.pop('tags', None)

        self.getLoggingMap()[level](message, *args, **kwargs)

        if not self.persistentLogging:
            return

        stack = None
        if 'exc_info' in kwargs:
            f = StringIO.StringIO()
            traceback.print_exc(25, f)
            stack = f.getvalue()

        # this _log method requires everything to be serializable, which is not the case for the logging
        # module. if message is not a basestring, then we simply cast it to a string to allow _something_
        # to be logged in the deferred task
        if not isinstance(message, basestring):
            try:
                message = str(message)
            except Exception:
                message = LOG_ERROR_MESSAGE
                if args:
                    args = []
                logging.warning(message, exc_info=True)

        taskName = (self.__obj or {}).get(constants.TASK_NAME_PARAM)

        stateName = None
        if self.context.currentState:
            stateName = self.context.currentState.name

        transitionName = None
        if self.context.startingState and self.context.startingEvent:
            transitionName = self.context.startingState.getTransition(
                self.context.startingEvent).name

        actionName = None
        if self.context.currentAction:
            actionName = self.context.currentAction.__class__.__name__

        # in immediateMode, tack the messages onto obj so that they can be returned
        # in the http response in handler.py
        if self.__obj is not None:
            if self.__obj.get(constants.IMMEDIATE_MODE_PARAM):
                try:
                    self.__obj[constants.MESSAGES_PARAM].append(message % args)
                except TypeError:
                    self.__obj[constants.MESSAGES_PARAM].append(message)

        serialized = deferred.serialize(
            _log,
            taskName,
            self.context.instanceName,
            self.context.machineName,
            stateName,
            actionName,
            transitionName,
            level,
            namespace,
            (self.tags or []) + (tags or []),
            message,
            stack,
            datetime.datetime.now(),  # FIXME: called .utcnow() instead?
            *args,
            **kwargs)

        try:
            task = taskqueue.Task(
                url=constants.DEFAULT_LOG_URL,
                payload=serialized,
                retry_options=taskqueue.TaskRetryOptions(task_retry_limit=20))
            # FIXME: a batch add may be more optimal, but there are quite a few more corners to deal with
            taskqueue.Queue(name=constants.DEFAULT_LOG_QUEUE_NAME).add(task)

        except taskqueue.TaskTooLargeError:
            logging.warning(
                "fantasm log message too large - skipping persistent storage")

        except taskqueue.Error:
            logging.warning(
                "error queuing log message Task - skipping persistent storage",
                exc_info=True)
Пример #9
0
def run_gcp_service_test(request):
    task = taskqueue.Task(url=reverse(test_gcp_service_task))
    q = taskqueue.Queue('maintenance')
    q.add(task)

    return HttpResponse("Task Added")