I think we are conflating the solutions to two separate “problems” (or requirements is a better word):
- Creating a concept of “when an asset was terminated”.
- Archiving terminated assets.
I think it’s important to note that “archived” status doesn’t have any implicit meaning in farmOS. It is only used as a visibility mechanism to hide assets from lists/maps/etc in the UI.
It does not mean that the asset is “terminated”. So the farmOS Asset Termination module solves problem 1 first and foremost by providing this explicit meaning to assets. It just happens to also be trying to solve problem #2 at the same time, which makes sense, but I think it helps to keep them separate in our minds.
What is valid/invalid “state” of logs doesn’t really matter from a data model perspective. farmOS determines location by asking: “what is the most recent done
log with a timestamp less than or equal to now” - but now is a parameter of that function. Granted, it’s the default parameter, and therefore affects most of the default behavior - but we shouldn’t conflate the behavior with the data model and how it represents things, which is essentially timeless.
For all intents and purposes, a future log that is marked done IS DONE… in the future. It may not be “the future” right now, but it will be eventually… without making any changes to data in farmOS. So as time goes on, the state of farmOS changes automatically - without making any changes to the database. Think about it like playing a cassette tape: you can rewind/fast forward the “present moment” and it changes the current state without changing what’s recorded on the tape. Maybe this way of thinking is a little esoteric, and I’m not sure if it helps this conversation but it is worth stating I think.
In practice, I agree that logs should be marked done when they are actually completed. Creating logs in the future with a status of “done” leaves open the possibility that you’re creating future incorrect data, because maybe it doesn’t happen as planned! But, that’s a different problem, IMO. And we should NOT disallow future “done” logs from being created.
I just say all of this so that we can take a step back and ask what problems we’re trying to solve.
@gbathree Some of these questions might depend on specifically what you’re trying to achieve. I know in private chat you and I discovered that “done termination logs in the future archive the asset” and that was an issue… but in practice you won’t be creating done logs in the future, right? If you are, then maybe we should be digging into that more and asking why, but I don’t think you are.
It seems like @wotnak fixed that specific issue… basically by limiting the logic so that it only archives assets when a termination log is save if the log timestamp <= now. That makes sense to me. It means that assets WON’T be archived in those circumstances, though, so then the next step is asking: should there be logic to automatically archive them in those circumstances?
I think one could argue: NO, that is a weird case (done logs in the future), so leave it alone. It’s not farm_asset_termination
module’s problem. The user can archive those assets themselves later if/when they want to (again, trying to separate the two intentions/problems we’re trying to solve here).
Or, it could use a cron job to automatically find and archive assets, like @wotnak suggested:
- in a background job run in cron?
- it looks better from the perspective of good programming practices
- but since farmOS documentation recommends scheduling cron jobs once a week in many cases, it would probably take few days from the actual termination event for the asset to be archived
If the module must handle this weird case, then that seems to be the best way to do it, from my perspective. But I still don’t know if it’s actually a problem that needs to be solved. (Again: @gbathree will you actually have future done logs ever??)