[refactoring] Do not delete sources, just inactivate them. Also don't delete jobs.

This commit is contained in:
Adrià Mercader 2011-04-08 17:07:19 +01:00
parent 2588352bc5
commit 3c505693ff
2 changed files with 17 additions and 39 deletions

View File

@ -14,16 +14,14 @@ class Harvester(CkanCommand):
- create new harvest source
harvester rmsource {id}
- remove a harvester source (and associated jobs)
- remove (inactivate) a harvester source
harvester sources
harvester sources [all]
- lists harvest sources
If 'all' is defined, it also shows the Inactive sources
harvester job {source-id}
- create new harvest job
harvester rmjob {job-id}
- remove a harvest job
harvester jobs
- lists harvest jobs
@ -70,8 +68,6 @@ class Harvester(CkanCommand):
self.list_harvest_sources()
elif cmd == 'job':
self.create_harvest_job()
elif cmd == "rmjob":
self.remove_harvest_job()
elif cmd == 'jobs':
self.list_harvest_jobs()
elif cmd == 'run':
@ -145,13 +141,19 @@ class Harvester(CkanCommand):
print 'Please provide a source id'
sys.exit(1)
delete_harvest_source(source_id)
remove_harvest_source(source_id)
print 'Removed harvest source: %s' % source_id
def list_harvest_sources(self):
sources = get_harvest_sources()
if len(self.args) >= 2 and self.args[1] == 'all':
sources = get_harvest_sources()
what = 'harvest source'
else:
sources = get_harvest_sources(active=True)
what = 'active harvest source'
self.print_harvest_sources(sources)
self.print_there_are(what="harvest source", sequence=sources)
self.print_there_are(what=what, sequence=sources)
def create_harvest_job(self):
if len(self.args) >= 2:
@ -167,16 +169,6 @@ class Harvester(CkanCommand):
jobs = get_harvest_jobs(status=status)
self.print_there_are('harvest jobs', jobs, condition=status)
def remove_harvest_job(self):
if len(self.args) >= 2:
job_id = unicode(self.args[1])
else:
print 'Please provide a job id'
sys.exit(1)
delete_harvest_job(job_id)
print 'Removed harvest job: %s' % job_id
def list_harvest_jobs(self):
jobs = get_harvest_jobs()
self.print_harvest_jobs(jobs)

View File

@ -81,16 +81,15 @@ def create_harvest_source(source_dict):
return _source_as_dict(source)
def delete_harvest_source(source_id):
def remove_harvest_source(source_id):
try:
source = HarvestSource.get(source_id)
except:
raise Exception('Source %s does not exist' % source_id)
source.delete()
repo.commit_and_remove()
#TODO: Jobs?
# Don't actually delete the record, just flag it as inactive
source.active = False
source.save()
return True
@ -122,19 +121,6 @@ def create_harvest_job(source_id):
return _job_as_dict(job)
def delete_harvest_job(job_id):
try:
job = HarvestJob.get(job_id)
except:
raise Exception('Job %s does not exist' % job_id)
job.delete()
repo.commit_and_remove()
#TODO: objects?
return True
def run_harvest_jobs():
# Check if there are pending harvest jobs
jobs = get_harvest_jobs(status=u'New')