[web2py] Re: Error background task with Redis
trying jose repo web2py-rq-dashboard, not sure how it's work - start worker in web is different from execute in terminal using rqworker (from web there is high-1,normal-1,low-1 in the queue column and in rqworker queue = default) - just run 1 rqworker in terminal but it shown 2 worker (from rqworker) - click test random queue, it seems ended with failed - start worker generate from web seems unstable, state change into pause and then gone (double check with rqinfo) *step i took:* *- copy repo* cd ~/python/web2py/applications git clone https://github.com/josedesoto/web2py-rq-dashboard rq *- start redis server from source install (stable version 4.0.9)* ./src/redis-server *- start web2py (stable version 2.16.1 on python 2.7)* source activate test2 python ~/python/web2py/web2py.py --nogui --no-banner -a a -i 0.0.0.0 -p 8000 *- open via browser* open http://localhost:8000/rq *- start rqworker in terminal* source activate test2 rqworker *- start rqinfo** in terminal* source activate test2 rqinfo perhaps i misunderstood about how this work, pls advice thx and best regards, stifan -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] how to start Celery worker in web2py
trying to learn web2py with celery, but an error occured *- install celery* source activate test2 pip install celery *- start redis server from source install (stable version 4.0.9)* ./src/redis-server *- start web2py (stable version 2.16.1 on python 2.7)* source activate test2 python ~/python/web2py/web2py.py --nogui --no-banner -a a -i 0.0.0.0 -p 8000 *- create new web2py app named : celery* *- create modules* modules/w2p_celery.py from celery import Celery mycelery = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0') *- create models* *models/thecelerymodel.py* from w2p_celery import mycelery celery = mycelery @celery.task(name='tasks.gen_url') def gen_url(x): return A(x, _href=URL('rule_the_world')) @celery.task(name='tasks.add_user') def add_user(): try: db.auth_user.insert(first_name='John') db.commit() except: db.rollback() *- create tasks.py in the same folder as web2py.py* #!/usr/bin/env python # -*- coding: utf-8 -*- import gluon.widget#forgot: why this is apparently the only way to fix custom imports ? from gluon.shell import env from gluon import current from celery import Celery def make_celery(app): celery = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0') TaskBase = celery.Task class ContextTask(TaskBase): abstract = True def __call__(self, *args, **kwargs): _env = env(a=app, import_models=True) globals().update(_env) return TaskBase.__call__(self, *args, **kwargs) celery.Task = ContextTask return celery celery = make_celery('celery') #be sure that you write this correctly @celery.task(name='tasks.gen_url') def gen_url(x): return A(x, _href=URL(x, 'rule_the_world')) @celery.task(name='tasks.add_user') def add_user(): #yes, for the love of your apps, wrap all db operations! try: db.auth_user.insert(first_name='miao') db.commit() except: db.rollback() *- start celery* cd ~/python/web2py/ source activate test2 python >>> import celery >>> celery worker -A tasks File "", line 1 celery worker -A tasks ^ SyntaxError: invalid syntax any idea? thanks and best regards, stifan -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] European General data protection act and web2py
I just went with cookie consent - from github - it just goes into layout.html and is only about 5 lines for simple setup - all JavaScript but works fine with Web2py. -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: Python Redis Queue
trying to learn web2py with rq but ended with error *- install rq* source activate test2 pip install rq *- start web2py (stable version 2.16.1 on python 2.7)* source activate test2 python ~/python/web2py/web2py.py --nogui --no-banner -a a -i 0.0.0.0 -p 8000 *- create new web2py app named : redis* *- create modules* *modules/queued_functions.py* #!/usr/bin/env python #-*- coding:utf-8 -*- # need to put this for mail to work import sys sys.path.append("/Users/sugizo/python/web2py") from gluon.tools import Mail def send_email(*args, **kwargs): mail = Mail() mail.settings.server = 'mail.hosting.com:25' mail.settings.sender = 'sen...@mail.com' mail.settings.login = 'lo...@mail.com:password' return mail.send(*args, **kwargs) *- add to models* *models/db.py* from redis import Redis from rq import Queue q = Queue(connection=Redis()) *- add to controllers* *controllers/default.py* def contact(): import queued_functions form = SQLFORM.factory(Field("name", label="your name"), Field("message", "text")) if form.accepts(request): q.enqueue(queued_functions.send_email, to="t...@mail.com", subject="%s contacted you" % form.vars.name, message=form.vars.message) return dict(form=form) *- start redis server from source install (stable version 4.0.9)* ./src/redis-server *- start rqworker* source activate test2 rqworker *- fill the form in browser : http://localhost:8000/redis/default/contact* *result in rqworker* 04:40:32 default: applications.redis.modules.queued_functions.send_email(message='a', subject='a contacted you', to='t...@mail.com') (b416fc6c-f6c9-4415-8194-0e75fdc47a10) 04:40:32 ImportError: No module named applications.redis.modules.queued_functions Traceback (most recent call last): File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/worker.py", line 789, in perform_job rv = job.perform() File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/job.py", line 573, in perform self._result = self._execute() File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/job.py", line 579, in _execute return self.func(*self.args, **self.kwargs) File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/job.py", line 206, in func return import_attribute(self.func_name) File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/utils.py", line 152, in import_attribute module = importlib.import_module(module_name) File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) ImportError: No module named applications.redis.modules.queued_functions Traceback (most recent call last): File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/worker.py", line 789, in perform_job rv = job.perform() File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/job.py", line 573, in perform self._result = self._execute() File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/job.py", line 579, in _execute return self.func(*self.args, **self.kwargs) File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/job.py", line 206, in func return import_attribute(self.func_name) File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/site-packages/rq/utils.py", line 152, in import_attribute module = importlib.import_module(module_name) File "/Users/sugizo/miniconda3/envs/test2/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) ImportError: No module named applications.redis.modules.queued_functions 04:40:32 Moving job to u'failed' queue 04:40:32 Cleaning registries for queue: default any idea? thanks and best regards, stifan -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] IS_LENGTH does not work with "list:string"
On Saturday, May 19, 2018 at 8:59:30 AM UTC-4, Anthony wrote: > > On Saturday, May 19, 2018 at 4:32:49 AM UTC-4, mweissen wrote: >> >> Hi Anthony, >> do you have an answer for the second problem? >> > > No, other than to submit a Github issue (or better yet, a pull request). > SQLFORM.accepts does convert to a list for insertion into the database but > fails to copy the list to form.vars. > On second thought, I'm not sure we should change the current behavior. Currently, request.vars.some_field and form.vars.some_field reflect the data returned by the form. If the same field name appears multiple times in the submitted form data, all the values go into a list -- otherwise, just a single value is associated with the field. request.vars and form.vars are not intended to replicate the data types of DAL database models, as not all forms are associated with DAL models. Anyway, if you want to pursue changing the current behavior, maybe open a discussion on the developers list, as this probably requires some thought (could break backward compatibility). Anthony -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] IS_LENGTH does not work with "list:string"
Ok, thank you again! 2018-05-19 14:59 GMT+02:00 Anthony : > On Saturday, May 19, 2018 at 4:32:49 AM UTC-4, mweissen wrote: >> >> Hi Anthony, >> do you have an answer for the second problem? >> > > No, other than to submit a Github issue (or better yet, a pull request). > SQLFORM.accepts does convert to a list for insertion into the database but > fails to copy the list to form.vars. > > For now: > > def listify(obj): > return obj if isinstance(obj, list) else [obj] > > listify(form.vars.auswahl) > > Anthony > > -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] IS_LENGTH does not work with "list:string"
On Saturday, May 19, 2018 at 4:32:49 AM UTC-4, mweissen wrote: > > Hi Anthony, > do you have an answer for the second problem? > No, other than to submit a Github issue (or better yet, a pull request). SQLFORM.accepts does convert to a list for insertion into the database but fails to copy the list to form.vars. For now: def listify(obj): return obj if isinstance(obj, list) else [obj] listify(form.vars.auswahl) Anthony -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] IS_LENGTH does not work with "list:string"
Hi Anthony, do you have an answer for the second problem? I want to get the number of items in the list "auswahl": form = SQLFORM.factory( Field("auswahl", "list:string"), ) - If there is only one item in "auswahl" then the type of form.vars.auswahl is string and len(form.vars.auswahl) is the length of the string. - If there is more than one item, the type is list and len(form.vars.auswahl) is the desired length. I think it would be better if "list:string" delivers always a list. Something like len(form.vars.auswahl) if isinstance(form.vars.auswahl, list) else 1 is not very pythonic. 2018-05-18 17:03 GMT+02:00 Anthony : > On Wednesday, May 16, 2018 at 1:35:02 PM UTC-4, mweissen wrote: >> >> I understand that there is no DEFAULT VALIDATOR for 'list:string', but it >> seems that is not possible to use IS_LENGTH at all. >> > > See the end of this section: http://web2py.com/ > books/default/chapter/29/07/forms-and-validators#Validators. In > particular, it notes that you can use IS_LIST_OF in conjunction with any > other validator. > > Anthony > > -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.