Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
reflectometry
django-remote-submission
Commits
8ba917b2
Commit
8ba917b2
authored
Mar 29, 2022
by
Jose Borreguero
Browse files
temporary clean_expired_sessions mock
Signed-off-by:
Jose Borreguero
<
borreguero@gmail.com
>
parent
3643d24a
Pipeline
#199120
failed with stages
in 5 minutes and 43 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
django_remote_submission/tasks.py
View file @
8ba917b2
...
@@ -27,11 +27,11 @@ logger = get_task_logger(__name__)
...
@@ -27,11 +27,11 @@ logger = get_task_logger(__name__)
try
:
try
:
from
celery
import
shared_task
from
celery
import
shared_task
except
ImportError
:
except
ImportError
:
logger
.
warning
(
'Could not import Celery. '
logger
.
warning
(
'Could not import Celery. '
'Tasks will not be implemented by Celery
\'
s queue.'
)
'Tasks will not be implemented by Celery
\'
s queue.'
)
def
shared_task
(
func
):
def
shared_task
(
func
):
"""Naive wrapper in case Celery does not exist."""
"""Naive wrapper in case Celery does not exist."""
def
delay
(
*
args
,
**
kwargs
):
def
delay
(
*
args
,
**
kwargs
):
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
...
@@ -119,9 +119,13 @@ class LogContainer(object):
...
@@ -119,9 +119,13 @@ class LogContainer(object):
"""
"""
LogLine
=
collections
.
namedtuple
(
'LogLine'
,
[
LogLine
=
collections
.
namedtuple
(
'now'
,
'output'
,
'LogLine'
,
])
[
'now'
,
'output'
,
],
)
def
__init__
(
self
,
job
,
log_policy
):
def
__init__
(
self
,
job
,
log_policy
):
"""Instantiate a log container.
"""Instantiate a log container.
...
@@ -151,10 +155,12 @@ class LogContainer(object):
...
@@ -151,10 +155,12 @@ class LogContainer(object):
"""
"""
if
self
.
log_policy
!=
LogPolicy
.
LOG_NONE
:
if
self
.
log_policy
!=
LogPolicy
.
LOG_NONE
:
lst
.
append
(
LogContainer
.
LogLine
(
lst
.
append
(
now
=
now
,
LogContainer
.
LogLine
(
output
=
output
,
now
=
now
,
))
output
=
output
,
)
)
if
self
.
log_policy
==
LogPolicy
.
LOG_LIVE
:
if
self
.
log_policy
==
LogPolicy
.
LOG_LIVE
:
self
.
flush
()
self
.
flush
()
...
@@ -210,9 +216,16 @@ class LogContainer(object):
...
@@ -210,9 +216,16 @@ class LogContainer(object):
@
shared_task
@
shared_task
def
submit_job_to_server
(
job_pk
,
password
=
None
,
key_filename
=
None
,
username
=
None
,
def
submit_job_to_server
(
timeout
=
None
,
log_policy
=
LogPolicy
.
LOG_LIVE
,
job_pk
,
store_results
=
None
,
remote
=
True
):
password
=
None
,
key_filename
=
None
,
username
=
None
,
timeout
=
None
,
log_policy
=
LogPolicy
.
LOG_LIVE
,
store_results
=
None
,
remote
=
True
,
):
"""Submit a job to the remote server.
"""Submit a job to the remote server.
This can be used as a Celery task, if the library is installed and running.
This can be used as a Celery task, if the library is installed and running.
...
@@ -304,9 +317,16 @@ def submit_job_to_server(job_pk, password=None, key_filename=None, username=None
...
@@ -304,9 +317,16 @@ def submit_job_to_server(job_pk, password=None, key_filename=None, username=None
@
shared_task
@
shared_task
def
copy_job_to_server
(
job_pk
,
password
=
None
,
key_filename
=
None
,
username
=
None
,
def
copy_job_to_server
(
timeout
=
None
,
log_policy
=
LogPolicy
.
LOG_LIVE
,
job_pk
,
store_results
=
None
,
remote
=
True
):
password
=
None
,
key_filename
=
None
,
username
=
None
,
timeout
=
None
,
log_policy
=
LogPolicy
.
LOG_LIVE
,
store_results
=
None
,
remote
=
True
,
):
"""Copy a job file to the remote server.
"""Copy a job file to the remote server.
This can be used as a Celery task, if the library is installed and running.
This can be used as a Celery task, if the library is installed and running.
...
@@ -352,7 +372,8 @@ def copy_job_to_server(job_pk, password=None, key_filename=None, username=None,
...
@@ -352,7 +372,8 @@ def copy_job_to_server(job_pk, password=None, key_filename=None, username=None,
log
=
Log
(
log
=
Log
(
time
=
timezone
.
now
(),
time
=
timezone
.
now
(),
content
=
'File {} successfully copied to {}.'
.
format
(
content
=
'File {} successfully copied to {}.'
.
format
(
job
.
remote_filename
,
job
.
remote_directory
,
job
.
remote_filename
,
job
.
remote_directory
,
),
),
stream
=
'stdout'
,
stream
=
'stdout'
,
job
=
job
,
job
=
job
,
...
@@ -366,12 +387,14 @@ def copy_job_to_server(job_pk, password=None, key_filename=None, username=None,
...
@@ -366,12 +387,14 @@ def copy_job_to_server(job_pk, password=None, key_filename=None, username=None,
@
shared_task
@
shared_task
def
copy_key_to_server
(
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
def
copy_key_to_server
(
username
:
str
,
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
password
:
str
,
username
:
str
,
hostname
:
str
,
password
:
str
,
port
:
int
=
22
,
hostname
:
str
,
remote
:
bool
=
True
)
->
None
:
port
:
int
=
22
,
remote
:
bool
=
True
,
)
->
None
:
r
"""Copy the client key to the remote server so the next connections
r
"""Copy the client key to the remote server so the next connections
do not need the password any further
do not need the password any further
The key will not be copied if it already exists on the remote server.
The key will not be copied if it already exists on the remote server.
...
@@ -393,14 +416,15 @@ def copy_key_to_server(public_key_filename: Optional[Union[PosixPath, str]],
...
@@ -393,14 +416,15 @@ def copy_key_to_server(public_key_filename: Optional[Union[PosixPath, str]],
@
shared_task
@
shared_task
def
delete_key_from_server
(
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
def
delete_key_from_server
(
username
:
str
,
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
password
:
Optional
[
str
],
username
:
str
,
key_filename
:
Optional
[
str
],
password
:
Optional
[
str
],
hostname
:
str
,
key_filename
:
Optional
[
str
],
port
:
int
=
22
,
hostname
:
str
,
remote
:
bool
=
True
port
:
int
=
22
,
)
->
None
:
remote
:
bool
=
True
,
)
->
None
:
r
"""Delete the client key from the remote server so the next connections
r
"""Delete the client key from the remote server so the next connections
will need password. This can be used at the logout of the session.
will need password. This can be used at the logout of the session.
...
@@ -419,3 +443,11 @@ def delete_key_from_server(public_key_filename: Optional[Union[PosixPath, str]],
...
@@ -419,3 +443,11 @@ def delete_key_from_server(public_key_filename: Optional[Union[PosixPath, str]],
with
wrapper
.
connect
(
password
=
password
,
key_filename
=
key_filename
):
with
wrapper
.
connect
(
password
=
password
,
key_filename
=
key_filename
):
wrapper
.
delete_key
(
public_key_filename
)
wrapper
.
delete_key
(
public_key_filename
)
return
None
return
None
# DEBUG: remove this mock task
@
shared_task
def
clean_expired_sessions
():
r
"""Print a silly message"""
print
(
"DEBUG: clean_expired_sessions"
)
# print to celery's log file /var/log/celery.log
open
(
"/tmp/clean_expired_sessions.log"
,
"a"
).
write
(
"DEBUG: clean_expired_sessions
\n
"
)
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