| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import argparse |
| 4 |
import datetime |
| 5 |
|
| 6 |
import globus_sdk |
| 7 |
from globus_sdk.experimental.globus_app import UserApp |
| 8 |
|
| 9 |
# Tutorial Client ID - <replace this with your own client> |
| 10 |
NATIVE_CLIENT_ID = "61338d24-54d5-408f-a10d-66c06b59f6d2" |
| 11 |
USER_APP = UserApp("manage-timers-example", client_id=NATIVE_CLIENT_ID) |
| 12 |
|
| 13 |
|
| 14 |
def main(): |
| 15 |
parser = argparse.ArgumentParser() |
| 16 |
# the source, destination, and path to a file or dir to sync |
| 17 |
parser.add_argument("SOURCE_COLLECTION") |
| 18 |
parser.add_argument("DESTINATION_COLLECTION") |
| 19 |
parser.add_argument("PATH") |
| 20 |
parser.add_argument( |
| 21 |
"--interval-seconds", |
| 22 |
help="How frequently the timer runs, in seconds (default: 1 hour)", |
| 23 |
default=3600, |
| 24 |
type=int, |
| 25 |
) |
| 26 |
parser.add_argument( |
| 27 |
"--days", |
| 28 |
help="How many days to run the timer (default: 2)", |
| 29 |
default=2, |
| 30 |
type=int, |
| 31 |
) |
| 32 |
args = parser.parse_args() |
| 33 |
|
| 34 |
client = globus_sdk.TimersClient(app=USER_APP) |
| 35 |
|
| 36 |
body = globus_sdk.TransferData( |
| 37 |
source_endpoint=args.SOURCE_COLLECTION, |
| 38 |
destination_endpoint=args.DESTINATION_COLLECTION, |
| 39 |
) |
| 40 |
body.add_item(args.PATH, args.PATH) |
| 41 |
|
| 42 |
# the timer will run until the end date, on whatever interval was requested |
| 43 |
schedule = globus_sdk.RecurringTimerSchedule( |
| 44 |
interval_seconds=args.interval_seconds, |
| 45 |
end={ |
| 46 |
"condition": "time", |
| 47 |
"datetime": datetime.datetime.now() + datetime.timedelta(days=args.days), |
| 48 |
}, |
| 49 |
) |
| 50 |
|
| 51 |
timer = client.create_timer( |
| 52 |
timer=globus_sdk.TransferTimer( |
| 53 |
name=( |
| 54 |
"create-timer-example " |
| 55 |
f"[created at {datetime.datetime.now().isoformat()}]" |
| 56 |
), |
| 57 |
body=body, |
| 58 |
schedule=schedule, |
| 59 |
) |
| 60 |
) |
| 61 |
print("Finished submitting timer.") |
| 62 |
print(f"timer_id: {timer['timer']['job_id']}") |
| 63 |
|
| 64 |
|
| 65 |
if __name__ == "__main__": |
| 66 |
main() |