Models

Provide the Django models for interfacing with the job submission tasks.

+----------------+            +---------------+
| "Server"       | +--+------>| "Interpreter" |
+----------------+ |  |       +---------------+
| "interpreters" +-+  |
| "job_set"      +--+ |       +---------------+
+----------------+  | | +---->| "Result"      |
                    | | |     +---------------+
+----------------+  | | |
| "Job"          |<-+ | |     +---------------+
+----------------+    | | +-->| "Log"         |
| "interpreter"  +----+ | |   +---------------+
| "results"      +------+ |
| "logs"         +--------+   +---------------+
| "owner"        +----------->| "User"        |
+----------------+            +---------------+
class django_remote_submission.models.Server(*args, **kwargs)[source]

Encapsulates the remote server identifiers.

>>> from django_remote_submission.models import Server
>>> server = Server(
...     title='Remote',
...     hostname='foo.invalid',
...     port=22,
... )
>>> server.interpreters.set([python3])  # doctest: +SKIP
>>> server
<Server: Remote <foo.invalid:22>>
Parameters:
  • id (AutoField) – Id
  • created (AutoCreatedField) – Created
  • modified (AutoLastModifiedField) – Modified
  • title (CharField) – The human-readable name of the server
  • hostname (CharField) – The hostname used to connect to the server
  • port (IntegerField) – The port to connect to for SSH (usually 22)
  • interpreters (ManyToManyField) – List of interpreters available for this server
__str__()[source]

Convert model to string, e.g. "Remote <foo.invalid:22>".

exception DoesNotExist
exception MultipleObjectsReturned
class django_remote_submission.models.Job(*args, **kwargs)[source]

Encapsulates the information about a particular job.

>>> from django_remote_submission.models import Job
>>> job = Job(
...     title='My Job',
...     program='print("hello world")',
...     remote_directory='/tmp/',
...     remote_filename='foobar.py',
...     owner=user,
...     server=server,
...     interpreter=python3,
... )
>>> job
<Job: My Job>
Parameters:
  • id (AutoField) – Id
  • created (AutoCreatedField) – Created
  • modified (AutoLastModifiedField) – Modified
  • title (CharField) – The human-readable name of the job
  • uuid (UUIDField) – A unique identifier for use in grouping Result files
  • program (TextField) – The actual program to run (starting with a #!)
  • status (StatusField) – The current status of the program
  • remote_directory (CharField) – The directory on the remote host to store the program
  • remote_filename (CharField) – The filename to store the program to (e.g. reduce.py)
  • owner_id (ForeignKey to User) – The user that owns this job
  • server_id (ForeignKey to Server) – The server that this job will run on
  • interpreter_id (ForeignKey to Interpreter) – The interpreter that this job will run on
__str__()[source]

Convert model to string, e.g. "My Job".

clean()[source]

Ensure that the selected interpreter exists on the server.

To use effectively, add this to the django.db.models.signals.pre_save() signal for the Job model.

exception DoesNotExist
exception MultipleObjectsReturned
class django_remote_submission.models.Interpreter(*args, **kwargs)[source]

Encapsulates the executable and required arguments for each interpreter.

>>> from django_remote_submission.models import Interpreter
>>> python3 = Interpreter(
...     name='Python 3',
...     path='/usr/bin/python3',
...     arguments=['-u'],
... )
>>> python3
<Interpreter: Python 3 (/usr/bin/python3)>
Parameters:
  • id (AutoField) – Id
  • created (AutoCreatedField) – Created
  • modified (AutoLastModifiedField) – Modified
  • name (CharField) – The human-readable name of the interpreter
  • path (CharField) – The full path of the interpreter path.
  • arguments (ListField) – The arguments used when running the interpreter
__str__()[source]

Convert model to string, e.g. "Python 3 (/usr/bin/python3)".

exception DoesNotExist
exception MultipleObjectsReturned
class django_remote_submission.models.Result(*args, **kwargs)[source]

Encapsulates a resulting file produced by a job.

>>> from django_remote_submission.models import Result
>>> result = Result(
...     remote_filename='1.txt',
...     job=job,
... )
>>> result
<Result: 1.txt <My Job>>
Parameters:
  • id (AutoField) – Id
  • created (AutoCreatedField) – Created
  • modified (AutoLastModifiedField) – Modified
  • remote_filename (TextField) – The filename on the remote server for this result, relative to the remote directory of the job
  • local_file (FileField) – The filename on the local server for this result
  • job_id (ForeignKey to Job) – The job this result came from
__str__()[source]

Convert model to string, e.g. "1.txt <My Job>".

exception DoesNotExist
exception MultipleObjectsReturned
class django_remote_submission.models.Log(*args, **kwargs)[source]

Encapsulates a log message printed from a job.

>>> from django_remote_submission.models import Log
>>> from datetime import datetime
>>> log = Log(
...     time=datetime(year=2017, month=1, day=2, hour=3, minute=4, second=5),
...     content='Hello World',
...     stream='stdout',
...     job=job,
... )
>>> log
<Log: 2017-01-02 03:04:05 My Job>
Parameters:
  • id (AutoField) – Id
  • time (AutoCreatedField) – The time this log was created
  • content (TextField) – The content of this log message
  • stream (CharField) – Output communication channels. Either stdout or stderr.
  • job_id (ForeignKey to Job) – The job this log came from
__str__()[source]

Convert model to string, e.g. "2017-01-02 03:04:05 My Job".

exception DoesNotExist
exception MultipleObjectsReturned
django_remote_submission.models.job_result_path(instance, filename)[source]

Produce the path to locally store the job results.

Parameters:
  • instance (Result) – the Result instance to produce the path for
  • filename (str) – the original filename