Skip to content

Commit 7843ec5

Browse files
sirosenkurtmckee
andauthored
Remove 'TimerJob.from_transfer_data' constructor (#1269)
Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
1 parent 5377ff2 commit 7843ec5

5 files changed

Lines changed: 24 additions & 112 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Breaking Changes
2+
----------------
3+
4+
- The ``TimerJob.from_transfer_data`` classmethod, which was deprecated in
5+
globus-sdk version 3, has been removed. Users should use the ``TransferTimer``
6+
class to construct timers which submit transfer tasks. (:pr:`NUMBER`)

src/globus_sdk/services/timers/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,12 @@ def create_job(
188188
**Examples**
189189
190190
>>> from datetime import datetime, timedelta
191-
>>> transfer_data = TransferData(...)
191+
>>> callback_url = ...
192+
>>> data = ...
192193
>>> timers_client = globus_sdk.TimersClient(...)
193-
>>> job = TimerJob.from_transfer_data(
194-
... transfer_data,
194+
>>> job = TimerJob(
195+
... callback_url,
196+
... data,
195197
... datetime.utcnow(),
196198
... timedelta(days=14),
197199
... name="my-timer-job"

src/globus_sdk/services/timers/data.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import logging
77
import typing as t
88

9-
from globus_sdk._internal.utils import slash_join
109
from globus_sdk._missing import MISSING, MissingType
1110
from globus_sdk._payload import GlobusPayload
12-
from globus_sdk.config import get_service_url
13-
from globus_sdk.exc import warn_deprecated
1411
from globus_sdk.services.transfer import TransferData
1512

1613
log = logging.getLogger(__name__)
@@ -266,69 +263,6 @@ def __init__(
266263
if scope is not None:
267264
self["scope"] = scope
268265

269-
@classmethod
270-
def from_transfer_data(
271-
cls,
272-
transfer_data: TransferData | dict[str, t.Any],
273-
start: dt.datetime | str,
274-
interval: dt.timedelta | int | None,
275-
*,
276-
name: str | None = None,
277-
stop_after: dt.datetime | None = None,
278-
stop_after_n: int | None = None,
279-
scope: str | None = None,
280-
environment: str | None = None,
281-
) -> TimerJob:
282-
r"""
283-
Specify data to create a Timers job using the parameters for a transfer. Timers
284-
will use those parameters to run the defined transfer operation, recurring at
285-
the given interval.
286-
287-
:param transfer_data: A :class:`TransferData <globus_sdk.TransferData>` object.
288-
Construct this object exactly as you would normally; Timers will use this to
289-
run the recurring transfer.
290-
:param start: The datetime at which to start the Timers job.
291-
:param interval: The interval at which the Timers job should recur. Interpreted
292-
as seconds if specified as an integer. If ``stop_after_n == 1``, i.e. the
293-
job is set to run only a single time, then interval *must* be None.
294-
:param name: A (not necessarily unique) name to identify this job in Timers
295-
:param stop_after: A date after which the Timers job will stop running
296-
:param stop_after_n: A number of executions after which the Timers job will stop
297-
:param scope: Timers defaults to the Transfer 'all' scope. Use this parameter to
298-
change the scope used by Timers when calling the Transfer Action Provider.
299-
:param environment: For internal use: because this method needs to generate a
300-
URL for the Transfer Action Provider, this argument can control which
301-
environment the Timers job is sent to.
302-
"""
303-
warn_deprecated(
304-
"TimerJob.from_transfer_data(X, ...) is deprecated. "
305-
"Prefer TransferTimer(body=X, ...) instead."
306-
)
307-
308-
transfer_action_url = slash_join(
309-
get_service_url("actions", environment=environment), "transfer/transfer/run"
310-
)
311-
log.debug(
312-
"Creating TimerJob from TransferData, action_url=%s", transfer_action_url
313-
)
314-
for key in ("submission_id", "skip_activation_check"):
315-
if transfer_data.get(key, MISSING) is not MISSING:
316-
raise ValueError(
317-
f"cannot create TimerJob from TransferData which has {key} set"
318-
)
319-
# dict will either convert a `TransferData` object or leave us with a dict here
320-
callback_body = {"body": dict(transfer_data)}
321-
return cls(
322-
transfer_action_url,
323-
callback_body,
324-
start,
325-
interval,
326-
name=name,
327-
stop_after=stop_after,
328-
stop_after_n=stop_after_n,
329-
scope=scope,
330-
)
331-
332266

333267
def _format_date(date: str | dt.datetime | MissingType) -> str | MissingType:
334268
if isinstance(date, dt.datetime):

tests/functional/services/timers/test_jobs.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
import pytest
55

6-
from globus_sdk import TimerJob, TimersAPIError, TransferData, config, exc
7-
from globus_sdk._internal.utils import slash_join
6+
from globus_sdk import TimerJob, TimersAPIError
87
from globus_sdk.testing import get_last_request, load_response
9-
from tests.common import GO_EP1_ID, GO_EP2_ID
108

119

1210
def test_list_jobs(client):
@@ -39,17 +37,14 @@ def test_get_job_errors(client):
3937
)
4038
def test_create_job(client, start, interval):
4139
meta = load_response(client.create_job).metadata
42-
transfer_data = TransferData(GO_EP1_ID, GO_EP2_ID)
43-
with pytest.warns(exc.RemovedInV4Warning, match="Prefer TransferTimer"):
44-
timer_job = TimerJob.from_transfer_data(transfer_data, start, interval)
45-
response = client.create_job(timer_job)
46-
assert response.http_status == 201
47-
assert response.data["job_id"] == meta["job_id"]
48-
with pytest.warns(exc.RemovedInV4Warning, match="Prefer TransferTimer"):
49-
timer_job = TimerJob.from_transfer_data(dict(transfer_data), start, interval)
40+
timer_job = TimerJob(
41+
"https://example.bogus/bogus-callback", {"bogus": "bogus_body"}, start, interval
42+
)
43+
5044
response = client.create_job(timer_job)
5145
assert response.http_status == 201
5246
assert response.data["job_id"] == meta["job_id"]
47+
5348
req_body = json.loads(get_last_request().body)
5449
if isinstance(start, datetime.datetime):
5550
assert req_body["start"] == start.isoformat()
@@ -59,18 +54,17 @@ def test_create_job(client, start, interval):
5954
assert req_body["interval"] == interval.total_seconds()
6055
else:
6156
assert req_body["interval"] == interval
62-
assert req_body["callback_url"] == slash_join(
63-
config.get_service_url("actions"), "/transfer/transfer/run"
64-
)
57+
assert req_body["callback_url"] == "https://example.bogus/bogus-callback"
6558

6659

6760
def test_create_job_validation_error(client):
6861
meta = load_response(client.create_job, case="validation_error").metadata
69-
transfer_data = TransferData(GO_EP1_ID, GO_EP2_ID)
70-
with pytest.warns(exc.RemovedInV4Warning, match="Prefer TransferTimer"):
71-
timer_job = TimerJob.from_transfer_data(
72-
transfer_data, "2022-04-05T06:00:00", 1800
73-
)
62+
timer_job = TimerJob(
63+
"https://example.bogus/bogus-callback",
64+
{"bogus": "bogus_body"},
65+
"2022-04-05T06:00:00",
66+
1800,
67+
)
7468

7569
with pytest.raises(TimersAPIError) as excinfo:
7670
client.create_job(timer_job)

tests/unit/helpers/test_timer.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,13 @@
55
from globus_sdk import (
66
OnceTimerSchedule,
77
RecurringTimerSchedule,
8-
TimerJob,
98
TransferData,
109
TransferTimer,
11-
exc,
1210
)
1311
from globus_sdk._missing import filter_missing
1412
from tests.common import GO_EP1_ID, GO_EP2_ID
1513

1614

17-
def test_timer_from_transfer_data_ok():
18-
tdata = TransferData(GO_EP1_ID, GO_EP2_ID)
19-
with pytest.warns(exc.RemovedInV4Warning, match="Prefer TransferTimer"):
20-
job = TimerJob.from_transfer_data(tdata, "2022-01-01T00:00:00Z", 600)
21-
assert "callback_body" in job
22-
assert "body" in job["callback_body"]
23-
assert "source_endpoint" in job["callback_body"]["body"]
24-
assert "destination_endpoint" in job["callback_body"]["body"]
25-
assert job["callback_body"]["body"]["source_endpoint"] == GO_EP1_ID
26-
assert job["callback_body"]["body"]["destination_endpoint"] == GO_EP2_ID
27-
28-
29-
@pytest.mark.parametrize(
30-
"badkey, value", (("submission_id", "foo"), ("skip_activation_check", True))
31-
)
32-
def test_timer_from_transfer_data_rejects_forbidden_keys(badkey, value):
33-
tdata = TransferData(GO_EP1_ID, GO_EP2_ID, **{badkey: value})
34-
with pytest.raises(ValueError):
35-
with pytest.warns(exc.RemovedInV4Warning, match="Prefer TransferTimer"):
36-
TimerJob.from_transfer_data(tdata, "2022-01-01T00:00:00Z", 600)
37-
38-
3915
def test_transfer_timer_ok():
4016
tdata = TransferData(GO_EP1_ID, GO_EP2_ID)
4117
timer = TransferTimer(body=tdata, name="foo timer", schedule={"type": "once"})

0 commit comments

Comments
 (0)