Skip to content

Commit

Permalink
implement CopySubmission class
Browse files Browse the repository at this point in the history
  • Loading branch information
gxagxagxa committed Oct 7, 2018
1 parent 0a2a552 commit c6eb0b9
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions dayu_job_center/src/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class SubmissionBase(object):
total = 1
total = 1.0
start_time = None
progress = 0.0
status = None
Expand All @@ -19,10 +19,11 @@ def __init__(self, cmd, total):
self.total = total

def setup(self):
pass
self.start_time = datetime.datetime.now()
self.progress = 0.0

def update_status(self, current):
raise NotImplementedError
self.progress = current / self.total

def start(self):
raise NotImplementedError
Expand All @@ -31,19 +32,34 @@ def stop(self):
raise NotImplementedError


class CopySubmission(SubmissionBase):
def start(self):
from unipath import Path
self.setup()
self.status = JOB_RUNNING

current = 0.0
from_files = self.cmd.get('from_files', [])
to_files = self.cmd.get('to_files', [])
for file_pair in zip(from_files, to_files):
self.update_status(current)
yield

from_file = Path(file_pair[0])
to_file = Path(file_pair[1])
to_files.parent.mkdir(parents=True)
from_file.copy(to_file)
current += 1
else:
self.status = JOB_FINISHED
yield


class TestSubmission(SubmissionBase):
pass


class RandomSleepSubmission(TestSubmission):
def setup(self):
super(RandomSleepSubmission, self).setup()
self.start_time = datetime.datetime.now()
self.progress = 0.0

def update_status(self, current):
self.progress = current / self.total

def start(self):
import random
import time
Expand All @@ -52,9 +68,9 @@ def start(self):
self.status = JOB_RUNNING
current = 0.0
while current <= self.total:
time.sleep(random.random())
self.update_status(current)
yield
time.sleep(random.random())
current += 1
self.update_status(current)

self.status = JOB_FINISHED

0 comments on commit c6eb0b9

Please sign in to comment.