How to avoid a web app timout whilst data-crunching? - python-3.x

Now my Python web app spends so much time data-crunching that PythonAnywhere assumes that the app has crashed and times out. (>5 mins = timeout)
My plan is (ultimately) to deliver the output to users by email, so they dont have to wait around anyway. ("Please check your email in 10 mins for your report").
I thought about doing a screen "refresh" periodically during the data-crunching to keep pythonanywhere happy - BUT if users close the browser then this isnt going to work.
How can I avoid a timeout and keep the app running for 10-15 mins without a browser?
Joe

PythonAnywhere dev here -- I think we've already discussed this over email, but I'll post what I said here just in case it's useful for other people.
A good option for stuff that takes a long time to run is to refactor it into a script that you can run periodically, and then schedule that on the "Tasks" tab. If you have a paid account, you can schedule up to 20 hourly tasks (we can bump that up if you need more), so to make the script run every (say) ten minutes, you could schedule it at 2 past the hour, 12 past the hour, and so on. If you need the script to process data that comes from the user via your website, you could make your view write something to the database with the details of what needs doing, then the scheduled task could pick that up, process it, and put the results in the DB for the website to pick up.
We've got a help page with a bit more information here.

Related

Bot scheduled messages using Cron have multiple-minute delay

I've been learning how to make Discord bots recently and have been experimenting with scheduled messages. Currently, I have 8 or so messages scheduled to send throughout the week. Some send at a certain time every single day, while some send at a specific time only on the weekends, etc.
Every few weeks or so, however, the messages start sending one minute later than they're supposed to. It started with just sending one minute late, so I adjusted the time in the job to one minute later, but the delay just keeps getting worse. Now the messages are sending 7 minutes later than they're supposed to according to the time I originally set in the job.
I'm very much an amateur, and I'm not sure what might be causing this.
The only thing I have been able to come up with to remedy the problem is adjusting the time in the job, but that's definitely not an ideal solution. It works for a little while, but then the message just delays even more.
The issue still persists even after I've reset the bot, refreshed the js files, etc. as I've been working on other bot functions.
Is there a way to reset those Cron tasks specifically, so they're running on time again. Is the reason just because I have other stuff going on in the command file where those jobs are started? If so, how could I remedy that besides moving it to a separate file?

Rescheduled to delete more contacts in next off-peak period

In Kentico (9) when I run the task "Delete inactive contacts" it never actually runs and the result is always "Rescheduled to delete more contacts in next off-peak period"
I've tried changing the settings to run once a week and I've tried creating a custom IDeleteContacts then setting it to use that custom class, but I always get the same result.
Any ideas?
By default, Kentico runs it's scheduled tasks in the tail of regular web requests. That's fine if you have traffic 24/7. If you don't, then you can run into all kinds of nastyness including the issue you're describing now because scheduled tasks are not executing.
If you're running on a Windows server you can setup a service to trigger scheduled tasks. If that's not an option, you can setup monitoring to hit your site every couple of minutes, for example UptimeRobot or Application Insights. You'll get the added bonus of being notified whenever the site goes down.
If you really need to clean up the EMS contacts because it's getting out of control, you can access the database directly and trigger the same stored procedure that the scheduled task uses. It's called [Proc_OM_Contact_MassDelete] and takes a where clause and a batch size. The where clause is where you specify the delete policy. For example
ContactCreated < GETDATE()-60 AND ([ContactEmail] IS NULL PR [ContactEmail]='')
With this where clause the stored proc would process contacts that were created over 60 days ago and don't have an e-mail address yet.
Please be aware that large volumes of EMS data will require database index tuning for this procedure to run within an acceptable period of time. This is true for EMS in general when your site has a decent amount of traffic.
If the standard Kentico cleanup doesn't work, for example because the database is unable to deal with millions of contacts, we've written a script to purge all EMS data. Use with caution ;)
do you have applied the latest hotfix (9.0.50) on your project? There was a bug when the deletion of inactive contacts took longer than 1 minute, the next run of the "Delete inactive contacts" scheduled task was not set, and the task did not execute again. You can download the package directly from this page: https://devnet.kentico.com/download/hotfixes
The "Delete inactive contacts" scheduled task only runs between 2am and 6am based on the servers time the site is running on. You can see this in the documentation. It only ever deletes a batch of 1000 contacts and never more. If you want to "trick" the site into running the scheduled task more, update the time on the server to 1:58am and restart the site.

Azure Webjob: will it retry if it doesn't get a response within a certain timeframe?

We have an Azure Webjob running on one of our websites that is supposed to run once a day, during the night. This generally processes some data, updates a few records ... It's a process that runs for a few minutes and in the end simply prints "OK".
The Webjob is set to run at 10 PM.
Now, we notice in our logging, that it does indeed run at 10PM, and then runs again at 10:01PM and 10:02PM and 10:03PM. It runs four times.
What I suppose is happening is that the job is taking some time to process (it takes about three minutes on our production environment) and the Azure Webjob keeps triggering it once every minute until it receives a response.
Can someone confirm or deny this? I've tried reading the documentation and googling for this specific problem, but couldn't find much information about it, other than that it might show this behavior if an exception is thrown (which is definitely not the case).
Can this behavior be configured in some way?

User Created Job Scheduling

I'm currently in the process of building an app in MeteorJS that allows users to create jobs and schedule them, e.g. Posting a link to social media every 2 hours. Are there any Meteor or Node packages that would make this possible? I've looked into https://github.com/percolatestudio/meteor-synced-cron, but I'm not sure that this would be the right approach for user submitted jobs (seems to be for jobs you create on app start-up). The idea would be that users could create these jobs and delete them later.
Thanks!
I've used https://github.com/percolatestudio/meteor-synced-cron in an app to check if invoices are due and then fire up email reminders. The jobs run on startup but if you set it to go through the collection of jobs, check the time they were created, and then fire something 2 hours after the creation, I'm sure you'll be able to get the work you need done
You can use a setInterval(); to loop every so often, maybe query a database or something for entries that are over 2 hours old, then act on them.

Polling a webpage periodically

I have a website where I need to poll a webpage in every minute or so. The page on the server will perform different task. I am trying to use Windows Scheduled Tasks, but that cannot be set to run in every minute. I know that there is cron jobs for this on Linux, but that is not available on Windows.
Any ideas how to do this on Windows?
Try with windows service. It can be set to start when system is started up without the need for someone to log in. Also check this article http://www.codeproject.com/KB/dotnet/WindowsServiceScheduler.aspx
The repeat interval drop-down goes down to 5 minutes here and I can easily type a 1 instead of the 5:
http://hypftier.de/temp/task.png
It gets this actually right, since when I click on OK, the description of the trigger reads:
http://hypftier.de/temp/task2.png
Or maybe that was added to Windows 7 or Vista, but I doubt it, actually.

Resources