On Tuesday, August 2, 2016 at 10:51:36 AM UTC-7, madhu nomula wrote:
>
> Hi All,
>
> I need help on below requirement.
>
> We have implemented Time sheet  logging tool for users in web2py tool.
>
> Now the requirement is to send email notifications to the users of tool, 
> to enter time sheet and submit.
> This email has to be sent for all users from 1 to 15 days of month and 16 
> to 30 days of month till the user submits time sheets.
>

I am not sure what you mean here ... That twice a month you start nagging 
the users?  That's the easiest interpretation.  Also, I think, easy to do 
... see below.
 

>
> Please suggest, how can I schedule this sending emails option in Web2Py 
> tool.
>

I recommend using the built-in scheduler.  This looks something like:
(read about it at 
<URL:http://web2py.com/books/default/chapter/29/04/the-core#web2py-Scheduler>)
(and note that this is untested, but based on my own scheduler usage and 
comments in this forum by Niphlod)

in your model file (scheduler.py is a good name)
# define scheduler task
   def send_nags(first_reminder = False):
      if first_reminder or now.date in [1, 16]:
        db(db.staff.ALL).update(curts_recd = False)
      mail = auth.settings.mailer         
      query = db.staff.curts_recd == False
      rows = db(query)
      for row in rows:
        msg = compose_reminder(row.id, ...)
        mail.send(to=row.email, reply_to="payroll@mybiz", message = msg)

# instantiate Scheduler class
from gluon.scheduler.import Scheduler
scheduler = Scheduler(db)


In one of your controller files:
# schedule recurring tasks:
def sched_tasks(arg1=""):
  # arg1 keeps this from being expose as a web page
  # instantiate Scheduler class
  from gluon.scheduler.import Scheduler
  scheduler = Scheduler(db)
  task = scheduler.queue_task("send_nags", period = 86400, repeats=1)
  # show on console, or add to log
  print task
  db.commit()

# also add as needed
def stop_tasks(arg1=""):
  # arg1 keeps this from being expose as a web page
  # instantiate Scheduler class
  from gluon.scheduler.import Scheduler
  scheduler = Scheduler(db)
  task = scheduler.task_status(db.scheduler_task.task_name == 'send_nags')
  if hasattr(task, "status") and task.status in ["QUEUED", "RUNNING"]:
     stop = scehduler.stop_task(task.uuid)
     # show on console or add to log
     print cue
     db.commit()




Use  these from the command line like this:
web2py.py -M -S uploader/default/sched_tasks 
or
web2py.py -M -S uploader/default/stop_tasks 

(and of course, you've used the -K option earlier to start the scheduler 
... you can add this to the startup sequence for your webserver)

 See
   <URL:https://groups.google.com/d/msg/web2py/9WrqIxi75JY/UHxICIC-BQAJ>
for more details.


-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to