1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2018-2021 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # classic use case of a job
29 if __name__ == '__main__':
31 launcher = salome.naming_service.Resolve('/SalomeLauncher')
32 job_params = salome.JobParameters()
33 job_params.resource_required = salome.ResourceParameters()
34 job_params.resource_required.name = "localhost"
35 job_params.resource_required.nb_proc = 1 # slurm: --ntasks
37 job_params.job_type = "command"
40 case_dir = tempfile.mkdtemp(prefix="test")
41 job_params.local_directory = cwd
42 job_params.job_file = "command.sh"
43 job_params.work_directory = os.path.join(case_dir, "run")
44 job_params.result_directory = os.path.join(case_dir, "result")
45 job_params.out_files = ["result.txt"]
46 job_params.wckey="P11U5:CARBONES"
47 job_params.job_name = "MyJob"
48 job_id = launcher.createJob(job_params)
49 launcher.launchJob(job_id)
50 job_string = launcher.dumpJob(job_id)
51 jobState = launcher.getJobState(job_id)
52 while jobState != 'FINISHED' and jobState != 'FAILED':
54 jobState = launcher.getJobState(job_id)
55 launcher.getJobResults(job_id, '')
56 launcher.getJobWorkFile(job_id, "result.txt", '')
57 launcher.clearJobWorkingDir(job_id)
58 launcher.removeJob(job_id)
59 new_id = launcher.restoreJob(job_string)
60 job_params_bis = launcher.getJobParameters(new_id)
61 jobState = launcher.getJobState(new_id)
62 launcher.removeJob(new_id)
63 launcher.saveJobs(os.path.join(case_dir,"savejobs.xml"))