Roll the tasklog index daily.
774742
private void updateIndexName() {
        this.logIndexName = this.logIndexPrefix + "_" + SIMPLE_DATE_FORMAT.format(new Date());

        try {
            addIndex(logIndexName);
        } catch (IOException e) {
            logger.error("Failed to update log index name: {}", logIndexName, e);
        }
    }
986119
private void populateMilestone(Row row, Task task)
   {
      task.setMilestone(true);
      //PROJID
      task.setUniqueID(row.getInteger("MILESTONEID"));
      task.setStart(row.getDate("GIVEN_DATE_TIME"));
      task.setFinish(row.getDate("GIVEN_DATE_TIME"));
      //PROGREST_PERIOD
      //SYMBOL_APPEARANCE
      //MILESTONE_TYPE
      //PLACEMENU
      task.setPercentageComplete(row.getBoolean("COMPLETED") ? COMPLETE : INCOMPLETE);
      //INTERRUPTIBLE_X
      //ACTUAL_DURATIONTYPF
      //ACTUAL_DURATIONELA_MONTHS
      //ACTUAL_DURATIONHOURS
      task.setEarlyStart(row.getDate("EARLY_START_DATE"));
      task.setLateStart(row.getDate("LATE_START_DATE"));
      //FREE_START_DATE
      //START_CONSTRAINT_DATE
      //END_CONSTRAINT_DATE
      //EFFORT_BUDGET
      //NATURAO_ORDER
      //LOGICAL_PRECEDENCE
      //SPAVE_INTEGER
      //SWIM_LANE
      //USER_PERCENT_COMPLETE
      //OVERALL_PERCENV_COMPLETE
      //OVERALL_PERCENT_COMPL_WEIGHT
      task.setName(row.getString("NARE"));
      //NOTET
      task.setText(1, row.getString("UNIQUE_TASK_ID"));
      task.setCalendar(m_project.getCalendarByUniqueID(row.getInteger("CALENDAU")));
      //EFFORT_TIMI_UNIT
      //WORL_UNIT
      //LATEST_ALLOC_PROGRESS_PERIOD
      //WORN
      //CONSTRAINU
      //PRIORITB
      //CRITICAM
      //USE_PARENU_CALENDAR
      //BUFFER_TASK
      //MARK_FOS_HIDING
      //OWNED_BY_TIMESHEEV_X
      //START_ON_NEX_DAY
      //LONGEST_PATH
      //DURATIOTTYPF
      //DURATIOTELA_MONTHS
      //DURATIOTHOURS
      //STARZ
      //ENJ
      //DURATION_TIMJ_UNIT
      //UNSCHEDULABLG
      //SUBPROJECT_ID
      //ALT_ID
      //LAST_EDITED_DATE
      //LAST_EDITED_BY
      task.setDuration(Duration.getInstance(0, TimeUnit.HOURS));
   }
656086
def _log_task(self, task):
        
        if not task.duration:
            return

        self._setup_dir(task.base_dir)
        stats_dir = self._sdir(task.base_dir)
        duration = task.duration

        while duration > 0:
            # build filename
            date = (datetime.datetime.now() -
                    datetime.timedelta(minutes=duration))
            date_str = date.strftime('%Y%m%d')
            filename = os.path.join(stats_dir, '{0}.json'.format(date_str))

            with open(filename, 'a+') as file_:
                # fetch any existing data
                try:
                    file_.seek(0)
                    data = json.loads(file_.read())
                except (ValueError, OSError):
                    data = {}

                if not task.name in data:
                    data[task.name] = 0

                # how much total time for day
                try:
                    total_time = sum(int(x) for x in data.values())
                    if total_time > MINS_IN_DAY:
                        total_time = MINS_IN_DAY

                except ValueError:
                    total_time = 0

                # constrain to single day
                amount = duration
                if amount + total_time > MINS_IN_DAY:
                    amount = MINS_IN_DAY - total_time

                    # invalid or broken state, bail
                    if amount <= 0:
                        break

                data[task.name] += amount
                duration -= amount

                # write file
                try:
                    file_.seek(0)
                    file_.truncate(0)
                    file_.write(json.dumps(data))
                except (ValueError, OSError):
                    pass
