[refactoring] Do not delete sources, just inactivate them. Also don't delete jobs.
This commit is contained in:
parent
2588352bc5
commit
3c505693ff
|
@ -14,16 +14,14 @@ class Harvester(CkanCommand):
|
||||||
- create new harvest source
|
- create new harvest source
|
||||||
|
|
||||||
harvester rmsource {id}
|
harvester rmsource {id}
|
||||||
- remove a harvester source (and associated jobs)
|
- remove (inactivate) a harvester source
|
||||||
|
|
||||||
harvester sources
|
harvester sources [all]
|
||||||
- lists harvest sources
|
- lists harvest sources
|
||||||
|
If 'all' is defined, it also shows the Inactive sources
|
||||||
|
|
||||||
harvester job {source-id}
|
harvester job {source-id}
|
||||||
- create new harvest job
|
- create new harvest job
|
||||||
|
|
||||||
harvester rmjob {job-id}
|
|
||||||
- remove a harvest job
|
|
||||||
|
|
||||||
harvester jobs
|
harvester jobs
|
||||||
- lists harvest jobs
|
- lists harvest jobs
|
||||||
|
@ -70,8 +68,6 @@ class Harvester(CkanCommand):
|
||||||
self.list_harvest_sources()
|
self.list_harvest_sources()
|
||||||
elif cmd == 'job':
|
elif cmd == 'job':
|
||||||
self.create_harvest_job()
|
self.create_harvest_job()
|
||||||
elif cmd == "rmjob":
|
|
||||||
self.remove_harvest_job()
|
|
||||||
elif cmd == 'jobs':
|
elif cmd == 'jobs':
|
||||||
self.list_harvest_jobs()
|
self.list_harvest_jobs()
|
||||||
elif cmd == 'run':
|
elif cmd == 'run':
|
||||||
|
@ -145,13 +141,19 @@ class Harvester(CkanCommand):
|
||||||
print 'Please provide a source id'
|
print 'Please provide a source id'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
delete_harvest_source(source_id)
|
remove_harvest_source(source_id)
|
||||||
print 'Removed harvest source: %s' % source_id
|
print 'Removed harvest source: %s' % source_id
|
||||||
|
|
||||||
def list_harvest_sources(self):
|
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_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):
|
def create_harvest_job(self):
|
||||||
if len(self.args) >= 2:
|
if len(self.args) >= 2:
|
||||||
|
@ -167,16 +169,6 @@ class Harvester(CkanCommand):
|
||||||
jobs = get_harvest_jobs(status=status)
|
jobs = get_harvest_jobs(status=status)
|
||||||
self.print_there_are('harvest jobs', jobs, condition=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):
|
def list_harvest_jobs(self):
|
||||||
jobs = get_harvest_jobs()
|
jobs = get_harvest_jobs()
|
||||||
self.print_harvest_jobs(jobs)
|
self.print_harvest_jobs(jobs)
|
||||||
|
|
|
@ -81,16 +81,15 @@ def create_harvest_source(source_dict):
|
||||||
return _source_as_dict(source)
|
return _source_as_dict(source)
|
||||||
|
|
||||||
|
|
||||||
def delete_harvest_source(source_id):
|
def remove_harvest_source(source_id):
|
||||||
try:
|
try:
|
||||||
source = HarvestSource.get(source_id)
|
source = HarvestSource.get(source_id)
|
||||||
except:
|
except:
|
||||||
raise Exception('Source %s does not exist' % source_id)
|
raise Exception('Source %s does not exist' % source_id)
|
||||||
|
|
||||||
source.delete()
|
# Don't actually delete the record, just flag it as inactive
|
||||||
repo.commit_and_remove()
|
source.active = False
|
||||||
|
source.save()
|
||||||
#TODO: Jobs?
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -122,19 +121,6 @@ def create_harvest_job(source_id):
|
||||||
|
|
||||||
return _job_as_dict(job)
|
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():
|
def run_harvest_jobs():
|
||||||
# Check if there are pending harvest jobs
|
# Check if there are pending harvest jobs
|
||||||
jobs = get_harvest_jobs(status=u'New')
|
jobs = get_harvest_jobs(status=u'New')
|
||||||
|
|
Loading…
Reference in New Issue