|
@@ -8,7 +8,7 @@ from threading import Thread
|
|
|
from subprocess import check_output
|
|
from subprocess import check_output
|
|
|
from bookworm import s3
|
|
from bookworm import s3
|
|
|
from bookworm.logger import log, setup_logger
|
|
from bookworm.logger import log, setup_logger
|
|
|
-from bookworm.constants import UNPACKABLE_EXTENSIONS, REDIS_UNPACK_FILE, REDIS_STATE_KEY, REDIS_STEP_KEY
|
|
|
|
|
|
|
+from bookworm.constants import UNPACKABLE_EXTENSIONS, REDIS
|
|
|
import redis
|
|
import redis
|
|
|
|
|
|
|
|
def should_unpack(fname):
|
|
def should_unpack(fname):
|
|
@@ -46,15 +46,15 @@ def delete_raw_file(s3client, s3key, meta):
|
|
|
s3client.delete_object(Bucket=meta['raw_file_bucket'], Key=s3key)
|
|
s3client.delete_object(Bucket=meta['raw_file_bucket'], Key=s3key)
|
|
|
|
|
|
|
|
def unpack_and_convert(job_key, s3key, s3client, redis, meta):
|
|
def unpack_and_convert(job_key, s3key, s3client, redis, meta):
|
|
|
- redis.hset(job_key, REDIS_STEP_KEY, 'UNPACKING')
|
|
|
|
|
|
|
+ redis.hset(job_key, REDIS.STEP_KEY, 'UNPACKING')
|
|
|
unpacked_files = unpack(s3key, s3client, redis, meta)
|
|
unpacked_files = unpack(s3key, s3client, redis, meta)
|
|
|
- redis.hset(job_key, REDIS_STEP_KEY, 'UNPACK_DONE')
|
|
|
|
|
|
|
+ redis.hset(job_key, REDIS.STEP_KEY, 'UNPACK_DONE')
|
|
|
log.info('Done unpacking job %s', job_key)
|
|
log.info('Done unpacking job %s', job_key)
|
|
|
|
|
|
|
|
for fname, data in unpacked_files:
|
|
for fname, data in unpacked_files:
|
|
|
if not fname.lower().endswith('mobi'):
|
|
if not fname.lower().endswith('mobi'):
|
|
|
- redis.hset(job_key, REDIS_STEP_KEY, 'CONVERTING')
|
|
|
|
|
- redis.hset(job_key, REDIS_STATE_KEY, fname)
|
|
|
|
|
|
|
+ redis.hset(job_key, REDIS.STEP_KEY, 'CONVERTING')
|
|
|
|
|
+ redis.hset(job_key, REDIS.STATE_KEY, fname)
|
|
|
log.info('Asked to store %s, need to convert first', fname)
|
|
log.info('Asked to store %s, need to convert first', fname)
|
|
|
fname_no_ext, ext = os.path.splitext(fname)
|
|
fname_no_ext, ext = os.path.splitext(fname)
|
|
|
with tempfile.NamedTemporaryFile(suffix=ext) as original:
|
|
with tempfile.NamedTemporaryFile(suffix=ext) as original:
|
|
@@ -82,7 +82,6 @@ def unpack(s3key, s3client, redis, meta):
|
|
|
|
|
|
|
|
to_extract = archive_contents(fd)
|
|
to_extract = archive_contents(fd)
|
|
|
if not to_extract:
|
|
if not to_extract:
|
|
|
- log.info(contents['lsarContents'])
|
|
|
|
|
log.error("Could not find any valid file")
|
|
log.error("Could not find any valid file")
|
|
|
return []
|
|
return []
|
|
|
|
|
|
|
@@ -100,8 +99,8 @@ def main():
|
|
|
setup_logger()
|
|
setup_logger()
|
|
|
s3client = s3.client()
|
|
s3client = s3.client()
|
|
|
while True:
|
|
while True:
|
|
|
- log.info('Waiting for message on %s', REDIS_UNPACK_FILE)
|
|
|
|
|
- topic, message = r.blpop(REDIS_UNPACK_FILE)
|
|
|
|
|
|
|
+ log.info('Waiting for message on %s', REDIS.Q_UNPACK_FILE)
|
|
|
|
|
+ topic, message = r.blpop(REDIS.Q_UNPACK_FILE)
|
|
|
|
|
|
|
|
log.info('got message: %s', message)
|
|
log.info('got message: %s', message)
|
|
|
params = json.loads(message.decode('utf-8'))
|
|
params = json.loads(message.decode('utf-8'))
|