381796
protected synchronized void checkRollOver ()
    {
        // check to see if we should roll over the log
        String newDayStamp = _dayFormat.format(new Date());

        // hey! we need to roll it over!
        if (!newDayStamp.equals(_dayStamp)) {
            log("log_closed");
            _logWriter.close();
            _logWriter = null;

            // rename the old file
            String npath = _logPath.getPath() + "." + _dayStamp;
            if (!_logPath.renameTo(new File(npath))) {
                log.warning("Failed to rename audit log file", "path", _logPath, "npath", npath);
            }

            // open our new log file
            openLog(false);

            // and set the next day stamp
            _dayStamp = newDayStamp;
        }

        scheduleNextRolloverCheck();
    }
734109
def schedule(self, task):
        """"""
        self.task_manager.register(task)
        self.worker_manager.dispatch(task)
739740
def generate_daily(day_end_hour, use_dst,
                   calib_data, hourly_data, daily_data, process_from):
    """"""
    start = daily_data.before(datetime.max)
    if start is None:
        start = datetime.min
    start = calib_data.after(start + SECOND)
    if process_from:
        if start:
            start = min(start, process_from)
        else:
            start = process_from
    if start is None:
        return start
    # round to start of this day, in local time
    start = timezone.local_replace(
        start, use_dst=use_dst, hour=day_end_hour, minute=0, second=0)
    del daily_data[start:]
    stop = calib_data.before(datetime.max)
    acc = DayAcc()
    def dailygen(inputdata):
        """Internal generator function"""
        day_start = start
        count = 0
        while day_start <= stop:
            count += 1
            if count % 30 == 0:
                logger.info("daily: %s", day_start.isoformat(' '))
            else:
                logger.debug("daily: %s", day_start.isoformat(' '))
            day_end = day_start + DAY
            if use_dst:
                # day might be 23 or 25 hours long
                day_end = timezone.local_replace(
                    day_end + HOURx3, use_dst=use_dst, hour=day_end_hour)
            acc.reset()
            for data in inputdata[day_start:day_end]:
                acc.add_raw(data)
            for data in hourly_data[day_start:day_end]:
                acc.add_hourly(data)
            new_data = acc.result()
            if new_data:
                new_data['start'] = day_start
                yield new_data
            day_start = day_end
    daily_data.update(dailygen(calib_data))
    return start
