def main(): """Simple demonstration of creating a job with a large number of subjobs and then after a short period checking the status of them""" jmain = Job(application=Executable(exe='sleep')) jmain.splitter = ArgSplitter(args= [ [random.randint(1,4)] for _ in range(1000)]) jmain.submit() time.sleep(60) try: t0 = time.monotonic() statuses = get_status(jmain) t1 = time.monotonic() except Exception as x: jmain.kill() raise x print(f'Evaluated status in {t1-t0:.4f} seconds') l = list(statuses.values()) print(f'Job summary:') print(f'Submitted : {l.count("submitted")}') print(f'Running : {l.count("running")}') print(f'Completed : {l.count("completed")}') print(f'Failed : {l.count("failed")}') jmain.kill()
def submit_job(job_name, zip_name, backend): """ Allows a user non-interactively submit a job (eg from a script) :param job_name: The name of the job (to be shown in DIRAC) :param zip_name: The path to the zip file :param backend: The backend to run, local or grid """ if not zipfile.is_zipfile(zip_name): # Not a zip file - so need to get them to enter again! print("The file you have supplied is not a zip file!") raise Exception( "ZIPFileError", "The ZIP file you supplied is not a ZIP file! Cannot continue.") j = Job() j.name = "grid-analysis_" + job_name # Tell Ganga it's running an executable j.application = Executable() j.application.exe = File('run_analyse.sh') if backend == "grid": grid_backend(j, zip_name) else: local_backend(j, zip_name) j.submit()
def submit_job_interactive(): job_name = raw_input("Job name? > ") foundzip = False while foundzip is False: zip_name = raw_input("Path to ZIP file? > ") if not zipfile.is_zipfile(zip_name): # Not a zip file - so need to get them to enter again! print("The file you have supplied is not a zip file!") foundzip = False else: foundzip = True backend_chosen = False while backend_chosen is False: backend_choice = raw_input("Grid backend? [Y/N] > ") if backend_choice.lower() == "y": backend = "grid" backend_chosen = True elif backend_choice.lower() == "n": backend = "local" backend_chosen = True else: backend_chosen = False j = Job() j.name = "grid-analysis_" + job_name # Tell Ganga it's running an executable: analyse.py j.application = Executable() j.application.exe = File('run_analyse.sh') j.application.args = [zip_name] j.inputfiles = [LocalFile('frames.zip'), LocalFile('dscreader.py'), LocalFile('analyse.py')] if backend == "grid": j.outputfiles = [DiracFile('grid-analysis-frames.csv')] j.backend = Dirac() else: j.outputfiles = [LocalFile('grid-analysis-frames.csv')] j.submit()
def submit_job(job_name, zip_name, backend): if not zipfile.is_zipfile(zip_name): # Not a zip file - so need to get them to enter again! print("The file you have supplied is not a zip file!") raise Exception("ZIPFileError", "The ZIP file you supplied is not a ZIP file! Cannot continue.") j = Job() j.name = "grid-analysis_" + job_name # Tell Ganga it's running an executable: analyse.py j.application = Executable() j.application.exe = File('run_analyse.sh') j.application.args = [zip_name] j.inputfiles = [LocalFile('frames.zip'), LocalFile('dscreader.py'), LocalFile('analyse.py')] j.outputfiles = [LocalFile('grid-analysis-frames.csv')] j.submit()
def submit_job_interactive(): """ Allow a user to interactively submit a job, either locally or on GridPP. This will check that their input is valid and submit the job. """ job_name = raw_input("Job name? > ") foundzip = False while foundzip is False: zip_name = raw_input( "Path to ZIP file? Full path on your system please! > ") if not zipfile.is_zipfile(zip_name): # Not a zip file - so need to get them to enter again! print("The file you have supplied is not a zip file!") foundzip = False else: foundzip = True backend_chosen = False while backend_chosen is False: print( "Note: Choosing the grid backend will automatically upload input to DIRAC storage in your home area for your VO." ) backend_choice = raw_input("Grid backend? [Y/N] > ") if backend_choice.lower() == "y": backend = "grid" backend_chosen = True elif backend_choice.lower() == "n": backend = "local" backend_chosen = True else: backend_chosen = False j = Job() j.name = "grid-analysis_" + job_name # Tell Ganga it's running an executable j.application = Executable() j.application.exe = File('run_analyse.sh') if backend == "grid": grid_backend(j, zip_name) else: local_backend(j, zip_name) j.submit()
import ganga.ganga from ganga import Job, Local, runMonitoring # Create a new job. j = Job(name="Simple Hello World") j.backend = Local() # Submit the job. j.submit() runMonitoring() print("Job Status:", j.status) # Print the stdout output of the job. output = j.peek("stdout", "more") print(output)
def test_job_data_same(self): job = Job() data = create_job_data(job) new_job = create_job_from_data(data) assert job.name == new_job.name assert job.application == new_job.application
def test_create_job_data(self): j = Job() data = create_job_data(j) print(data) assert isinstance(data, bytes)