def main(): AWS_CREDENTIALS = utils.load_aws_credentials(base) ac, sk = AWS_CREDENTIALS.S3.access_key, AWS_CREDENTIALS.S3.secret_key S3_CONN = S3.AWSAuthConnection(ac, sk) S3_URL_GENERATOR = S3.QueryStringAuthGenerator(ac, sk, is_secure=False) S3_URL_GENERATOR.set_expires_in(60*60*2) # from wonderful PEP 3143: http://www.python.org/dev/peps/pep-3143/ daemon_context = daemon.DaemonContext() daemon_context.pidfile = lockfile.FileLock(join(base, 'pids', 'transcoder.pid')) with daemon_context: transcoder = TranscoderDaemon() transcoder.main()
def main(): AWS_CREDENTIALS = utils.load_aws_credentials(base) ac, sk = AWS_CREDENTIALS.S3.access_key, AWS_CREDENTIALS.S3.secret_key S3_CONN = S3.AWSAuthConnection(ac, sk) S3_URL_GENERATOR = S3.QueryStringAuthGenerator(ac, sk, is_secure=False) S3_URL_GENERATOR.set_expires_in(60*60*2) daemon_context = daemon.DaemonContext() # daemon_context.pidfile = lockfile.FileLock(os.path.join(base, 'pids', 'transcoder.pid')) # daemon_context.working_directory = base with daemon_context: transcoder = TranscoderDaemon() transcoder.main()
utils.lock_on_string(cursor, 'video_queue', 1000000); try: current_video = models.Video.objects.filter(status='pending_upload_to_s3')[0] except: utils.unlock_on_string(cursor, 'video_queue') time.sleep(10) continue remote_check = S3_CONN._make_request('HEAD', 'camera', 'originals/%s' % current_video.md5, {}, {}) if remote_check.status == 200: logging.info("File %s already exists on S3." % current_video.md5) else: tmp_video_file = self.get_tmp_video(current_video.md5) logging.info("Got pending video %s and started uploading to S3." % current_video.md5) options = {'Content-Type': current_video.mimetype or 'application/octet-stream', 'X-Amz-Acl': 'private'} S3_CONN.put(S3UploaderDaemon.S3_BUCKET_NAME, "originals/%s" % current_video.md5, S3.S3Object(tmp_video_file), options) logging.info("Finished uploading %s to S3." % current_video.md5) current_video.status = 'pending_transcoding' current_video.save() utils.unlock_on_string(cursor, 'video_queue'); except: file_name = os.path.join(base, '..', 'log', 's3_uploader-%s.error' % str(time.time()).replace('.', '')) logging.info("OMGWTFLOLBBQ: %s." % file_name) error_details = open(file_name, 'w') traceback.print_exc(file=error_details) error_details.close() time.sleep(15) if __name__ == '__main__': AWS_CREDENTIALS = utils.load_aws_credentials(base) S3_CONN = S3.AWSAuthConnection(AWS_CREDENTIALS.S3.access_key, AWS_CREDENTIALS.S3.secret_key) S3UploaderDaemon().main()