コード例 #1
0
ファイル: tasks.py プロジェクト: shahar3012/Sub-Zero.bundle
    def run(self):
        self.running = True
        missing_count = len(self.items_searching)
        items_done_count = 0

        for item_id, title in self.items_searching:
            Log.Debug(u"Task: %s, triggering refresh for %s (%s)", self.name, title, item_id)
            searchMissing(item_id, title)
            search_started = datetime.datetime.now()
            tries = 1
            while 1:
                if item_id in self.items_done:
                    items_done_count += 1
                    Log.Debug(u"Task: %s, item %s done", self.name, item_id)
                    self.percentage = int(items_done_count * 100 / missing_count)
                    break

                if (datetime.datetime.now() - search_started).total_seconds() > self.stall_time:
                    if tries > 3:
                        self.items_failed.append(item_id)
                        Log.Debug(u"Task: %s, item stalled for %s times: %s, skipping", self.name, tries, item_id)
                        break

                    Log.Debug(u"Task: %s, item stalled for %s seconds: %s, retrying", self.name, self.stall_time, item_id)
                    tries += 1
                    searchMissing(item_id, title)
                    search_started = datetime.datetime.now()
                    time.sleep(1)
                time.sleep(0.5)
            time.sleep(2)
        Log.Debug("Task: %s, done. Failed items: %s", self.name, self.items_failed)
        self.running = False
コード例 #2
0
ファイル: tasks.py プロジェクト: utajum/Sub-Zero
    def run(self):
	self.items_done = []
	missing = getAllRecentlyAddedMissing()
	ids = set([id for id, title in missing])
	self.items_searching = ids
	self.ready_for_display = True

	missing_count = len(ids)
	
	# dispatch all searches
	time_start = datetime.datetime.now()
	searchMissing(missing)

	while 1:
	    if set(self.items_done).intersection(ids) == ids:
		Log.Debug("Task: %s, all items done", self.name)
		break
	    self.percentage = int(round(len(self.items_done) * 100 / missing_count))
	    time.sleep(0.1)

	self.last_run_time = datetime.datetime.now() - time_start
	self.percentage = 0
	self.ready_for_display = False