def safe_log_job(job_name, log_lines): log_path = get_job_logs_path(job_name) try: _lock_log(log_path, log_lines) except (FileNotFoundError, OSError): create_job_logs_path(job_name=job_name) # Retry _lock_log(log_path, log_lines)
def test_build_job_logs_path_creation_deletion(self): job = BuildJobFactory() job_logs_path = get_job_logs_path(job.unique_name) create_job_logs_path(job.unique_name) open(job_logs_path, '+w') # Should be true, created by the signal assert os.path.exists(job_logs_path) is True delete_job_logs(job.unique_name) assert os.path.exists(job_logs_path) is False
def build_set_post_save(sender, **kwargs): instance = kwargs['instance'] instance.set_status(status=JobLifeCycle.CREATED) # Clean outputs and logs delete_job_logs(instance.unique_name) delete_job_outputs(instance.unique_name) # Create logs path create_job_logs_path(instance.unique_name)
def create_logs(self, temp): log_path = get_job_logs_path(self.job.unique_name, temp=temp) create_job_logs_path(job_name=self.job.unique_name, temp=temp) fake = Faker() self.logs = [] for _ in range(self.num_log_lines): self.logs.append(fake.sentence()) with open(log_path, 'w') as file: for line in self.logs: file.write(line) file.write('\n')
def setUp(self): super().setUp() project = ProjectFactory(user=self.auth_client.user) job = JobFactory(project=project) self.url = '/{}/{}/{}/jobs/{}/logs'.format(API_V1, project.user.username, project.name, job.id) log_path = get_job_logs_path(job.unique_name) create_job_logs_path(job_name=job.unique_name) fake = Faker() self.logs = [] for _ in range(self.num_log_lines): self.logs.append(fake.sentence()) with open(log_path, 'w') as file: for line in self.logs: file.write(line) file.write('\n')