Message Boards Message Boards

Cloud deploying a scheduled task?

Posted 9 years ago

Hi, all

I am trying to deploy a ScheduledTask that monitors the state of a google spread sheet every hour. I want the cloud object to display the contents of the csv file that I am monitoring. Here is a look at my code:

This imports the contents of the google doc:

Clear@url
Clear@csv
(url = "https://path-to-google-doc/export?format=csv") //
Import[#, "CSV", CharacterEncoding -> "UTF8"] & //
Flatten@# & //
(csv = #) & //
Dataset@# &

Which results in an output that takes the form: Dataset[{....}].

To create the ScheduledTask, I have tried both:

 Clear@obj
 obj = ScheduledTask[{Now, csv}, "Hourly"](*creates a scheduled task that monitors the information in the doc every hour*)//
 RunScheduledTask[#]& //
 CloudDeploy[#, Permissions -> "Public"] &

and

Clear@obj
obj = ScheduledTask[{Now, csv}, "Hourly"](*creates a scheduled task that monitors the information in the doc every hour*)//
StartScheduledTask[#]& //
CloudDeploy[#, Permissions -> "Public"] &

The former returns this, and the latter gives me this. I am pretty new to using the Wolfram Cloud so extensively, but it's more and more beginning to feel like a black box, which makes debugging pretty difficult because I am never sure where the issue truly lies; my thought is to wrap the scheduled task in an APIFunction, but I am not sure how to go about doing that, since there is no specific association I am looking to make for the information in the csv file. Is this the right way to go about this? How can I utilize APIFunction if I don't have an explicit set of rules I am looking to make and how is the Cloud processing all of the information I am attempting to send it?

POSTED BY: Jesse Dohmann
6 Replies
Posted 9 years ago
POSTED BY: Jesse Dohmann
Posted 9 years ago
POSTED BY: Jesse Dohmann

You can actually do all of it in the AutoRefreshed like this:

getSpreadSheet[] := Dataset[Flatten[Import["https://path-to-google-doc/export?format=csv", "CSV", CharacterEncoding -> "UTF8"]]];
CloudPut[getSpreadSheet[], CloudObject["OldSpreadSheet"]];
CloudDeploy[
    AutoRefreshed[
        Module[{currentCSV = getSpreadSheet[], oldCSV = CloudObject["OldSpreadSheet"]}, 
            If[currentCSV =!= CloudGet[oldCSV], 
                CloudPut[currentCSV, oldCSV];
                SendMail["To" -> "user@email.com", "AttachedExpressions" -> {currentCSV}]
            ];
            currentCSV
        ],
        "Hourly", 
        "CloudCDF"
    ],
Permissions -> "Public"

]

It's a little bit more involved than before since you need to keep track of what the old spread sheet looked like, but it only takes an extra CloudPut to handle that.

POSTED BY: Dylan Boliske
Posted 9 years ago

I've never seen this GenerateHTTPResponse function before, it's very useful! Can AutoRefreshed be used in conjunction with ScheduledTask? I ask because I have another function I've created:

CheckForChanges[] :=
 If[Length[csv] > 9, 
  SendMail["user@email.com", 
   csv]](*if new elements are added to csv sends email alert to user*)

That I would like to run every time the document is being checked and the value gets consequently updated

POSTED BY: Jesse Dohmann
POSTED BY: Dylan Boliske
POSTED BY: Andrew de Laix
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract