Skip to content

Commit

Permalink
Rename Timers "jobs" to simply "timers"
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtmckee committed Dec 12, 2023
1 parent a2aa6c0 commit 9d7ccf9
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 100 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20231211_183203_kurtmckee_rename_timer_jobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Other

* User timers are now referred to as "timers" rather than as "jobs".
2 changes: 1 addition & 1 deletion src/globus_cli/commands/timer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
},
)
def timer_command() -> None:
"""Schedule and manage jobs in Globus Timers"""
"""Schedule and manage timers in Globus Timers"""
6 changes: 3 additions & 3 deletions src/globus_cli/commands/timer/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def render(self, value: dict[str, t.Any]) -> str:


_COMMON_FIELDS = [
Field("Job ID", "job_id"),
Field("Timer ID", "job_id"),
Field("Name", "name"),
Field("Type", "callback_url", formatter=CallbackActionTypeFormatter()),
Field("Submitted At", "submitted_at", formatter=formatters.Date),
Expand All @@ -85,7 +85,7 @@ def render(self, value: dict[str, t.Any]) -> str:
]


JOB_FORMAT_FIELDS = _COMMON_FIELDS + [
TIMER_FORMAT_FIELDS = _COMMON_FIELDS + [
Field("Status", "status"),
Field("Last Run", "last_ran_at", formatter=formatters.Date),
Field("Next Run", "next_run", formatter=formatters.Date),
Expand All @@ -95,7 +95,7 @@ def render(self, value: dict[str, t.Any]) -> str:
Field("Number of Timer Errors", "n_errors"),
]

DELETED_JOB_FORMAT_FIELDS = _COMMON_FIELDS + [
DELETED_TIMER_FORMAT_FIELDS = _COMMON_FIELDS + [
Field("Status", "status"),
Field("Stop After Date", "stop_after.date"),
Field("Stop After Number of Runs", "stop_after.n_runs"),
Expand Down
2 changes: 1 addition & 1 deletion src/globus_cli/commands/timer/create/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@group(
"create",
short_help="Submit a Timer job",
short_help="Create a timer",
lazy_subcommands={"transfer": (".transfer", "transfer_command")},
)
def create_command() -> None:
Expand Down
18 changes: 9 additions & 9 deletions src/globus_cli/commands/timer/create/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


INTERVAL_HELP = """\
Interval at which the job should run. Expressed in weeks, days, hours, minutes, and
Interval at which the timer should run. Expressed in weeks, days, hours, minutes, and
seconds. Use 'w', 'd', 'h', 'm', and 's' as suffixes to specify.
e.g. '1h30m', '500s', '10d'
"""
Expand All @@ -71,7 +71,7 @@ def resolve_optional_local_time(
return start_with_tz


@command("transfer", short_help="Create a recurring transfer job in Timer")
@command("transfer", short_help="Create a recurring transfer timer")
@click.argument(
"source", metavar="SOURCE_ENDPOINT_ID[:SOURCE_PATH]", type=ENDPOINT_PLUS_OPTPATH
)
Expand All @@ -90,18 +90,18 @@ def resolve_optional_local_time(
@click.option(
"--start",
type=click.DateTime(formats=DATETIME_FORMATS),
help="Start time for the job. Defaults to current time.",
help="Start time for the timer. Defaults to current time.",
)
@click.option(
"--interval",
type=TimedeltaType(),
help=INTERVAL_HELP,
)
@click.option("--name", type=str, help="A name for the Timer job.")
@click.option("--name", type=str, help="A name for the timer.")
@click.option(
"--label",
type=str,
help="A label for the Transfer tasks submitted by the Timer job.",
help="A label for the Transfer tasks submitted by the timer.",
)
@click.option(
"--stop-after-date",
Expand Down Expand Up @@ -137,10 +137,10 @@ def transfer_command(
notify: dict[str, bool],
) -> None:
"""
Create a Timer job which will run a transfer on a recurring schedule
Create a timer which will run a transfer on a recurring schedule
according to the parameters provided.
For example, to create a job which runs a Transfer from /foo/ on one endpoint to
For example, to create a timer which runs a Transfer from /foo/ on one endpoint to
/bar/ on another endpoint every day, with no end condition:
\b
Expand Down Expand Up @@ -188,8 +188,8 @@ def transfer_command(
"transfer requires either SOURCE_PATH and DEST_PATH or --batch"
)

# Interval must be null iff the job is 'once', i.e. stop-after-runs == 1.
# and it must be non-null if the job is 'recurring'
# Interval must be null iff the timer is 'once', i.e. stop-after-runs == 1.
# and it must be non-null if the timer is 'recurring'
schedule: globus_sdk.RecurringTimerSchedule | globus_sdk.OnceTimerSchedule
start_ = resolve_optional_local_time(start)
if stop_after_runs == 1:
Expand Down
16 changes: 8 additions & 8 deletions src/globus_cli/commands/timer/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
from globus_cli.parsing import command
from globus_cli.termio import TextMode, display

from ._common import DELETED_JOB_FORMAT_FIELDS
from ._common import DELETED_TIMER_FORMAT_FIELDS


@command("delete", short_help="Delete a timer job")
@click.argument("JOB_ID", type=click.UUID)
@command("delete", short_help="Delete a timer")
@click.argument("TIMER_ID", type=click.UUID)
@LoginManager.requires_login("timer")
def delete_command(login_manager: LoginManager, *, job_id: uuid.UUID) -> None:
def delete_command(login_manager: LoginManager, *, timer_id: uuid.UUID) -> None:
"""
Delete a Timer job.
Delete a timer.
The contents of the deleted job is printed afterwards.
The contents of the deleted timer are printed afterward.
"""
timer_client = login_manager.get_timer_client()
deleted = timer_client.delete_job(job_id)
deleted = timer_client.delete_job(timer_id)
display(
deleted,
text_mode=TextMode.text_record,
fields=DELETED_JOB_FORMAT_FIELDS,
fields=DELETED_TIMER_FORMAT_FIELDS,
)
8 changes: 4 additions & 4 deletions src/globus_cli/commands/timer/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
from globus_cli.parsing import command
from globus_cli.termio import TextMode, display

from ._common import JOB_FORMAT_FIELDS
from ._common import TIMER_FORMAT_FIELDS


@command("list", short_help="List your jobs")
@command("list", short_help="List your timers")
@LoginManager.requires_login("timer")
def list_command(login_manager: LoginManager) -> None:
"""
List your Timer jobs.
List your timers.
"""
timer_client = login_manager.get_timer_client()
response = timer_client.list_jobs(query_params={"order": "submitted_at asc"})
display(
response["jobs"],
text_mode=TextMode.text_record_list,
fields=JOB_FORMAT_FIELDS,
fields=TIMER_FORMAT_FIELDS,
)
6 changes: 3 additions & 3 deletions src/globus_cli/commands/timer/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@


@command("pause", short_help="Pause a timer")
@click.argument("JOB_ID", type=click.UUID)
@click.argument("TIMER_ID", type=click.UUID)
@LoginManager.requires_login("timer")
def pause_command(login_manager: LoginManager, *, job_id: uuid.UUID) -> None:
def pause_command(login_manager: LoginManager, *, timer_id: uuid.UUID) -> None:
"""
Pause a timer.
"""
timer_client = login_manager.get_timer_client()
paused = timer_client.pause_job(job_id)
paused = timer_client.pause_job(timer_id)
display(
paused,
text_mode=TextMode.text_raw,
Expand Down
21 changes: 7 additions & 14 deletions src/globus_cli/commands/timer/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,14 @@ def resume_command(
Resume a timer.
"""
timer_client = login_manager.get_timer_client()
job_doc = timer_client.get_job(timer_id)
timer_doc = timer_client.get_job(timer_id)

gare = _get_inactive_reason(job_doc)
gare = _get_inactive_reason(timer_doc)
if not skip_inactive_reason_check:
check_inactive_reason(login_manager, timer_id, gare)

resumed = timer_client.resume_job(
timer_id,
update_credentials=(gare is not None),
)
display(
resumed,
text_mode=TextMode.text_raw,
simple_text=resumed["message"],
)
resumed = timer_client.resume_job(timer_id, update_credentials=(gare is not None))
display(resumed, text_mode=TextMode.text_raw, simple_text=resumed["message"])


def check_inactive_reason(
Expand Down Expand Up @@ -105,16 +98,16 @@ def check_inactive_reason(


def _get_inactive_reason(
job_doc: dict[str, t.Any] | globus_sdk.GlobusHTTPResponse
timer_doc: dict[str, t.Any] | globus_sdk.GlobusHTTPResponse
) -> GlobusAuthRequirementsError | None:
from globus_sdk.experimental.auth_requirements_error import (
to_auth_requirements_error,
)

if job_doc.get("status") != "inactive":
if timer_doc.get("status") != "inactive":
return None

reason = job_doc.get("inactive_reason", {})
reason = timer_doc.get("inactive_reason", {})
if reason.get("cause") != "globus_auth_requirements":
return None

Expand Down
14 changes: 7 additions & 7 deletions src/globus_cli/commands/timer/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from globus_cli.parsing import command
from globus_cli.termio import TextMode, display

from ._common import JOB_FORMAT_FIELDS
from ._common import TIMER_FORMAT_FIELDS


@command("show", short_help="Display a Timer job")
@click.argument("JOB_ID", type=click.UUID)
@command("show", short_help="Display a timer")
@click.argument("TIMER_ID", type=click.UUID)
@LoginManager.requires_login("timer")
def show_command(login_manager: LoginManager, *, job_id: uuid.UUID) -> None:
def show_command(login_manager: LoginManager, *, timer_id: uuid.UUID) -> None:
"""
Display information about a particular job.
Display information about a particular timer.
"""
timer_client = login_manager.get_timer_client()
response = timer_client.get_job(job_id)
display(response, text_mode=TextMode.text_record, fields=JOB_FORMAT_FIELDS)
response = timer_client.get_job(timer_id)
display(response, text_mode=TextMode.text_record, fields=TIMER_FORMAT_FIELDS)
32 changes: 16 additions & 16 deletions tests/functional/timer/test_job_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import pytest
from globus_sdk._testing import RegisteredResponse, load_response, load_response_set

from globus_cli.commands.timer._common import JOB_FORMAT_FIELDS
from globus_cli.commands.timer._common import TIMER_FORMAT_FIELDS

# NOTE: this is not quite the same as the "normal" job responses from
# NOTE: this is not quite the same as the "normal" timer responses from
# create/update—definitely something to consider revisiting on the Timer API.
_job_id = "e304f241-b77a-4e75-89f6-c431ddafe497"
_timer_id = "e304f241-b77a-4e75-89f6-c431ddafe497"
DELETE_RESPONSE = RegisteredResponse(
metadata={"job_id": _job_id},
metadata={"timer_id": _timer_id},
service="timer",
path=f"/jobs/{_job_id}",
path=f"/jobs/{_timer_id}",
method="DELETE",
json={
"callback_body": {
Expand Down Expand Up @@ -46,9 +46,9 @@
},
"callback_url": "https://actions.automate.globus.org/transfer/transfer/run",
"interval": None,
"job_id": _job_id,
"job_id": _timer_id,
"n_tries": 1,
"name": "example-timer-job",
"name": "example-timer",
"owner": "5276fa05-eedf-46c5-919f-ad2d0160d1a9",
"refresh_token": None,
"results": [],
Expand All @@ -62,44 +62,44 @@
)


def test_show_job(run_line):
def test_show_timer(run_line):
meta = load_response_set(globus_sdk.TimerClient.get_job).metadata
assert meta
result = run_line(["globus", "timer", "show", meta["job_id"]])
assert result.exit_code == 0
assert meta["job_id"] in result.output
for field in JOB_FORMAT_FIELDS:
for field in TIMER_FORMAT_FIELDS:
assert field.name in result.output


def test_list_jobs(run_line):
def test_list_timers(run_line):
meta = load_response_set(globus_sdk.TimerClient.list_jobs).metadata
assert meta
result = run_line(["globus", "timer", "list"])
assert result.exit_code == 0
assert all(job_id in result.output for job_id in meta["job_ids"])
for field in JOB_FORMAT_FIELDS:
assert all(timer_id in result.output for timer_id in meta["job_ids"])
for field in TIMER_FORMAT_FIELDS:
assert field.name in result.output


@pytest.mark.parametrize("out_format", ["text", "json"])
def test_delete_job(run_line, out_format):
def test_delete_timer(run_line, out_format):
meta = load_response(DELETE_RESPONSE).metadata
add_args = []
if out_format == "json":
add_args = ["-F", "json"]
result = run_line(["globus", "timer", "delete", meta["job_id"]] + add_args)
result = run_line(["globus", "timer", "delete", meta["timer_id"]] + add_args)
assert result.exit_code == 0
if out_format == "json":
assert json.loads(result.output) == DELETE_RESPONSE.json
else:
pattern = re.compile(
r"^Job ID:\s+" + re.escape(meta["job_id"]) + "$", flags=re.MULTILINE
r"^Timer ID:\s+" + re.escape(meta["timer_id"]) + "$", flags=re.MULTILINE
)
assert pattern.search(result.output) is not None


def test_pause_job(run_line):
def test_pause_timer(run_line):
meta = load_response_set(globus_sdk.TimerClient.pause_job).metadata
add_args = []
run_line(
Expand Down
Loading

0 comments on commit 9d7ccf9

Please sign in to comment.