diff --git a/Dockerfile b/Dockerfile index 08000c69..79770349 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,7 @@ RUN groupadd --system $ARCHIVEBOX_USER \ RUN apt-get update -qq \ && apt-get install -qq -y --no-install-recommends \ apt-transport-https ca-certificates gnupg2 zlib1g-dev \ - dumb-init gosu unzip curl \ + dumb-init gosu cron unzip curl \ && rm -rf /var/lib/apt/lists/* # Install apt dependencies diff --git a/archivebox/main.py b/archivebox/main.py index 0f063544..44a7ee8d 100644 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -967,9 +967,55 @@ def schedule(add: bool=False, stderr() stderr(' Make sure you have enough storage space available to hold all the data.') stderr(' Using a compressed/deduped filesystem like ZFS is recommended if you plan on archiving a lot.') + stderr('') + elif show: + if existing_jobs: + print('\n'.join(str(cmd) for cmd in existing_jobs)) + else: + stderr('{red}[X] There are no ArchiveBox cron jobs scheduled for your user ({}).{reset}'.format(USER, **ANSI)) + stderr(' To schedule a new job, run:') + stderr(' archivebox schedule --every=[timeperiod] https://example.com/some/rss/feed.xml') raise SystemExit(0) + elif clear: + print(cron.remove_all(comment=CRON_COMMENT)) + cron.write() + raise SystemExit(0) + cron = CronTab(user=True) + cron = dedupe_cron_jobs(cron) + existing_jobs = list(cron.find_comment(CRON_COMMENT)) + + if foreground or run_all: + if not existing_jobs: + stderr('{red}[X] You must schedule some jobs first before running in foreground mode.{reset}'.format(**ANSI)) + stderr(' archivebox schedule --every=hour https://example.com/some/rss/feed.xml') + raise SystemExit(1) + + print('{green}[*] Running {} ArchiveBox jobs in foreground task scheduler...{reset}'.format(len(existing_jobs), **ANSI)) + if run_all: + try: + for job in existing_jobs: + sys.stdout.write(f' > {job.command}') + sys.stdout.flush() + job.run() + sys.stdout.write(f'\r √ {job.command}\n') + except KeyboardInterrupt: + print('\n{green}[√] Stopped.{reset}'.format(**ANSI)) + raise SystemExit(1) + + if foreground: + try: + for job in existing_jobs: + sys.stdout.write(f' > {job.command}') + sys.stdout.flush() + for result in cron.run_scheduler(): + print(result) + except KeyboardInterrupt: + print('\n{green}[√] Stopped.{reset}'.format(**ANSI)) + raise SystemExit(1) + + @enforce_types def server(runserver_args: Optional[List[str]]=None, reload: bool=False, diff --git a/docker-compose.yml b/docker-compose.yml index a4c9f1e2..c8733e1b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,7 @@ services: # host machine, add tasks and see more info with archivebox schedule --help # scheduler: # image: nikisweeting/archivebox:latest - # command: schedule --foreground + # command: schedule --foreground --every=day --depth=1 'https://getpocket.com/users/USERNA