<commit_before>import { isAnyTest, onStartup, runAfterDelay } from '../lib/executionEnvironment';
import { SyncedCron } from './vendor/synced-cron/synced-cron-server';

SyncedCron.options = {
  log: true,
  collectionName: 'cronHistory',
  utc: false,
  collectionTTL: 172800
};

export function addCronJob(options: {
  name: string,
  interval?: string,
  cronStyleSchedule?: string,
  job: ()=>void,
})
{
  onStartup(function() {
    if (!isAnyTest) {
      // Defer starting of cronjobs until 20s after server startup
      runAfterDelay(() => {
        SyncedCron.add({
          name: options.name,
          schedule: (parser: any) => {
            if (options.interval)
              return parser.text(options.interval);
            else if (options.cronStyleSchedule)
              return parser.cron(options.cronStyleSchedule);
            else
              throw new Error("addCronJob needs a schedule specified");
          },
          job: options.job,
        });
      }, 20000);
    }
  });
}

export function startSyncedCron() {
  if (typeof SyncedCron !== 'undefined') {
    SyncedCron.start();
  }
}<commit_msg>Don't run cronjobs in shell-but-not-webserver mode<commit_after>import { isAnyTest, onStartup, runAfterDelay } from '../lib/executionEnvironment';
import { SyncedCron } from './vendor/synced-cron/synced-cron-server';
import { getCommandLineArguments } from '../platform/express/server/commandLine';

SyncedCron.options = {
  log: true,
  collectionName: 'cronHistory',
  utc: false,
  collectionTTL: 172800
};

export function addCronJob(options: {
  name: string,
  interval?: string,
  cronStyleSchedule?: string,
  job: ()=>void,
})
{
  onStartup(function() {
    if (!isAnyTest && !getCommandLineArguments().shellMode) {
      // Defer starting of cronjobs until 20s after server startup
      runAfterDelay(() => {
        SyncedCron.add({
          name: options.name,
          schedule: (parser: any) => {
            if (options.interval)
              return parser.text(options.interval);
            else if (options.cronStyleSchedule)
              return parser.cron(options.cronStyleSchedule);
            else
              throw new Error("addCronJob needs a schedule specified");
          },
          job: options.job,
        });
      }, 20000);
    }
  });
}

export function startSyncedCron() {
  if (typeof SyncedCron !== 'undefined') {
    SyncedCron.start();
  }
}
{'fraction_non_alphanumeric': 0.12752785802723896, 'fraction_numerical': 0.010730499380932727, 'mean_word_length': 2.661631419939577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '915006', 'n_tokens_mistral': 764, 'n_tokens_neox': 729, 'n_words': 164}