good solution for indexing script which should run always

36 views
Skip to first unread message

Mirek Zvolský

unread,
Oct 27, 2016, 6:36:06 AM10/27/16
to web2py-users
I need run a script which for marked records in one table creates "indexing" or "helpers" records in another table.
This script should:
- switch this activity and sleep(10) /should sleep after it will not find any marked record/
- run always
- run in 1 instance only /to avoid indexing of same records from 2 instances/

I decide to solve it as systemd service.
My QUESTION IS: Is this good decision, or should I use something web2py specific (scheduler?) ?

-----------------
If somebody is interested in the "systemd service" solution, I made in based on this article:

...and I have added into the [service] section: Restart=on-failure

Mirek Zvolský

unread,
Dec 9, 2016, 8:19:09 AM12/9/16
to web2py-users
So I have received no recommendation to this.
There was no problem with the systemd service,
but (to be more portable,...) I have moved now to the scheduler.

If somebody is interested, here is my code.
I can/need initialize the scheduler with one (admins) access to url myapp/sysadmin/start_idx.

@auth.requires_membership('admin')
def start_idx():
    if DEBUG_SCHEDULER:
        idx()
        return 'Indexing finished.'
    else:
        if db((db.scheduler_task.application_name == 'codex2020/sysadmin') &
                (db.scheduler_task.task_name == 'idx')).select().first():
            return 'Task idx already queued. Remove it from scheduler_task table if you want re-create it.'
        else:
            scheduler.queue_task(
                idx,
                pargs=[],
                pvars={},
                start_time=datetime.datetime.now(),
                stop_time=None,
                timeout=2147483647,
                prevent_drift=False,
                period=20,
                immediate=False,
                repeats=0
            )
            return 'Task idx was added.'


Reply all
Reply to author
Forward
0 new messages