Function Repository Resource:

ScheduleCloudObjectExpiration

Source Notebook

Deploy a task to delete or replace a CloudObject after a delay

Contributed by: Bradley Ashby

ResourceFunction["ScheduleCloudObjectExpiration"][cloudobject]

schedules a task to delete the given CloudObject after a delay.

ResourceFunction["ScheduleCloudObjectExpiration"][cloudobject,newexpr]

schedules a task to deploy newexpr to the given CloudObject after a delay.

Details and Options

ResourceFunction["ScheduleCloudObjectExpiration"] accepts the following options:
"Delay""Hourly"how long to wait before modifying the object
"ReplacementFunction"CloudDeploywhich function to use when replacing the object
The following specification can be given for the value of "Delay", which follows the specifications for ScheduledTask:
"Hourly"delete object after an hour
"Daily"delete object after a day
"Weekly"delete object after a week
"Monthly"delete object after a month
"Yearly"delete object after a year
Quantity[]delete object after a specified time interval
DateObject[patt]delete object on a specified day and/or time
Typical values for "ReplacementFunction" include CloudDeploy, CloudPut or CloudExport.
The tasks to modify the cloud objects are deployed to $CloudRootDirectory/CloudObjectExpirationTasks/location. Use CloudObjects["CloudObjectExpirationTasks"] to list them.
Cloud objects are deleted or modified based on their UUID, not their URL or path.
Normal deployments to the location of an existing CloudObject does not change the UUID of the cloud object but deleting a cloud object and writing to the same location will result in a new UUID.
In the cloud, the precise times at which scheduled tasks are run are typically determined by load-balancing requirements and may not match a specified time exactly.

Examples

Basic Examples (2) 

Deploy a random image to a new unnamed object in the Wolfram Cloud and schedule its removal:

In[1]:=
co = CloudDeploy[RandomImage[]];
ResourceFunction["ScheduleCloudObjectExpiration"][co]
Out[1]=

See that a task as been created to delete the resulting CloudObject:

In[2]:=
CloudObjects["CloudObjectExpirationTasks"]
Out[2]=

Scope (2) 

Deploy a FormFunction to a named location:

In[3]:=
co = CloudDeploy[FormFunction[{"integer" -> "Integer"}, #x! &], "myform"]
Out[29]=

Schedule the replacement of the form with a new one:

In[30]:=
ResourceFunction["ScheduleCloudObjectExpiration"][co, FormFunction[{"real" -> "Real"}, Sqrt[#x] &]]
Out[30]=

Options (4) 

Delay (3) 

Set an object to be deleted in one year:

In[31]:=
ResourceFunction["ScheduleCloudObjectExpiration"][
 CloudObject["myform"], "Delay" -> "Yearly"]
Out[31]=

Set an object to be deleted at a specific time:

In[32]:=
ResourceFunction["ScheduleCloudObjectExpiration"][
 CloudObject["myform"], "Delay" -> DateObject[{2019, 12, 24, 23}]]
Out[32]=

Use to specify a deletion time:

In[33]:=
ResourceFunction["ScheduleCloudObjectExpiration"][
 CloudObject["myform"], "Delay" -> \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "tomorrow at noon", Typeset`boxes$$ = RowBox[{"DateObject", "[", 
RowBox[{"Tomorrow", ",", " ", 
RowBox[{"TimeObject", "[", 
RowBox[{"{", 
RowBox[{"12", ",", " ", "0", ",", " ", "0"}], "}"}], "]"}]}], "]"}], Typeset`allassumptions$$ = {}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1}, Typeset`querystate$$ = {"Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.530983, "Messages" -> {}}}, 
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, 
Dynamic[Typeset`query$$], 
Dynamic[Typeset`boxes$$], 
Dynamic[Typeset`allassumptions$$], 
Dynamic[Typeset`assumptions$$], 
Dynamic[Typeset`open$$], 
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{137.79999999999998`, {9., 15.8}},
TrackedSymbols:>{Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)]
Out[33]=

Permissions (1) 

CloudDeploy options can be provided for the newly deployment:

In[34]:=
ResourceFunction["ScheduleCloudObjectExpiration"][
 CloudObject["myform"], FormFunction[{"real" -> "Real"}, Sqrt[#x] &], Permissions -> "Public"]
Out[34]=

Applications (1) 

Deploy a registration form and set an expiration to prevent entries after a deadline:

In[35]:=
form = CloudDeploy[FormFunction[<|
     "Name" -> "String",
     "Email" -> "EmailAddress"|>,
    DatabinAdd[databin, #] &,
    AppearanceRules -> <|"Title" -> "Sign up by Friday!"|>], Permissions -> "Public"];
ResourceFunction[
 "ScheduleCloudObjectExpiration"][form, "Registration has closed", Permissions -> "Public", "Delay" -> \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "Saturday", Typeset`boxes$$ = RowBox[{"DayPlus", "[", 
RowBox[{"Yesterday", ",", " ", "1", ",", " ", "Saturday"}], "]"}], Typeset`allassumptions$$ = {{"type" -> "Clash", "word" -> "Saturday", "template" -> "Assuming \"${word}\" is ${desc1}. Use as ${desc2} instead", "count" -> "2", "Values" -> {{"name" -> "CalendarEventName", "desc" -> "a weekday", "input" -> "*C.Saturday-_*CalendarEventName-"}, {"name" -> "Word", "desc" -> "a word", "input" -> "*C.Saturday-_*Word-"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1}, Typeset`querystate$$ = {"Online" -> True, "Allowed" -> True, "mparse.jsp" -> 0.235803, "Messages" -> {}}}, 
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, 
Dynamic[Typeset`query$$], 
Dynamic[Typeset`boxes$$], 
Dynamic[Typeset`allassumptions$$], 
Dynamic[Typeset`assumptions$$], 
Dynamic[Typeset`open$$], 
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{79.8, {9., 15.8}},
TrackedSymbols:>{Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)]
Out[35]=

Possible Issues (1) 

Specific times for scheduled tasks may be adjusted by the cloud. This deployment was ultimately scheduled for deletion at 1:48 instead of 1:00:

In[36]:=
ResourceFunction["ScheduleCloudObjectExpiration"][
 CloudObject["myform"], "Delay" -> DateObject[{2019, 12, 01, 01, 00}]]
Out[36]=

Publisher

Bradley Ashby

Version History

  • 1.0.0 – 03 February 2020

Related Resources

License Information