Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve developed an ADHD management system for myself that\'s attempting to chang

ID: 646940 • Letter: I

Question

I've developed an ADHD management system for myself that's attempting to change multiple habits at once. I know this is counter to conventional wisdom, but I've tried the conventional for years & am now trying it my way. (just wanted to say that to try and prevent it from distracting people from the actual question)

Anyway, I'd like to write something to run on a remote server that monitors me, helps me build/avoid certain habits, etc.

What this amounts to is a system that:

runs 24/7
may have multiple independent tasks to run at once
may have tasks that require other tasks to run first
lets tasks be scheduled by specific time, recurrence (ie. "run every 5 mins"), or interval (ie. "run from 2pm to 3pm")
My first naive attempt at this was just a single PHP script scheduled to run every minute by cron (language was chosen in order to use a certain library, but no longer necessary). The logic behind when to run this or that portion of code got hairy pretty quick.

So my question is how should I approach this from here? I'm not tied to any one language, though I'm partial to python/javascript.

Thoughts:

Could be done as a set of scripts that include a scheduling mechanism with one script per bit of logic...but the idea just feels wrong to me.

Building it as a daemon could be helpful, but still unsure what to do about dozens of if-else statements for detecting the current time

Explanation / Answer

I would go about it like this:

Every Task is encapsulated in its own class
A task only contains of a single method: Execute. This method executes the action of the task.
A task is not responsible for checking its requirements.
Scheduling is done via Jobs
A job references a task
A job defines when its task is allowed to run
You would have one class per job type, i.e. you would have
a RecurringJob ("every 5 minutes")
an IntervalJob ("from 2pm to 3pm")
A job is an implementation of the Tester/Doer pattern.
You would have an Job Registry. That is basically the scheduler that executes the jobs.
It periodically checks (every 10 seconds, every minute or whatever you need) all registered jobs of they can be executed.
The requirement "may have tasks that require other tasks to run first" can be implemented using the Composite pattern and passing the tasks in the correct order.

The requirement "may have multiple independent tasks to run at once" can be implemented by making the execution of a task asynchronous.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote