Commit 8ba917b2 authored by Jose Borreguero's avatar Jose Borreguero
Browse files

temporary clean_expired_sessions mock



Signed-off-by: default avatarJose Borreguero <borreguero@gmail.com>
parent 3643d24a
Pipeline #199120 failed with stages
in 5 minutes and 43 seconds
......@@ -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(
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]],
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:
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]],
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:
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")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment