question

TristanChambers-8544 avatar image
0 Votes"
TristanChambers-8544 asked ryanchill commented

Cron job in AppService? Or alternative?

Hi I need to run a periodic (nightly) background task for maintaining my system running in an Azure App Service -- Linux Python runtime. On a traditional VPS I would use cron for this task. Is cron the appropriate solution in the Azure App Service context? If not what would you recommend instead? If cron is appropriate is there anything I need to know in terms of the inherent impermanence of the system? I'm assuming that I would need to add the creation of the cron job to a custom deployment script, to ensure that it was in place any time the system was rebuilt.

Notes: I explored using WebJobs but, at the time of writing, the documentation says "WebJobs is not yet supported for App Service on Linux."
https://docs.microsoft.com/en-us/azure/app-service/webjobs-create


azure-functionsazure-webapps-webjobs
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How long do your jobs run for?

0 Votes 0 ·
lextm avatar image
1 Vote"
lextm answered TristanChambers-8544 commented

Azure Functions is always there and you just need a Timer triggered function,

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python#example

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Lextm, Azure Functions certainly does have a timer triggered function. I'm working in a monolithic environment running in Azure App Services. What's the best practice for configuring the Azure Function to call a Linux shell command on the target system in a secure and reliable way? I need a command like this to be called weekly: python manage.py clearsessions. Thanks

0 Votes 0 ·
KaranBhatt-5518 avatar image
1 Vote"
KaranBhatt-5518 answered ryanchill commented

@TristanChambers-8544 ,
Hope you are good.

I have found something that might help you to run Cron Job in Azure App service.

You can use the "SSH Console" of the Linux based App service which is located under Development Tools.

I have configure in that, and it is work proper as of now.

Ref. Link: https://docs.microsoft.com/en-us/azure/app-service/configure-linux-open-ssh-session

This service is might be in public preview currently but useful for configuring cron.

Vote up if it found helpful.

Regards,
Karan


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Karan, If I configure a cron job on the shell of the app service, would the crontab persist between system reboots and 'scaling up'? Let's not consider 'scaling out' for this discussion though. Thanks

0 Votes 0 ·
ryanchill avatar image ryanchill TristanChambers-8544 ·

You could try enabling App Cache by setting WEBSITES_ENABLE_APP_CACHE=true on the app service. But depending on the complexity of your app, this may or may not work for you.





0 Votes 0 ·