Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
363ddb70
Commit
363ddb70
authored
Aug 25, 2016
by
yumaojun03
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add celery support (not use django-celery)
parent
97a2e8bb
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
41 deletions
+35
-41
celery.py
apps/common/celery.py
+21
-0
settings.py
apps/jumpserver/settings.py
+0
-3
__init__.py
apps/ops/__init__.py
+1
-0
tasks.py
apps/ops/tasks.py
+13
-38
No files found.
apps/common/celery.py
0 → 100644
View file @
363ddb70
from
__future__
import
absolute_import
from
celery
import
Celery
# import traceback
# # Import project config setting
# try:
# from config import config as env_config, env
# JMS_CONF = env_config.get(env, 'default')()
# print "ok"
# except ImportError:
# traceback.print_exc()
# JMS_CONF = type('_', (), {'__getattr__': None})()
# print "false"
app
=
Celery
(
'common'
,
broker
=
'redis://localhost:6379/0'
,
backend
=
'redis://localhost:6379/0'
,
include
=
[
'ops.tasks'
])
apps/jumpserver/settings.py
View file @
363ddb70
...
...
@@ -23,8 +23,6 @@ sys.path.append(os.path.dirname(BASE_DIR))
try
:
from
config
import
config
as
env_config
,
env
CONFIG
=
env_config
.
get
(
env
,
'default'
)()
BROKER_URL
=
CONFIG
.
BROKER_URL
except
ImportError
:
CONFIG
=
type
(
'_'
,
(),
{
'__getattr__'
:
None
})()
...
...
@@ -57,7 +55,6 @@ INSTALLED_APPS = [
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'djcelery'
,
]
MIDDLEWARE
=
[
...
...
apps/ops/__init__.py
View file @
363ddb70
apps/ops/tasks.py
View file @
363ddb70
from
celery
import
Celery
from
django.conf
import
settings
from
time
import
sleep
app
=
Celery
(
'ops'
,
broker
=
settings
.
BROKER_URL
)
@app.task
()
def
UploadTask
(
message
):
# Update the state. The meta data is available in task.info dicttionary
# The meta data is useful to store relevant information to the task
# Here we are storing the upload progress in the meta.
UploadTask
.
update_state
(
state
=
'PROGRESS'
,
meta
=
{
'progress'
:
0
})
sleep
(
30
)
UploadTask
.
update_state
(
state
=
'PROGRESS'
,
meta
=
{
'progress'
:
30
})
sleep
(
30
)
return
message
def
get_task_status
(
task_id
):
# If you have a task_id, this is how you query that task
task
=
UploadTask
.
AsyncResult
(
task_id
)
status
=
task
.
status
progress
=
0
if
status
==
u'SUCCESS'
:
progress
=
100
elif
status
==
u'FAILURE'
:
progress
=
0
elif
status
==
'PROGRESS'
:
progress
=
task
.
info
[
'progress'
]
return
{
'status'
:
status
,
'progress'
:
progress
}
\ No newline at end of file
from
__future__
import
absolute_import
from
common.celery
import
app
import
time
@app.task
def
longtime_add
(
x
,
y
):
print
'long time task begins'
# sleep 5 seconds
time
.
sleep
(
5
)
print
'long time task finished'
return
x
+
y
\ No newline at end of file
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