from utime import sleep from scron.week import simple_cron from scron.decorators import run_times, call_counter, time_since_last_call, debug_call @debug_call def some_counter(scorn_instance, callback_name, pointer, memory): if 'counter' in memory: memory['counter'] += 1 else: memory['counter'] = 1 @debug_call def long_task(scorn_instance, callback_name, pointer, memory): if 'counter' in memory: memory['counter'] += 1 else: memory['counter'] = 1 sleep(20) simple_cron.add('every 10 seconds', long_task, seconds=range(0, 59, 10)) simple_cron.add('every 2 seconds', some_counter, seconds=range(0, 59, 2)) simple_cron.run()
from scron.week import simple_cron from scron.decorators import run_times, call_counter, time_since_last_call, debug_call @debug_call def some_counter(scorn_instance, callback_name, pointer, memory): if 'counter' in memory: memory['counter'] += 1 else: memory['counter'] = 1 def start_another_one_callback(scorn_instance, callback_name, pointer, memory): callback_name_e5s_id = 'every fifth second' scorn_instance.add('run only 3 times', run_times(3)(some_counter)) simple_cron.add('every 2 minutes 3 times', start_another_one_callback, seconds=0, minutes=range(0, 59, 2)) simple_cron.run()
# define rotary variables r = RotaryIRQ(pin_num_clk=14, pin_num_dt=13, min_val=0, max_val=len(names) - 1, reverse=True, range_mode=RotaryIRQ.RANGE_WRAP) lastval = r.value() simple_cron.run() # orbitTracker_all needs to be cached 1/day simple_cron.add('Daily', lambda *a, **k: orbit_loc_all(), hours=12, minutes=0, seconds=0) #define starfield screensaver variables stars = 500 star_x = list(range(stars)) star_y = list(range(stars)) star_z = list(range(stars)) xc = 63 yc = 31 for i in range(stars): initStar(i, star_x, star_y, star_z) while True:
from scron.week import simple_cron from scron.decorators import run_times def some_counter(scorn_instance, callback_name, pointer, memory): if 'counter' in memory: memory['counter'] += 1 else: memory['counter'] = 1 print('Call %d' % memory['counter']) simple_cron.add('run only 5 times', run_times(5)(some_counter)) simple_cron.run()
from scron.week import simple_cron from scron.decorators import run_times, call_counter, time_since_last_call, debug_call @debug_call def some_counter(scorn_instance, callback_name, pointer, memory): if 'counter' in memory: memory['counter'] += 1 else: memory['counter'] = 1 simple_cron.add('every second minute', some_counter, seconds=0, minutes=range(0, 59, 2)) simple_cron.run( ) # You have to run it once. This initiates the SimpleCRON action, and reserve one timmer. simple_cron.add('every 10 seconds', some_counter, seconds=range(0, 59, 10))
@decorators.successfully_run_times(3) @decorators.call_counter def test_suc_runtimes_x3(scorn_instance, callback_name, pointer, memory): print('RETURN: test_suc_runtimes_x3 %d sec. %d' % (memory[decorators.call_counter.ID], utime.localtime()[5])) return not bool(memory[decorators.call_counter.ID] % 2) @decorators.time_since_last_call @decorators.call_counter def test_time_since_last_call(scorn_instance, callback_name, pointer, memory): print('RETURN: test_time_since_last_call %d sec. %d' % (memory[decorators.call_counter.ID], utime.localtime()[5])) if memory[decorators.call_counter.ID] >= 6: scorn_instance.remove(callback_name) print('RUN', utime.localtime()) simple_cron.add('test_runtimes_x6', test_runtimes_x6) simple_cron.add('test_suc_runtimes_x3', test_suc_runtimes_x3) simple_cron.add('test_time_since_last_call', test_time_since_last_call, seconds=[10, 19]) simple_cron.run() print(list(simple_cron.list())) utime.sleep(21) simple_cron.remove_all() print('END', utime.localtime())
import utime import machine from scron.week import simple_cron simple_cron.add('test1', lambda *a, **k: print('RETURN: test1', utime.localtime()), seconds=10) simple_cron.add('test2', lambda *a, **k: print('RETURN: test2', utime.localtime()), seconds=9) simple_cron.run() # 2000-01-01 00:00:05 machine.RTC().datetime(utime.localtime(0)) print('RUN', utime.localtime()) simple_cron._sync_time() print(list(simple_cron.list())) utime.sleep(4) simple_cron.remove('test2') simple_cron.remove('test1') print(list(simple_cron.list())) print('END', utime.localtime())