Having a function always running in the background

91 visualitzacions
Ves al primer missatge no llegit

mostwanted

no llegida,
1 de set. 2020, 9:41:271/9/20
a web2py-users

Is there a way to have a function always running without having to use a scheduler?
I have a function that i want to always send emails based on its arguments & conditions but i want it to run in the background unnoticed like a worker but not run by a scheduler, is this possible? I hope my question is clear.

Regards;

Mostwanted

Clemens

no llegida,
1 de set. 2020, 9:50:591/9/20
a web2py-users
Hi, I've done this via LOAD and ajax in an target div to have a graph always be updated if the user changes the model to be visualized. If the user changes the model, I trigger an update by an jquery reload. The data is exchanged via session and of course via the database. If you have no output in the DIV, the user won't see anything about your mailer.

Could this be an solution for you? If yes, do you know what to do or do you need more detailed information?

Regards
Clemens

Jim S

no llegida,
1 de set. 2020, 10:02:421/9/20
a web2py-users
The web2py scheduler pretty much is a background task that runs unnoticed.  

I use it in a number of places to queue hundreds or thousands of outbound emails.  I like the scheduler because it then also servers as a log of the emails that were sent.

If that isn't what you're looking for then how about celery or redis-queue?  But, they are a bother because then you have more services you need to grok, start up and manage.  The web2py scheduler takes care of all of that for you.  Let me know if you want to see a sample of how we handle it.

-Jim

mostwanted

no llegida,
1 de set. 2020, 12:59:021/9/20
a web2py-users
Hey Jim, I'm failing to understand the scheduler, please if its not a bother simplify it for me. In my script below I wanna send users who host stuff on my site emails when their subscription is left with 7 days to expire. Ideally twice a week for these 7 days. I'm hosting my app with pythonanywhere. How do i put it together?

CODE:
import datetime
def email_reminder():
    dt=db(db.house_owner).select()
    for dt in dt:
            now_dt=dt.expiry_date-request.now.date()
            now_dt2=now_dt.days
            new_con=dt.controller+1
            if now_dt2 <= 7:
                mail.send(to=dt.email_address,subject="House Hosting Reminder",message ='Hello %s %s, \nThis is a reminder that your house listing with our service will expire in %d days. \nTo increase your suscription time or for further details please contact us at the given details.\n\nBest regards;' % (dt.Name, dt.Surname, now_dt2))
                db(db.house_owner.controller).update(controller=new_con)

Regards;             

mostwanted

no llegida,
1 de set. 2020, 13:02:091/9/20
a web2py-users
Hey Clemens, the reason i'm running away from the scheduler honestly is because i dont understand it but i've asked Jim to show me how, your solution sounds very neat, if i still dont get the scheduler after Jim i'm reaching out to you.

Regards;

Jim S

no llegida,
1 de set. 2020, 14:48:341/9/20
a web2py-users
Ah, so this sounds a little different than what I thought you were after.

Looks like you want to run a task at a regularly scheduled time, not based on something that you've triggered in your application.

Given that information, I'd turn to the scheduler on my host system.  Are you running Linux then I'd just create a cron job.  Windows - add it to the windows scheduler (they still have that on windows server, right?)


to learn how to craft a command that would call my script to determine who to send emails to, and then send them.

Does that help?

(or, please correct me if my understanding of your problem is still off)

-Jim

mostwanted

no llegida,
2 de set. 2020, 3:09:152/9/20
a web2py-users
You are on point Jim, you get what i'm trying to achieve, let me see if i can put it together.

Regards;

Andy W

no llegida,
2 de set. 2020, 21:31:532/9/20
a web2py-users
If you are using PythonAnywhere, they have Scheduled Tasks and (for paid accounts) an Aways-on Task.
These are very simple to use. I use them for managing the queue of outgoing emails.

Andy

António Ramos

no llegida,
3 de set. 2020, 18:20:353/9/20
a web...@googlegroups.com
maybe this online cron can help.


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/b09e640c-fd89-4d03-803a-53b5f9e91df2n%40googlegroups.com.

Dave S

no llegida,
9 de set. 2020, 2:24:429/9/20
a web2py-users


On Tuesday, September 1, 2020 at 11:48:34 AM UTC-7, Jim S wrote:
Ah, so this sounds a little different than what I thought you were after.

Looks like you want to run a task at a regularly scheduled time, not based on something that you've triggered in your application.

Given that information, I'd turn to the scheduler on my host system.  Are you running Linux then I'd just create a cron job.  Windows - add it to the windows scheduler (they still have that on windows server, right?)
 
Tasks and the Windows scheduler are a pain, IMO.  The web2py scheduler can handle regularly schedule times, and the later versions have a way setting a scheduled task with a cron-like  description.

I use the web2py scheduler to run tasks at regular times, including cleaning sessions and reporting uploads.  I also use a plain old atq to run a psql script to make a weekly report, but I use the web2py scheduler to look for the report output file and mail it to my target users.

Having figured out the scheduler myself, I think it's pretty easy, and most of what you need is in Chapter 3 (The Core).  One of the helpful hints that Simone (Niphlod) cued me in on is my contribution to "Deployment".


[On the other hand, I was also shocked by someone on StackOverflow saying it was hard to use libcurl)




to learn how to craft a command that would call my script to determine who to send emails to, and then send them.

Does that help?

(or, please correct me if my understanding of your problem is still off)

-Jim


/dps
Respon a tots
Respon a l'autor
Reenvia
0 missatges nous