Skip to content
Snippets Groups Projects
Commit 0c7e6d6c authored by Daniel Neuwirth's avatar Daniel Neuwirth
Browse files

enqueuedsaved

parent 4bb6998c
No related branches found
No related tags found
No related merge requests found
from __future__ import absolute_import, print_function, unicode_literals #Note to change it to a background job, just this file would need to be be edited
#please look up the branch URL_Upload
from .thumbnail import create_thumbnail, create_thumbnail_for_last_resource from .thumbnail import create_thumbnail, create_thumbnail_for_last_resource
import ckan.plugins.toolkit as toolkit import ckan.plugins.toolkit as toolkit
from pylons import config
import logging.config
import os.path
import paste.deploy
from paste.registry import Registry
from pylons import config, translator
from ckan.plugins import toolkit
from ckan.config.environment import load_environment
from ckan.lib.cli import MockTranslator
# Adapted from ckanext-archiver
def _register_translator():
"""
Register a translator in this thread.
"""
global registry
try:
registry
except NameError:
registry = Registry()
registry.prepare()
global translator_obj
try:
translator_obj
except NameError:
translator_obj = MockTranslator()
registry.register(translator, translator_obj)
# Adapted from ckanext-archiver
def load_config(ini_path):
"""
Load CKAN configuration.
"""
ini_path = os.path.abspath(ini_path)
logging.config.fileConfig(ini_path, disable_existing_loggers=False)
conf = paste.deploy.appconfig('config:' + ini_path)
load_environment(conf.global_conf, conf.local_conf)
_register_translator()
def job_after_create(ini_path,resource, private):
load_config(ini_path)
create_thumbnail(resource, private)
def enqueue_after_create(context, resource): def enqueue_after_create(context, resource):
package = context.get('package') package = context.get('package')
private = package.private private = package.private
...@@ -61,19 +11,6 @@ def enqueue_after_create(context, resource): ...@@ -61,19 +11,6 @@ def enqueue_after_create(context, resource):
# without the background job # without the background job
create_thumbnail(resource, private) create_thumbnail(resource, private)
#background job
#args = (config['__file__'], resource, private)
#title = 'Thumbnail creating for resource {}'.format(resource['id'])
#toolkit.enqueue_job(job_after_create, args=args, title=title)
def job_after_update(ini_path, resources, private, package_id):
load_config(ini_path)
create_thumbnail_for_last_resource(resources, private, package_id)
def enqueue_after_update(context, resource): def enqueue_after_update(context, resource):
package = context.get('package') package = context.get('package')
private = package.private private = package.private
...@@ -84,15 +21,6 @@ def enqueue_after_update(context, resource): ...@@ -84,15 +21,6 @@ def enqueue_after_update(context, resource):
# without the background job # without the background job
create_thumbnail_for_last_resource(resources, private, package_id) create_thumbnail_for_last_resource(resources, private, package_id)
#background job
#args = (config['__file__'], resources, private, package_id)
#title = 'Thumbnail updating for resource {}'.format(resource['id'])
#toolkit.enqueue_job(job_after_update, args=args, title=title)
def job_after_delete(ini_path , resources, private, package_id):
load_config(ini_path)
create_thumbnail_for_last_resource(resources, private, package_id)
def enqueue_after_delete(context, resources): def enqueue_after_delete(context, resources):
if len(resources) > 0: if len(resources) > 0:
package = context.get('package') package = context.get('package')
...@@ -103,11 +31,6 @@ def enqueue_after_delete(context, resources): ...@@ -103,11 +31,6 @@ def enqueue_after_delete(context, resources):
# without the background job # without the background job
create_thumbnail_for_last_resource(resources, private, package_id) create_thumbnail_for_last_resource(resources, private, package_id)
#background job
#args = (config['__file__'], resources, private, package_id)
#title = 'Thumbnail deleting for resource {}'.format(package_id)
#toolkit.enqueue_job(job_after_delete, args=args, title=title)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment