fix: task slicing index range restraints

This commit is contained in:
2026-07-08 14:47:35 +08:00
parent 036519ca98
commit feb3020fba
2 changed files with 21 additions and 23 deletions
+4 -4
View File
@@ -379,7 +379,7 @@ $.set('#subcategory', 'change', (e) => {
}); });
$.set('#chunksize', 'change', (e) => { $.set('#chunksize', 'change', (e) => {
let limit = Math.max(minor, major - 1); let limit = Math.max(minor || major - 1, 0);
let value = Math.floor(limit / e.target.valueAsNumber); let value = Math.floor(limit / e.target.valueAsNumber);
$('#limit').value = value; $('#limit').value = value;
$('#offset').max = value; $('#offset').max = value;
@@ -448,11 +448,11 @@ while (await new Promise(o => setTimeout(o, 1000, true))) {
$('#send').classList.add('pulse'); $('#send').classList.add('pulse');
$('#timezoneLabel').innerText = Temporal.Now.zonedDateTimeISO(locale.timezone).toLocaleString(locale.name); $('#timezoneLabel').innerText = Temporal.Now.zonedDateTimeISO(locale.timezone).toLocaleString(locale.name);
let { done, skip, omit, email, subject, recipient } = await Rpc2.invoke('progress').catch(() => new Object()); let { done, skip, email, subject, recipient } = await Rpc2.invoke('progress').catch(() => new Object());
let limit = minor || major - 1; let count = done + skip;
let limit = Math.max(minor || major - 1, 0);
let chunk = $('#chunksize').valueAsNumber; let chunk = $('#chunksize').valueAsNumber;
let total = $('#slice').checked ? Math.min(chunk, limit - chunk * $('#offset').valueAsNumber) : limit; let total = $('#slice').checked ? Math.min(chunk, limit - chunk * $('#offset').valueAsNumber) : limit;
let count = $('#slice').checked ? done + skip - omit : done + skip;
$('#progressLabel').innerText = `${parseFloat(count / total * 100).toFixed(2)}% (${count}/${total})`; $('#progressLabel').innerText = `${parseFloat(count / total * 100).toFixed(2)}% (${count}/${total})`;
$('#subjectLabel').innerText = subject ?? ''; $('#subjectLabel').innerText = subject ?? '';
+17 -19
View File
@@ -347,6 +347,7 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
class MismatchedEmailSubject(Exception): pass class MismatchedEmailSubject(Exception): pass
class MismatchedEmailAddress(Exception): pass class MismatchedEmailAddress(Exception): pass
class Next(Exception): pass
while True: while True:
try: try:
@@ -373,7 +374,7 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
progress['done'] = 0 progress['done'] = 0
progress['skip'] = 0 progress['skip'] = 0
progress['omit'] = 0 progress['next'] = 0
progress['subject'] = subject progress['subject'] = subject
logger.info('Done') logger.info('Done')
except Cancel: except Cancel:
@@ -407,15 +408,17 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
logger.warning("[%d/%d] Exhausted all allowed attempts; skipping", index-1, limit-1) logger.warning("[%d/%d] Exhausted all allowed attempts; skipping", index-1, limit-1)
raise Skip() raise Skip()
if index < options.get('start', 2) or progress['done'] >= options.get('limit', limit): if options.get('slice') and (start := options.get('start')) and (end := options.get('limit')):
logger.info("[%d/%d] Not planned; skipping '%s'", index-1, limit-1, email) if index < start or index > start + end:
progress['omit'] += 1 logger.info("[%d/%d] Not planned; skipping '%s'", index-1, limit-1, email)
raise Skip() raise Next()
if (items := options.get('subcategories')) and (item := str(cell(index, column.region).value)) not in items:
logger.info("[%d/%d] Value '%s' not enlisted; skipping '%s'", index-1, limit-1, item, email)
raise Next()
if (sent := cell(index, column.sent).value) is not None and str(sent).strip(): if (sent := cell(index, column.sent).value) is not None and str(sent).strip():
logger.info("[%d/%d] Already visited; skipping '%s'", index-1, limit-1, email) logger.info("[%d/%d] Already visited; skipping '%s'", index-1, limit-1, email)
occurrence[code] += 1 occurrence[code] += 1
progress['omit'] += 1
raise Skip() raise Skip()
match options.get('occurrence'): match options.get('occurrence'):
@@ -428,11 +431,6 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
logger.info("[%d/%d] No Spam! Skipping '%s'", index-1, limit-1, email) logger.info("[%d/%d] No Spam! Skipping '%s'", index-1, limit-1, email)
raise Skip() raise Skip()
if options.get('slice') and (sub := options.get('subcategories')):
if (value := str(cell(index, column.region).value)) not in sub:
logger.info("[%d/%d] Value '%s' not enlisted; skipping '%s'", index-1, limit-1, value, email)
raise Skip()
while mails := driver.find_elements(By.CSS_SELECTOR, "div.io-ox-mail-compose-window"): while mails := driver.find_elements(By.CSS_SELECTOR, "div.io-ox-mail-compose-window"):
try: try:
click(mails[0].find_element(By.CSS_SELECTOR, "button[data-action='close']"), wait=False) click(mails[0].find_element(By.CSS_SELECTOR, "button[data-action='close']"), wait=False)
@@ -486,8 +484,8 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
hello += ',' hello += ','
action.send_keys(hello).perform() action.send_keys(hello).perform()
if items := iframe.find_elements(By.XPATH, f'//*[contains(text(), "{hello}")]'): if elements := iframe.find_elements(By.XPATH, f'//*[contains(text(), "{hello}")]'):
target = items[0] target = elements[0]
clean = target.text == hello clean = target.text == hello
driver.switch_to.default_content() driver.switch_to.default_content()
@@ -523,16 +521,16 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
flow.react(Wait) flow.react(Wait)
click("div.io-ox-mail-compose-window button[data-action='send']") click("div.io-ox-mail-compose-window button[data-action='send']")
except Skip:
progress['skip'] += 1
index += 1
attempts = 0
continue
except Cancel: except Cancel:
status = Status.IDLE status = Status.IDLE
break break
except (Next, Skip) as e:
progress[e.__class__.__name__.lower()] += 1
index += 1
attempts = 0
continue
except (MismatchedEmailAddress, MismatchedEmailSubject) as e: except (MismatchedEmailAddress, MismatchedEmailSubject) as e:
logger.error('Nuh-Uh', exc_info=e) logger.error('Input mismatched', exc_info=e)
status = Status.STANDBY status = Status.STANDBY
continue continue
except Exception as e: except Exception as e: