Skip to content
GitLab
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__)
try
:
from
celery
import
shared_task
except
ImportError
:
logger
.
warning
(
'Could not import Celery. '
'Tasks will not be implemented by Celery
\'
s queue.'
)
logger
.
warning
(
'Could not import Celery. '
'Tasks will not be implemented by Celery
\'
s queue.'
)
def
shared_task
(
func
):
"""Naive wrapper in case Celery does not exist."""
def
delay
(
*
args
,
**
kwargs
):
return
func
(
*
args
,
**
kwargs
)
...
...
@@ -119,9 +119,13 @@ class LogContainer(object):
"""
LogLine
=
collections
.
namedtuple
(
'LogLine'
,
[
'now'
,
'output'
,
])
LogLine
=
collections
.
namedtuple
(
'LogLine'
,
[
'now'
,
'output'
,
],
)
def
__init__
(
self
,
job
,
log_policy
):
"""Instantiate a log container.
...
...
@@ -151,10 +155,12 @@ class LogContainer(object):
"""
if
self
.
log_policy
!=
LogPolicy
.
LOG_NONE
:
lst
.
append
(
LogContainer
.
LogLine
(
now
=
now
,
output
=
output
,
))
lst
.
append
(
LogContainer
.
LogLine
(
now
=
now
,
output
=
output
,
)
)
if
self
.
log_policy
==
LogPolicy
.
LOG_LIVE
:
self
.
flush
()
...
...
@@ -210,9 +216,16 @@ class LogContainer(object):
@
shared_task
def
submit_job_to_server
(
job_pk
,
password
=
None
,
key_filename
=
None
,
username
=
None
,
timeout
=
None
,
log_policy
=
LogPolicy
.
LOG_LIVE
,
store_results
=
None
,
remote
=
True
):
def
submit_job_to_server
(
job_pk
,
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.
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
@
shared_task
def
copy_job_to_server
(
job_pk
,
password
=
None
,
key_filename
=
None
,
username
=
None
,
timeout
=
None
,
log_policy
=
LogPolicy
.
LOG_LIVE
,
store_results
=
None
,
remote
=
True
):
def
copy_job_to_server
(
job_pk
,
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.
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,
log
=
Log
(
time
=
timezone
.
now
(),
content
=
'File {} successfully copied to {}.'
.
format
(
job
.
remote_filename
,
job
.
remote_directory
,
job
.
remote_filename
,
job
.
remote_directory
,
),
stream
=
'stdout'
,
job
=
job
,
...
...
@@ -366,12 +387,14 @@ def copy_job_to_server(job_pk, password=None, key_filename=None, username=None,
@
shared_task
def
copy_key_to_server
(
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
username
:
str
,
password
:
str
,
hostname
:
str
,
port
:
int
=
22
,
remote
:
bool
=
True
)
->
None
:
def
copy_key_to_server
(
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
username
:
str
,
password
:
str
,
hostname
:
str
,
port
:
int
=
22
,
remote
:
bool
=
True
,
)
->
None
:
r
"""Copy the client key to the remote server so the next connections
do not need the password any further
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]],
@
shared_task
def
delete_key_from_server
(
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
username
:
str
,
password
:
Optional
[
str
],
key_filename
:
Optional
[
str
],
hostname
:
str
,
port
:
int
=
22
,
remote
:
bool
=
True
)
->
None
:
def
delete_key_from_server
(
public_key_filename
:
Optional
[
Union
[
PosixPath
,
str
]],
username
:
str
,
password
:
Optional
[
str
],
key_filename
:
Optional
[
str
],
hostname
:
str
,
port
:
int
=
22
,
remote
:
bool
=
True
,
)
->
None
:
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.
...
...
@@ -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
):
wrapper
.
delete_key
(
public_key_filename
)
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
Supports
Markdown
0%
Try again
or
attach a new 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