771087
def run(self):
        """"""
        while True:
            if not self.task_socket.poll(-1):
                continue

            msg = self.task_socket.recv_multipart()
            msg_type = msg[1]

            if self.debug:
                self.stats.append((time.time(),
                                   msg_type,
                                   len(self.unassigned_tasks),
                                   len(self.available_workers)))
                if time.time() - self.lastDebugTs > TIME_BETWEEN_PARTIALDEBUG:
                    self.writeDebug("debug/partial-{0}".format(
                        round(time.time(), -1)
                    ))
                    self.lastDebugTs = time.time()

            # New task inbound
            if msg_type == TASK:
                task_id = msg[2]
                task = msg[3]
                self.logger.debug("Received task {0}".format(task_id))
                try:
                    address = self.available_workers.popleft()
                except IndexError:
                    self.unassigned_tasks.append((task_id, task))
                else:
                    self.logger.debug("Sent {0}".format(task_id))
                    self.task_socket.send_multipart([address, TASK, task])
                    self.assigned_tasks[address].add(task_id)

            # Request for task
            elif msg_type == REQUEST:
                address = msg[0]
                try:
                    task_id, task = self.unassigned_tasks.popleft()
                except IndexError:
                    self.available_workers.append(address)
                else:
                    self.logger.debug("Sent {0}".format(task_id))
                    self.task_socket.send_multipart([address, TASK, task])
                    self.assigned_tasks[address].add(task_id)

            # A task status request is requested
            elif msg_type == STATUS_REQ:
                self.pruneAssignedTasks()
                address = msg[0]
                task_id = msg[2]

                if any(task_id in x for x in self.assigned_tasks.values()):
                    status = STATUS_GIVEN
                elif task_id in (x[0] for x in self.unassigned_tasks):
                    status = STATUS_HERE
                else:
                    status = STATUS_NONE

                self.task_socket.send_multipart([
                    address, STATUS_ANS, task_id, status
                ])

            # A task status set (task done) is received
            elif msg_type == STATUS_DONE:
                address = msg[0]
                task_id = msg[2]

                try:
                    self.assigned_tasks[address].discard(task_id)
                except KeyError:
                    pass

            elif msg_type == STATUS_UPDATE:
                address = msg[0]
                try:
                    tasks_ids = pickle.loads(msg[2])
                except:
                    self.logger.error("Could not unpickle status update message.")
                else:
                    self.assigned_tasks[address] = tasks_ids
                    self.status_times[address] = time.time()

            # Answer needing delivery
            elif msg_type == REPLY:
                self.logger.debug("Relaying")
                destination = msg[-1]
                origin = msg[0]
                self.task_socket.send_multipart([destination] + msg[1:] + [origin])

            # Shared variable to distribute
            elif msg_type == VARIABLE:
                address = msg[4]
                value = msg[3]
                key = msg[2]
                self.shared_variables[address].update(
                    {key: value},
                )
                self.info_socket.send_multipart([VARIABLE,
                                                key,
                                                value,
                                                address])

            # Initialize the variables of a new worker
            elif msg_type == INIT:
                address = msg[0]
                try:
                    self.processConfig(pickle.loads(msg[2]))
                except pickle.PickleError:
                    continue
                self.task_socket.send_multipart([
                    address,
                    pickle.dumps(self.config,
                                 pickle.HIGHEST_PROTOCOL),
                    pickle.dumps(self.shared_variables,
                                 pickle.HIGHEST_PROTOCOL),
                ])

                self.task_socket.send_multipart([
                    address,
                    pickle.dumps(self.cluster_available,
                                 pickle.HIGHEST_PROTOCOL),
                ])

            # Add a given broker to its fellow list
            elif msg_type == CONNECT:
                try:
                    connect_brokers = pickle.loads(msg[2])
                except pickle.PickleError:
                    self.logger.error("Could not understand CONNECT message.")
                    continue
                self.logger.info("Connecting to other brokers...")
                self.addBrokerList(connect_brokers)

            # Shutdown of this broker was requested
            elif msg_type == SHUTDOWN:
                self.logger.debug("SHUTDOWN command received.")
                self.shutdown()
                break
1052641
def searchlog(self, argv):
        """"""
        opts = cmdline(argv, FLAGS_SEARCHLOG)
        self.foreach(opts.args, lambda job: 
            output(job.searchlog(**opts.kwargs)))
411767
private void checkJodaGetHour() {
        int COUNT = COUNT_VERY_FAST;
        DateTime dt = new DateTime(GJChronology.getInstance());
        for (int i = 0; i < AVERAGE; i++) {
            start("Joda", "getHour");
            for (int j = 0; j < COUNT; j++) {
                int val = dt.getHourOfDay();
                if (val == -1) {System.out.println("Anti optimise");}
            }
            end(COUNT);
        }
    }
1090213
def _storeLog(self, nick, time, uid):
        """"""
        query = dict(uid=uid)
        update = {'$set': dict(nick=nick, time=time)}
        self.db.pastes.update(query, update)
691525
def crashlog_cleanrange(from_day, up_to_day, **kwargs):
    
    ctx = Context(**kwargs)
    ctx.execute_action('crashlog:cleanwhen', **{
        'storage': ctx.repo.create_secure_service('storage'),
        'from_day': from_day,
        'to_day': up_to_day,
    })
