Scheduler on Opalstack

61 views
Skip to first unread message

Gaël Princivalle

unread,
Nov 10, 2020, 4:25:36 AM11/10/20
to web2py-users

Hello.

Did someone tried to use the scheduler on Opalstack?

I was used to run this command to start a worker in Webfaction but in Opalstack it don't works:
nohup python web2py.py -K applicationname &

I've tried in also in the virtualenv no way.

Someone knows how I can do it?

Thanks.

António Ramos

unread,
Nov 10, 2020, 6:55:35 AM11/10/20
to web...@googlegroups.com
it worked for me. 

--
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/58d806b1-48e1-473b-82d4-5e2aaa0c8002n%40googlegroups.com.

Gaël Princivalle

unread,
Nov 11, 2020, 3:41:56 AM11/11/20
to web2py-users
Ok the problem was that the python command must be the one of the env.
So this works:
nohup ~/apps/web2py_folder1/env/bin/python ~/apps/web2py_folder1/web2py/web2py.py -K myapp1 &

However I've another another web2py in another folder with another app and it don't works:
nohup ~/apps/web2py_folder2/env/bin/python ~/apps/web2py_folder2/web2py/web2py.py -K myapp2 &
[1] 29291
$ nohup: ignoring input and appending output to ‘nohup.out’
[1]+  Exit 1                  nohup env/bin/python web2py/web2py.py -K myapp2

What a headache...

Gaël Princivalle

unread,
Nov 12, 2020, 2:17:21 AM11/12/20
to web2py-users
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

Dave S

unread,
Nov 12, 2020, 4:58:48 AM11/12/20
to web2py-users


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

Gaël Princivalle

unread,
Nov 12, 2020, 5:52:32 AM11/12/20
to web2py-users
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))

Gaël Princivalle

unread,
Nov 12, 2020, 2:01:40 PM11/12/20
to web2py-users
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.

AGRogers

unread,
Nov 12, 2020, 10:06:30 PM11/12/20
to web...@googlegroups.com
Regarding Scheduler code in, I understand you can put it in any Model file. 

--
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.
Reply all
Reply to author
Forward
0 new messages