Group Abstract Group Abstract

Message Boards Message Boards

0
|
1K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Issue with CloudDeploy on a ScheduledTask

Posted 6 months ago

I am trying to create ScheduledTask in my cloud account to run the below task on a daily basis, but WolframCloud is returning an error. Am I doing something wrong with building the task?  

BTW: I had to obscure sensitive detail; the task runs fine when done manually (not as a ScheduledTask).

Errors:

  • CloudSubmit: Cloud Server is not able to complete a request
  • CloudSubmit: --Message not Found--
task = 
	ScheduledTask[(dt = DateObject[Yesterday,TimeZone->"America/New_York"];
	csv = Import[HTTPRequest["XXXX", <|
		Method->"POST",
		"Body"-><|
			"query"->"SELECT latitude,longitude,trip FROM overland WHERE timestamp >= " <> ToString@UnixTime[DateObject[dt,TimeZone->"America/New_York"]]<>" AND timestamp < "<>ToString@UnixTime[DateObject[DatePlus[dt,1],TimeZone->"America/New_York"]]<>" AND wifi != 'Buehler?';"
			|>
		|>],"Dataset"];
	If [
		Length[csv]>1,
		tb=Table[{GeoPosition[{csv[[a,"latitude"]],csv[[a,"longitude"]]}],csv[[a,"trip"]]},{a,Length[csv]}];
		groupedData = KeySort[GroupBy[tb,Last]];
		map=GeoListPlot[
	  		Values@groupedData,
	  		PlotLegends->Placed[Keys@groupedData,Bottom],
	  		PlotMarkers->Point,
	  		PlotStyle->{PointSize[0.005]},
	  		ImageSize->{600,600},
	  		AspectRatio->1,
	  		GeoServer->"https://tile.openstreetmap.org/`1`/`2`/`3`.png",
	  		GeoScaleBar->{"Imperial", "Metric"},
	  		PlotLabel->Row[{
	  			Style["Overland", {"Text",Bold}],
		  		Style[" \[Bullet] "<>DateString[dt,"LocaleDateFull"],"Text"]
		 	 }],
			 ImageMargins->{{5,5},{10,5}}
		];
		URLExecute[HTTPRequest[
			"XXXX", <|
				Method->"POST",
				"Body"->{
					"authorization"->"XXXXXXXX",
					"file"->BaseEncode[ExportByteArray[map,"PNG"],"Base64"],
					"destination"->”xxx"
				}
				|>
			]
		]
	])
	,"Daily"
	,TimeZone->"America/New_York"
] 
POSTED BY: Steven Buehler
Posted 3 days ago

Steven,

The error message you are seeing, CloudSubmit: Cloud Server is not able to complete a request is often an internal server error (HTTP status 500) on the Wolfram Cloud server.

The fact that the task runs fine manually confirms your code is correct, but something is failing during the execution phase of the scheduled task. Issues with a ScheduledTask are often due to permissions, resources, or timeouts.

The Core Issue 1: Permissions and External APIs

Your code involves two crucial external network operations:

a) Fetching Data

Import[HTTPRequest["XXXX", ...]]

b) Uploading the Map

URLExecute[HTTPRequest["XXXX", ...]]

Scheduled tasks may not inherit the same execution permissions as your interactive session, which can cause these external network calls to fail.

Solution: Explicitly Enable External Network Access

When deploying the ScheduledTask, you must ensure that external network access is explicitly enabled using the Permissions option. While this is often implicitly handled in a manual session, it can be required for scheduled execution.

task = ScheduledTask[(... your task code ...), "Daily", TimeZone -> "America/New_York"];

CloudDeploy[task, 
    Permissions -> "Public", 
    AutoRemove -> False,
    Method -> {"ExternalNetwork", "Trusted"} (* <-- **CRITICAL CHANGE** *)
]

Adding Method -> {"ExternalNetwork", "Trusted"} is the most critical troubleshooting step to add to your CloudDeploy call.

It tells the cloud server that this task is trusted and allowed to make outbound network calls, which is essential for HTTPRequest and URLExecute.

Possible Issue 2: Timeouts and Resource Limits

Scheduled tasks are subject to stricter memory and time limits than interactive sessions. If your initial HTTPRequest or the subsequent GeoListPlot processing takes too long, the task could be terminated silently, leading to the server error.

Solution: Increase Timeout for HTTP Calls

Add a generous Timeout setting to your HTTPRequest to ensure that the task kernel is waiting long enough for the external API to respond:

csv = Import[
    HTTPRequest[
        "XXXX", 
        <| 
            Method -> "POST", 
            "Body" -> <| ... |> 
        |>
    ], 
    "Dataset",
    Timeout -> 60 (* Increase timeout to 60 seconds *)
];

Possible Issue 3: Server Instability

Since the error is server-side, you can try to isolate the deployment from the code execution by deploying a simple "wrapper" function instead of the raw ScheduledTask.

Solution: Deploy a Wrapper Function as a Workaround

A) Save the main logic as a Cloud Function:

Create a separate, simple function that performs the action and deploy it first.

cloudAction = CloudDeploy[
    Function[{dt}, 
        (* ALL of your complex code goes here, but use 'dt' instead of 
           DateObject[Yesterday, ...] *)
    ], 
    "MyDailyMapUpdater", 
    Permissions -> "Public"
]

B) Schedule the wrapper

Create a simpler ScheduledTask that just calls the deployed function.

CloudDeploy[
    ScheduledTask[
        cloudAction[DateObject[Yesterday, TimeZone -> "America/New_York"]],
        "Daily",
        TimeZone -> "America/New_York"
    ],
    Permissions -> "Public",
    Method -> {"ExternalNetwork", "Trusted"} (* Still needed for the main function *)
]

Hope this helps!

POSTED BY: Rob Pacey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard