Regarding Scheduler code in, I understand you can put it in any Model file.

On Fri, 13 Nov 2020, 5:01 am Gaël Princivalle, <gaelprinciva...@gmail.com>
wrote:

> I can see if I create a new app in Webpy 2.20.4 that the db file have this:
> if configuration.get('scheduler.enabled'):
>     from gluon.scheduler import Scheduler
>     scheduler = Scheduler(db,
> heartbeat=configuration.get('scheduler.heartbeat'))
>
> In my db.py file I don't have that, the scheduler is called at the end of
> the scheduler.py file and that's all.
>
> How can I adapt my db.py file to that?
> In my db.py file I have the connection strin of the db database (main
> tables) and the db_sc database (scheduler database):
> db = DAL('postgres://myuser:mypassword@localhost:5432/postg_db',
> check_reserved=['all'], pool_size=1, entity_quoting=True, bigint_id=True,
> migrate=False, fake_migrate_all=False)
> db_sc = DAL('postgres://myuser:mypassword@localhost:5432/postg_db_sc',
> check_reserved=['all'], pool_size=1, entity_quoting=True, bigint_id=True,
> migrate=False, fake_migrate_all=False)
>
> Thanks in advance for your help.
> Il giorno giovedì 12 novembre 2020 alle 11:52:32 UTC+1 Gaël Princivalle ha
> scritto:
>
>> Sure, here is the complete scheduler.py file:
>> My main DB is db, the DB with the scheduler tables is db_sc.
>> # -*- coding: utf-8 -*-
>>
>> def e_db():
>>     today = datetime.datetime.today()
>>     file_name = '%s_%s_%s_%s_%s:%s.csv' % (request.application,
>> today.day, today.month, today.year, today.hour, today.minute)
>>     file_url = '%s/static/z_backup/csv/%s' % (request.folder, file_name)
>>     db.export_to_csv_file(open(file_url, 'wb'))
>>     subject = 'Backup CSV %s' % request.application
>>     message = 'Il backup CSV di %s è stato salvato in %s.' %
>> (request.application, file_url)
>>     '''email_sent = mail.send(
>>                         to = 'm...@domain.com',
>>                         subject = subject,
>>                         reply_to = 'm...@domain.com',
>>                         message = message)'''
>>     db.commit()
>>
>> def sitemap_txt_auto():
>>     import os
>>     from gluon.myregex import regex_expose
>>     # Statics URLs
>>     exclusions =
>> ['make_slugs','get_fabbisogno','e_db','get_cart','get_product_cart','test_query','carrellon','ordine_verifican','order_sendn','brands',
>> 'cart_qty', 'cart_weight', 'carrello', 'ordine_verifica',
>> 'ordine_modifica_indirizzo', 'order_send', 'e_deb', 'fuzz',
>> 'googleaf365ee20ab65216', 'insert_product_enquiry',
>> 'insert_service_enquiry', 'prodotto', 'attivita_fattoria_didattica',
>> 'test', 'edit', 'user','unsubscribe','sitemap_txt','download', 'call',
>> 'data', 'upload', 'browse', 'delete']
>>     ctldir = os.path.join(request.folder,"controllers")
>>     ctls=os.listdir(ctldir)
>>     if 'appadmin.py' in ctls: ctls.remove('appadmin.py')
>>     if 'manage.py' in ctls: ctls.remove('manage.py')
>>     if 'admin.py' in ctls: ctls.remove('admin.py')
>>     if 'prod.py' in ctls: ctls.remove('prod.py')
>>     if 'default.py.1' in ctls: ctls.remove('default.py.1')
>>     sitemap='https://www.sitedomain.com'
>>     for ctl in ctls:
>>         if ctl.endswith(".bak") == False:
>>             filename = os.path.join(ctldir,ctl)
>>             data = open(filename, 'r').read()
>>             functions = regex_expose.findall(data)
>>             for f in functions:
>>                 if not any(f in s for s in exclusions): # if function is
>> not in exclustions
>>                     sitemap += '\r\n'
>>                     sitemap += 'https://www.sitedomain.com/%s' % (f)
>>     # Dynamic URLs
>>     # News
>>     news = db(db.news.on_line == True).select(db.news.ALL)
>>     for item in news:
>>         sitemap += '\r\n'
>>         sitemap += 'https://www.sitedomain.com/news?id=%s' % (str(item.id
>> ))
>>     # Products
>>     products = db(db.products.on_line == True).select(db.products.ALL)
>>     for item in products:
>>         sitemap += '\r\n'
>>         sitemap += 'https://www.sitedomain.com/prodotti?product_id=' +
>> (str(item.id)) + '&product_slug=' + item.product_slug
>>     # Categories
>>     sitemap += '\r\n'
>>     sitemap += 'https://www.sitedomain.com /prodotti?category_id=0'
>>     categories = db().select(db.products_categories.ALL)
>>     for item in categories:
>>         sitemap += '\r\n'
>>         sitemap += 'https://www. sitedomain.com
>> /prodotti?category_id=%s' % (str(item.id))
>>     # Servizi
>>     services = db().select(db.services.ALL)
>>     for item in services:
>>         sitemap += '\r\n'
>>         sitemap += '
>> https://www.sitedomain.com/attivita_fattoria_didattica?id=%s' % (str(
>> item.id))
>>     file = open('%s/static/sitemap.txt' %request.folder, 'w')
>>     file.write(sitemap)
>>     file.close()
>>     file = open('%s/static/sitemaps/sitemap.txt' %request.folder, 'w')
>>     file.write(sitemap)
>>     file.close()
>>     """email_sent = mail.send(
>>                         to = 'm...@domain.com',
>>                         subject = 'Sitemap',
>>                         reply_to = 'm...@domain.com',
>>                         message = 'La sitemap è stata generata con
>> successo.')"""
>>     db.commit()
>>
>> from gluon.scheduler import Scheduler
>> Scheduler(db_sc,dict(e_db=e_db, sitemap_txt_auto=sitemap_txt_auto))
>>
>>
>> Il giorno giovedì 12 novembre 2020 alle 10:58:48 UTC+1 snide...@gmail.com
>> ha scritto:
>>
>>>
>>>
>>> On Wednesday, November 11, 2020 at 11:17:21 PM UTC-8, Gaël Princivalle
>>> wrote:
>>>>
>>>> Running it without nohup I can see this error. How can I debug that?
>>>> This app was running first on Web2py 2.14.16 and now it runs on the
>>>> 2.20.4 version.
>>>>
>>>>  ~/apps/web2py_folder2/env/bin/python
>>>> ~/apps/web2py_folder2/web2py/web2py.py -K myapp2
>>>>
>>>> Traceback (most recent call last): File
>>>> "apps/web2py_folder2/web2py/web2py.py", line 41, in <module> import
>>>> gluon.widget File "/home/user/apps/web2py_folder2/web2py/gluon/widget.py",
>>>> line 27, in <module> from gluon.shell import die, run, test File
>>>> "/home/user/apps/web2py_folder2/web2py/gluon/shell.py", line 285
>>>> exec(read_pyc(pycfile), _env) SyntaxError: unqualified exec is not allowed
>>>> in function 'run' it contains a nested function with free variables
>>>>
>>>>>
>>>>>>>
>>> I'm guessing you have something different in how you've defined the
>>> scheduler routines, since it works for one case and not the other.  That
>>> doesn't mean the web2py code doesn't have a problem, but it does mean the
>>> problem isn't in the path of the working case.
>>>
>>> Can you show some of your models/scheduler.py code?
>>>
>>> /dps
>>>
>>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/1f4b4428-8bd4-450d-b2c6-5c121cd58ff8n%40googlegroups.com
> <https://groups.google.com/d/msgid/web2py/1f4b4428-8bd4-450d-b2c6-5c121cd58ff8n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CACWMBMN%3DZ3QRQQHdNdW88D0_dQqKfJ6tdTaJ2bBXPcY12PE2Yg%40mail.gmail.com.

Reply via email to