Wolfram Research

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

"Delay" "Hourly" how long to wait before modifying the object
“ReplacementFunction” CloudDeploy which 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

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

Deploy a FormFunction to a named location:

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

Schedule the replacement of the form with a new one:

Options

Delay

Set an object to be deleted in one year:

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

Set an object to be deleted at a specific time:

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

Use Ctrl+= to specify a deletion time:

In[6]:=
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., {9.5, 15.5}},
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[6]=

Permissions

CloudDeploy options can be provided for the newly deployment:

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

Applications

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

In[8]:=
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->{80., {9.5, 15.5}},
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[8]=

Possible Issues

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[9]:=
ResourceFunction["ScheduleCloudObjectExpiration"][
 CloudObject["myform"], "Delay" -> DateObject[{2019, 12, 01, 01, 00}]]
Out[9]=

Resource History

Related Resources

License Information