Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in date/times #27

Open
paulsaxe opened this issue Mar 8, 2023 · 1 comment
Open

Inconsistency in date/times #27

paulsaxe opened this issue Mar 8, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@paulsaxe
Copy link
Contributor

paulsaxe commented Mar 8, 2023

When I add a job from outside the Dashboard I use simple datetimes in UTC:

            with seamm_datastore.session_scope(db.Session) as session:
                job = db.Job.create(
                    job_id,
                    flowchart_path,
                    project_names=data["projects"],
                    path=wdir,
                    title=data["title"],
                    description="Run from the command-line",
                    submitted=current_time,
                    started=current_time,
                    parameters={"cmdline": []},
                    status="started",
                )
                session.add(job)

However, when I update the job after completion, the time to pass is ... different! This wonderful construct works:

                # current_time = datetime.datetime.now(datetime.timezone.utc)                                                                                                     

                # At the moment update takes weird numbers!                                                                                                                       
                now = datetime.datetime.now().astimezone()
                dt = now.utcoffset().total_seconds()
                current_time = (time.time() - dt) * 1000

                # Add to the database                                                                                                                                             
                ...
                with seamm_datastore.session_scope(db.Session) as session:
                    job = db.Job.update(
                        job_id, finished=current_time, status=data["state"]
                    )

This appears to be because the code in Job (models.py) is this

        for k, v in update_dict.items():
            if k == "submitted" or k == "finished" or k == "started":
                if v:
                    update_dict[k] = datetime.fromtimestamp(v / 1000)
                else:
                    update_dict[k] = None

Which seems to be 1000 times a timestamp. I presume this has something to do with the Web side of things, but it is certainly awkward for the job side. Would it be possible to check the type of the value v and use as-is if it is a datetime? Would a UTC datetime then give a reasonable time in the Web page?

@paulsaxe paulsaxe added the enhancement New feature or request label Mar 8, 2023
@paulsaxe
Copy link
Contributor Author

paulsaxe commented Mar 8, 2023

Hmmm. current_time got lost in the first code snippet. It is the same as the commented out line just below, in the 2nd snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants