Exemple #1
0
    def _new_function(request, *args, **kwargs):
        try:
            result = function(request, *args, **kwargs)
        except Exception as ex:
            # logdir must be absolute path
            if os.path.abspath(logdir) != logdir:
                raise

            if not os.path.isdir(logdir):
                os.makedirs(logdir)

            # create a file name from function name, date, time and some random characters
            file_name = "%s_%s_%s" % (
                function.__name__,
                datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d_%H-%M-%S"),
                random_string(32),
            )

            # create a file with 0600 perms (log can contain sensitive information like passwords)
            file_path = os.path.join(logdir, file_name)
            fd = os.open(file_path, os.O_CREAT | os.O_WRONLY, 0o600)
            os.write(fd, Traceback().get_traceback())
            os.close(fd)
            raise

        return result
Exemple #2
0
 def save(self, *args, **kwargs):
     if not self.upload_key:
         self.upload_key = random_string(64)
     if self.state == UPLOAD_STATES['FINISHED']:
         if FileUpload.objects.filter(state = UPLOAD_STATES['FINISHED'], name = self.name).exclude(id = self.id).count() != 0:
             # someone created same upload faster
             self.state == UPLOAD_STATES['FAILED']
     super(FileUpload, self).save(*args, **kwargs)
Exemple #3
0
 def save(self, *args, **kwargs):
     if not self.upload_key:
         self.upload_key = random_string(64)
     if self.state == UPLOAD_STATES['FINISHED']:
         if FileUpload.objects.filter(state = UPLOAD_STATES['FINISHED'], name = self.name).exclude(id = self.id).count() != 0:
             # someone created same upload faster
             self.state == UPLOAD_STATES['FAILED']
     super(FileUpload, self).save(*args, **kwargs)
Exemple #4
0
    def save(self, *args, **kwargs):
        # precompute task count, current load and ready
        tasks = Task.objects.opened().filter(worker=self)
        self.task_count = tasks.count()
        self.current_load = sum(( task.weight for task in tasks if not task.waiting ))
        self.ready = self.enabled and (self.current_load < self.max_load and self.task_count < 3*self.max_load)

        while not self.worker_key:
            # if worker_key is empty, generate a new one
            key = random_string(64)
            if Worker.objects.filter(worker_key=key).count() == 0:
                self.worker_key = key
        super(self.__class__, self).save(*args, **kwargs)
Exemple #5
0
 def __init__(self):
     self._variables = []
     self._files = []
     self._boundary = random_string(32)
     self.last_response = None
Exemple #6
0
 def __init__(self):
     self._variables = []
     self._files = []
     self._boundary = random_string(32)
     self.last_response = None