Skip to content

Commit

Permalink
Use create_output_filename from jupyter-scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaretnikov committed Dec 9, 2023
1 parent 82683a3 commit 3305f76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
6 changes: 0 additions & 6 deletions argo_jupyter_scheduler/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ def rename_files(db_url, job_definition_id, input_path, log_path, start_time):
gen_default_output_path,
gen_html_path,
gen_output_path,
gen_timestamp,
setup_logger,
)

Expand Down Expand Up @@ -706,8 +705,6 @@ def rename_files(db_url, job_definition_id, input_path, log_path, start_time):

start_time = q.start_time

start_time = gen_timestamp(start_time)

old_output_path = gen_default_output_path(input_path)
old_html_path = gen_default_html_path(input_path)

Expand Down Expand Up @@ -749,7 +746,6 @@ def send_to_slack(
from argo_jupyter_scheduler.utils import (
add_file_logger,
gen_html_path,
gen_timestamp,
setup_logger,
)

Expand All @@ -771,8 +767,6 @@ def send_to_slack(

start_time = q.start_time

start_time = gen_timestamp(start_time)

html_path = gen_html_path(input_path, start_time)

# Sends to Slack
Expand Down
36 changes: 15 additions & 21 deletions argo_jupyter_scheduler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import logging
import os
import re
from datetime import datetime
from enum import Enum
from pathlib import Path
from urllib.parse import urljoin

import urllib3
from hera.shared import global_config
from jupyter_scheduler.utils import create_output_filename
from urllib3.exceptions import ConnectionError

CONDA_STORE_TOKEN = "CONDA_STORE_TOKEN"
Expand Down Expand Up @@ -72,12 +72,6 @@ def authenticate():
return global_config


def gen_timestamp(time: int):
# See create_output_filename in jupyter-scheduler
timestamp = datetime.fromtimestamp(time / 1e3) # noqa: DTZ006
return timestamp.strftime("%Y-%m-%d-%I-%M-%S-%p")


def gen_workflow_name(job_id: str):
return f"job-{job_id}"

Expand All @@ -88,28 +82,28 @@ def gen_cron_workflow_name(job_definition_id: str):

def gen_default_output_path(input_path: str):
# The initial filename before we can get access to the timestamp. Has the
# "unknown" suffix to make it visible in the logs and to avoid clashing with
# the input filename.
return gen_output_path(input_path, "unknown")
# "0" suffix to avoid clashing with the input filename. This value will be
# pretty-printed as 1970-01-01-01-00-00-AM when the file is created.
return gen_output_path(input_path, 0)


def gen_default_html_path(input_path: str):
# The initial filename before we can get access to the timestamp. Has the
# "unknown" suffix to make it visible in the logs and to avoid clashing with
# the input filename.
return gen_html_path(input_path, "unknown")
# "0" suffix to avoid clashing with the input filename. This value will be
# pretty-printed as 1970-01-01-01-00-00-AM when the file is created.
return gen_html_path(input_path, 0)


def gen_output_path(input_path: str, timestamp: str):
# See create_output_filename in jupyter-scheduler
basename = os.path.splitext(input_path)[0]
return f"{basename}-{timestamp}.ipynb"
def gen_output_path(input_path: str, start_time: int):
# It's important to use this exact format to make files downloadable via the
# web UI.
return create_output_filename(input_path, start_time, "ipynb")


def gen_html_path(input_path: str, timestamp: str):
# See create_output_filename in jupyter-scheduler
basename = os.path.splitext(input_path)[0]
return f"{basename}-{timestamp}.html"
def gen_html_path(input_path: str, start_time: int):
# It's important to use this exact format to make files downloadable via the
# web UI.
return create_output_filename(input_path, start_time, "html")


def gen_log_path(input_path: str):
Expand Down

0 comments on commit 3305f76

Please sign in to comment.