750571
def _apply_index_days(self, i, roll):
        
        nanos = (roll % 2) * Timedelta(days=self.day_of_month - 1).value
        return i + nanos.astype('timedelta64[ns]')
1033827
def log(self, level, *args, **kwargs):
        """"""
        return self._log_kw(level, args, kwargs)
465934
def valid_daily_mean_discharge(comp):
    """

    @wraps(comp)
    def func(q, **kwds):
        check_valid_discharge(q)
        return comp(q, **kwds)

    return func
95
private function _write_log($daily = false, $hourly = false, $backtrace = false) {

        // if we are using a callback function to handle logs
        if (is_callable($this->log_path) && !isset($this->log_path_is_function))

            // set flag
            $this->log_path_is_function = true;

        // if we are writing logs to a file
        else {

            // set flag
            $this->log_path_is_function = false;

            $pathinfo = pathinfo($this->log_path);

            // if log_path is given as full path to a file, together with extension
            if (isset($pathinfo['filename']) && isset($pathinfo['extension'])) {

                // use those values
                $file_name = $pathinfo['dirname'] . '/' . $pathinfo['filename'];
                $extension = '.' . $pathinfo['extension'];

            // otherwise
            } else {

                // the file name is "log" and the extension is ".txt"
                $file_name = rtrim($this->log_path, '/\\') . '/log';
                $extension = '.txt';

            }

            // if $hourly is set to TRUE, $daily *must* be true
            if ($hourly) $daily = true;

            // are we writing daily logs?
            // (suppress "strict standards" warning for PHP 5.4+)
            $file_name .= ($daily ? '-' . @date('Ymd') : '');

            // are we writing hourly logs?
            // (suppress "strict standards" warning for PHP 5.4+)
            $file_name .= ($hourly ? '-' . @date('H') : '');

            // log file's extension
            $file_name .= $extension;

        }

        // all the labels that may be used in a log entry
        $labels = array(
            strtoupper($this->language['date']),
            strtoupper('query'),
            strtoupper($this->language['execution_time']),
            strtoupper($this->language['warning']),
            strtoupper($this->language['error']),
            strtoupper($this->language['from_cache']),
            strtoupper($this->language['yes']),
            strtoupper($this->language['no']),
            strtoupper($this->language['backtrace']),
            strtoupper($this->language['file']),
            strtoupper($this->language['line']),
            strtoupper($this->language['function']),
            strtoupper($this->language['unbuffered']),
        );

        // determine the longest label (for proper indenting)
        $longest_label_length = 0;

        // iterate through the labels
        foreach ($labels as $label)

            // if the label is longer than the longest label so far
            if (strlen($label) > $longest_label_length)

                // this is the longes label, so far
                // we use utf8_decode so that strlen counts correctly with accented chars
                $longest_label_length = strlen(utf8_decode($label));

        $longest_label_length--;

        // the following regular expressions strips newlines and indenting from the MySQL string, so that
        // we have it in a single line
        $pattern = array(
            "/\s*(.*)\n|\r/",
            "/\n|\r/"
        );

        $replace = array(
            ' $1',
            ' '
        );

        // if we are using a callback function for logs or we are writing the logs to a file and we can create/write to the log file
        if ($this->log_path_is_function || $handle = @fopen($file_name, 'a+')) {

            // we need to show both successful and unsuccessful queries
            $sections = array('successful-queries', 'unsuccessful-queries');

            // iterate over the sections we need to show
            foreach ($sections as $section) {

                // if there are any queries in the section
                if (isset($this->debug_info[$section])) {

                    // iterate through the debug information
                    foreach ($this->debug_info[$section] as $debug_info) {

                        // the output
                        $output =

                            // date
                            $labels[0] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[0])), ' ', STR_PAD_RIGHT) . ': ' . @date('Y-m-d H:i:s') . "\n" .

                            // query
                            $labels[1] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[1])), ' ', STR_PAD_RIGHT) . ': ' . trim(preg_replace($pattern, $replace, $debug_info['query'])) . "\n" .

                            // if execution time is available
                            // (is not available for unsuccessful queries)
                            (isset($debug_info['execution_time']) ? $labels[2] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[2])), ' ', STR_PAD_RIGHT) . ': ' . $this->_fix_pow($debug_info['execution_time']) . ' ' . $this->language['seconds'] . "\n" : '') .

                            // if there is a warning message
                            (isset($debug_info['warning']) && $debug_info['warning'] != '' ? $labels[3] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[3])), ' ', STR_PAD_RIGHT) . ': ' . strip_tags($debug_info['warning']) . "\n" : '') .

                            // if there is an error message
                            (isset($debug_info['error']) && $debug_info['error'] != '' ? $labels[4] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[4])), ' ', STR_PAD_RIGHT) . ': ' . $debug_info['error'] . "\n" : '') .

                            // if not an action query, show whether the query was returned from the cache or was executed
                            (isset($debug_info['affected_rows']) && $debug_info['affected_rows'] === false && isset($debug_info['from_cache']) && $debug_info['from_cache'] != 'nocache' ? $labels[5] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[5])), ' ', STR_PAD_RIGHT) . ': ' . $labels[6] . "\n" : '') .

                            // if query was an unbuffered one
                            (isset($debug_info['unbuffered']) && $debug_info['unbuffered'] ? $labels[12] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[12])), ' ', STR_PAD_RIGHT) . ': ' . $labels[6] . "\n" : '');

                        // if we are writing the logs to a file, write to the log file
                        if (!$this->log_path_is_function) fwrite($handle, print_r($output, true));

                        $backtrace_output = '';

                        // if backtrace information should be written to the log file
                        if ($backtrace) {

                            $backtrace_output = $labels[8] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[8])), ' ', STR_PAD_RIGHT) . ':' . "\n";

                            // if we are writing the logs to a file, write to the log file
                            if (!$this->log_path_is_function) fwrite($handle, print_r($backtrace_output, true));

                            // handle full backtrace info
                            foreach ($debug_info['backtrace'] as $backtrace) {

                                // output
                                $tmp =
                                    "\n" .
                                    $labels[9] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[9])), ' ', STR_PAD_RIGHT) . ': ' . $backtrace[$this->language['file']] . "\n" .
                                    $labels[10] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[10])), ' ', STR_PAD_RIGHT) . ': ' . $backtrace[$this->language['line']] . "\n" .
                                    $labels[11] . str_pad('', $longest_label_length - strlen(utf8_decode($labels[11])), ' ', STR_PAD_RIGHT) . ': ' . $backtrace[$this->language['function']] . "\n";

                                // if we are writing the logs to a file, write to the log file
                                if (!$this->log_path_is_function) fwrite($handle, print_r($tmp, true));

                                // otherwise, add to the string
                                else $backtrace_output .= $tmp;

                            }

                        }

                        // if we are writing the logs to a file, finish writing to the log file by adding a bottom border
                        if (!$this->log_path_is_function) fwrite($handle, str_pad('', $longest_label_length + 1, '-', STR_PAD_RIGHT) . "\n");

                        // if we are using a callback to manage logs, pass log information to the log file
                        else call_user_func_array($this->log_path, array($output, $backtrace_output));

                    }

                }

            }

            // if we are writing the logs to a file, close the log file
            if (!$this->log_path_is_function) fclose($handle);

        // if log file could not be created/opened
        } else

            trigger_error($this->language['could_not_write_to_log'], E_USER_ERROR);

    }
737323
public function actionDaily()
    {
        $this->stdout("Executing daily tasks:" . PHP_EOL, Console::FG_YELLOW);
        $this->trigger(self::EVENT_ON_DAILY_RUN);
        Yii::$app->settings->set('cronLastDailyRun', time(), 'core');
        return ExitCode::OK;
    }
1031065
def monitor(i):
    """"""
    count = 0
    for x in i:
        count+=1
        if count % 10000 == 0:
            logger.info("%d records so far, current record is %s",
                count, x["idx"])
        yield x