Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
74faf9bc
authored
Apr 23, 2020
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create task to status polling
parent
a587ac4e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
recircle/recircle/celery.py
+11
-1
recircle/status/consumers.py
+0
-1
recircle/status/tasks.py
+8
-0
No files found.
recircle/recircle/celery.py
View file @
74faf9bc
...
...
@@ -13,7 +13,9 @@ app = Celery('proj')
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app
.
config_from_object
(
'django.conf:settings'
,
namespace
=
'CELERY'
)
# app.config_from_object('django.conf:settings', namespace='CELERY')
app
.
conf
.
broker_url
=
'redis://localhost:6379/0'
# Load task modules from all registered Django app configs.
app
.
autodiscover_tasks
()
...
...
@@ -22,3 +24,11 @@ app.autodiscover_tasks()
@app.task
(
bind
=
True
)
def
debug_task
(
self
):
print
(
'Request: {0!r}'
.
format
(
self
.
request
))
app
.
conf
.
beat_schedule
=
{
'polling-status-in-every-second'
:
{
'task'
:
'status.tasks.poll_status'
,
'schedule'
:
1.0
,
},
}
recircle/status/consumers.py
View file @
74faf9bc
...
...
@@ -30,5 +30,4 @@ class StatusConsumer(WebsocketConsumer):
pass
def
status_changed
(
self
,
event
):
logger
.
info
(
"Event received"
)
self
.
send
(
text_data
=
json
.
dumps
({
"vm"
:
event
[
"vm"
],
"status"
:
event
[
"status"
]}))
recircle/status/tasks.py
0 → 100644
View file @
74faf9bc
from
celery
import
shared_task
@shared_task
def
poll_status
():
from
instance.models
import
Instance
for
instance
in
Instance
.
objects
.
filter
(
deleted
=
False
):
instance
.
update_status
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment