Beispiel #1
0
def videoExistsInMemcache(memcache, key):
    metadata = memcache.get('%s-metadata' % key)
    if metadata == None:
        return False
    chunkCount = struct.unpack('=L', metadata[:4])[0]
    for curChunk in xrange(chunkCount):
        if not memcache.touch('%s-%s' % (key, curChunk)):
            return False
    return True
def videoExistsInMemcache(memcache, key):
	metadata = memcache.get('%s-metadata' % key)
	if metadata == None:
		return False
	chunkCount = struct.unpack('=L', metadata[:4])[0]
	for curChunk in xrange(chunkCount):
		if not memcache.touch('%s-%s' % (key, curChunk)):
			return False
	return True
Beispiel #3
0
while time.time() < startTime + MINIMUM_RUN_PERIOD or memcache.get(
        trackerRequiredKey):
    cycleStartTime = time.time()
    # build stitched manifest
    manifest = manifestStitcher.getUpdatedManifest(liveStreamUrl,
                                                   adPositionsKey)
    # update the last used segment in memcache
    if manifestStitcher.lastUsedSegment != None:
        # Note: there is a race here between the get & set, but it shouldn't be a problem since trackers
        #		working on the same entry will more or less synchronized, if they aren't it's a problem anyway...
        savedLastUsedSegment = memcache.get(lastUsedSegmentKey)
        if savedLastUsedSegment == None or manifestStitcher.lastUsedSegment > int(
                savedLastUsedSegment):
            writeOutput('setting last used segment to %s' %
                        manifestStitcher.lastUsedSegment)
            memcache.set(lastUsedSegmentKey,
                         str(manifestStitcher.lastUsedSegment),
                         RESULT_MANIFEST_EXPIRY)

    # save the result to memcache
    memcache.set(outputMemcacheKey, manifest, RESULT_MANIFEST_EXPIRY)
    memcache.touch(ffmpegParamsKey, RESULT_MANIFEST_EXPIRY)

    # sleep until next cycle
    curTime = time.time()
    sleepTime = cycleStartTime + CYCLE_INTERVAL - curTime
    if sleepTime > 0:
        time.sleep(sleepTime)

writeOutput('Quitting...')
	executeCommand(cmdLine)
	

# main loop
manifestStitcher = ManifestStitcher()
startTime = time.time()
while time.time() < startTime + MINIMUM_RUN_PERIOD or memcache.get(trackerRequiredKey):
	cycleStartTime = time.time()
	# build stitched manifest
	manifest = manifestStitcher.getUpdatedManifest(liveStreamUrl, adPositionsKey)
	# update the last used segment in memcache
	if manifestStitcher.lastUsedSegment != None:
		# Note: there is a race here between the get & set, but it shouldn't be a problem since trackers
		#		working on the same entry will more or less synchronized, if they aren't it's a problem anyway...
		savedLastUsedSegment = memcache.get(lastUsedSegmentKey)
		if savedLastUsedSegment == None or manifestStitcher.lastUsedSegment > int(savedLastUsedSegment):
			writeOutput('setting last used segment to %s' % manifestStitcher.lastUsedSegment);
			memcache.set(lastUsedSegmentKey, str(manifestStitcher.lastUsedSegment), RESULT_MANIFEST_EXPIRY)
		
	# save the result to memcache
	memcache.set(outputMemcacheKey, manifest, RESULT_MANIFEST_EXPIRY)
	memcache.touch(ffmpegParamsKey, RESULT_MANIFEST_EXPIRY)
	
	# sleep until next cycle
	curTime = time.time()
	sleepTime = cycleStartTime + CYCLE_INTERVAL - curTime
	if sleepTime > 0:
		time.sleep(sleepTime)

writeOutput('Quitting...')