| 1 |
import datetime |
| 2 |
|
| 3 |
import globus_sdk |
| 4 |
from globus_sdk.experimental.globus_app import UserApp |
| 5 |
|
| 6 |
# Tutorial Client ID - <replace this with your own client> |
| 7 |
NATIVE_CLIENT_ID = "61338d24-54d5-408f-a10d-66c06b59f6d2" |
| 8 |
|
| 9 |
# Globus Tutorial Collection 1 |
| 10 |
# https://app.globus.org/file-manager/collections/6c54cade-bde5-45c1-bdea-f4bd71dba2cc |
| 11 |
SRC_COLLECTION = "6c54cade-bde5-45c1-bdea-f4bd71dba2cc" |
| 12 |
SRC_PATH = "/share/godata/file1.txt" |
| 13 |
|
| 14 |
# Globus Tutorial Collection 2 |
| 15 |
# https://app.globus.org/file-manager/collections/31ce9ba0-176d-45a5-add3-f37d233ba47d |
| 16 |
DST_COLLECTION = "31ce9ba0-176d-45a5-add3-f37d233ba47d" |
| 17 |
DST_PATH = "/~/example-timer-destination.txt" |
| 18 |
|
| 19 |
# as with an immediate data transfer, we take our input data and wrap them in |
| 20 |
# a TransferData object, representing the transfer task |
| 21 |
transfer_request = globus_sdk.TransferData(SRC_COLLECTION, DST_COLLECTION) |
| 22 |
transfer_request.add_item(SRC_PATH, DST_PATH) |
| 23 |
|
| 24 |
# we'll define the timer as one which runs every hour for 3 days |
| 25 |
# declare these data in the form of a "schedule" for the timer |
| 26 |
# |
| 27 |
# a wide variety of schedules are possible here; to setup a recurring timer: |
| 28 |
# - you MUST declare an interval for the timer (`interval_seconds`) |
| 29 |
# - you MAY declare an end condition (`end`) |
| 30 |
schedule = globus_sdk.RecurringTimerSchedule( |
| 31 |
interval_seconds=3600, |
| 32 |
end={ |
| 33 |
"condition": "time", |
| 34 |
"datetime": datetime.datetime.now() + datetime.timedelta(days=3), |
| 35 |
}, |
| 36 |
) |
| 37 |
|
| 38 |
with UserApp("manage-timers-example", client_id=NATIVE_CLIENT_ID) as app: |
| 39 |
# create a TimersClient to interact with the service, and register any data_access |
| 40 |
# scopes for the collections |
| 41 |
with globus_sdk.TimersClient(app=app) as timers_client: |
| 42 |
# Omit this step if the collections are either |
| 43 |
# (1) A guest collection or (2) high assurance. |
| 44 |
timers_client.add_app_transfer_data_access_scope( |
| 45 |
(SRC_COLLECTION, DST_COLLECTION) |
| 46 |
) |
| 47 |
|
| 48 |
# submit the creation request to the service, printing out the |
| 49 |
# ID of your new timer after it's created -- you can find it in |
| 50 |
# https://app.globus.org/activity/timers |
| 51 |
timer = timers_client.create_timer( |
| 52 |
globus_sdk.TransferTimer( |
| 53 |
name=( |
| 54 |
"create-timer-example " |
| 55 |
f"[created at {datetime.datetime.now().isoformat()}]" |
| 56 |
), |
| 57 |
body=transfer_request, |
| 58 |
schedule=schedule, |
| 59 |
) |
| 60 |
) |
| 61 |
|
| 62 |
print("Finished submitting timer.") |
| 63 |
print(f"timer_id: {timer['timer']['job_id']}") |