Re: Management command scheduling options

2023-10-23 Thread Rodrigo Bistolfi
Use devops for setting up cron jobs as part of the deployment process. You
could also use something like https://apscheduler.readthedocs.io/en/3.x/ if
you wanna something OS independent.

El lun, 23 oct 2023 a las 7:08, Mike Dewhirst ()
escribió:

> Django docs suggest cron or Windows scheduler for running management
> commands.
>
> I would like instead to build an internal Django based scheduler - because
> after migrating to a new server, setting up the new cron task will be
> forgotten.
>
> Is there a daily (approximately) event in a Django project I can hook into
> and test the date?
>
> The task is somewhat database intensive and needs to run quarterly for
> some users, monthly for most and weekly for others depending on their
> preferences.
>
> Ideas anyone?
>
> Thanks
>
> Mike
>
> --
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Your
> email software can handle signing.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7b29b24b-64f0-4f93-9a43-5d8f5e242b57%40dewhirst.com.au
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMQZ-Rf5sRxEZNEoGxHjh6f88FGsWHgTqCp%2BbUY4%2BH4GX3_7Kg%40mail.gmail.com.


Django channels raises TypeError on close: An asyncio.Future, a coroutine or an awaitable is required

2019-03-23 Thread Rodrigo Bistolfi
Hi there,

I am using Channels 2.1.7 with Python 3.7.2.
My consumer does this on connect:

async def connect(self): 
"""Accept connect if user has been provided by middleware"""  
self.user = self.scope.get('user') 
if self.user: 
await self.accept() 
else: 
await self.close() 

When `self.close()` is called, an exception is raised:

Traceback (most recent call last): 
  File 
"/opt/sps/.venv/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py"
, line 147, in run_asgi 
result = await asgi(self.asgi_receive, self.asgi_send) 
  File "/opt/sps/.venv/lib/python3.7/site-packages/channels/consumer.py", 
line 59, in __call__ 
[receive, self.channel_receive], self.dispatch 
  File "/opt/sps/.venv/lib/python3.7/site-packages/channels/utils.py", line 
59, in await_many_dispatch 
await task 
  File "/opt/sps/.venv/lib/python3.7/site-packages/channels/utils.py", line 
51, in await_many_dispatch 
result = task.result() 
  File 
"/opt/sps/.venv/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py"
, line 227, in asgi_receive 
data = await self.recv() 
  File "/opt/sps/.venv/lib/python3.7/site-packages/websockets/protocol.py", 
line 420, in recv 
return_when=asyncio.FIRST_COMPLETED, 
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 361, in wait 
fs = {ensure_future(f, loop=loop) for f in set(fs)} 
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 361, in 
fs = {ensure_future(f, loop=loop) for f in set(fs)} 
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 592, in 
ensure_future 
raise TypeError('An asyncio.Future, a coroutine or an awaitable is ' 
TypeError: An asyncio.Future, a coroutine or an awaitable is required 

The relevant code seems to be this:

while len(self.messages) <= 0: 
pop_message_waiter = asyncio.Future(loop=self.loop) 
self._pop_message_waiter = pop_message_waiter 
try: 
# If asyncio.wait() is canceled, it doesn't cancel 
# pop_message_waiter and self.transfer_data_task. 
tasks = [pop_message_waiter, self.transfer_data_task] 
yield from asyncio.wait( 
tasks, 
loop=self.loop,
return_when=asyncio.FIRST_COMPLETED,
)
finally:
self._pop_message_waiter = None 

In websockets/protocol.py line 410 and ss, `self.trasfer_data_task` is 
`None`. If I remove it from the wait list it seems to work.
Any ideas?

Thanks in advance, Rodrigo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d92a08a5-1080-4212-9cea-e46c53c4f3ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.