Giter Club home page Giter Club logo

Comments (13)

motorina0 avatar motorina0 commented on June 24, 2024 1

In the backend a call of this form will be made each time a job is executed:

async with httpx.AsyncClient() as client:
    resp = await client.get(    # action can be any HTTP verb (GET, PUT, POST, etc) set in the job config
        url,                    # from the job config
        headers,                # from the job config
    )
    save_job_execution(resp.status_code, resp.text())

from scheduler.

motorina0 avatar motorina0 commented on June 24, 2024 1

Any suggestions on where to put the dependency, would be helpful.

  • please open a PR on the lnbits/lnbits repo with the new dependency
  • this PR should be merged before releasing the extension

as the crontab script needs to call the API and does not inherit the LNBits environment

  • relative paths should be supported in the front-end
  • if a relative path is used then the back-end must add http://${HOST}/${PORT}

Also the user must set the username that has access to system /usr/bin/crontab

  • why is a OS user required? what happens on non-linux system?

from scheduler.

motorina0 avatar motorina0 commented on June 24, 2024 1

Do we want to enable the username?

  • we want to keep this as simple as possible for the users that install the extension
  • it looks like the username option is not mandatory, that is good

I know for OSX, I needed it.

  • you mean you had to take extra steps in order to use the lib?
  • we should limit/automate that as much as possible

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024 1

OK I am testing this with both Ubuntu and OSX. Will try to have everything working with latest 0.11 this weekend. (this week has been a bit busy)

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024 1
HOST=127.0.0.1
PORT=5000
* data can also be passes to the job in the `comment` field (or something similar), right?

yes I know that the HOST/PORT is in the LNBits .env, but that cron script unfortunately runs outside of the LNBits environment as its called by system crontab which doesn't inherit the LNBits environment.

I can pass the HOST/PORT in, just like the job ID and adminKey is passed in right now (this is testnet example).

Perhaps this is better way to do it.

Ok I will test and get back to you. Thanks @motorina0

Screenshot 2023-10-26 at 11 17 53 AM

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024 1

tested with sqlitedb only so far, no postgres

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024

@motorina0 OK. I think the directions are clear.

The python-crontabs module would store the X-API-Key values as environment variables in the crontab file, so each individual job will have its own set of env vars.

Assuming there is no need for global env vars, I'll remove the Global Environment variables box that is currently at the bottom of the extension right now.

Please do let me know if incorrect! thanks.

from scheduler.

motorina0 avatar motorina0 commented on June 24, 2024

Regarding running jobs:

  • there should be only one command file
  • the job_id is passed to the command file
  • the command file fetches the full job details from the DB and executes the HTTP call

Adapting a simple example from here:

from crontab import CronTab

cron = CronTab(user='username')
job = cron.new(command='python lnbits/utils/cron-job.py') # pass the job_id param somehow
job.minute.every(1)

cron.write()
  • cron-job.py:
# imports go here

# extract job_id param
# query DB for job

async with httpx.AsyncClient() as client:
    resp = await client.get(    # action can be any HTTP verb (GET, PUT, POST, etc) set in the job config
        url,                    # from the job config
        headers,                # from the job config
    )
    save_job_execution(resp.status_code, resp.text())

Note:

  • I'm not sure if the job creation example is the latest and greatest way of starting jobs with the crontab extension.
  • its just to illustrate the flow

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024

Working on testing the extension install now.

Any suggestions on where to put the dependency, would be helpful.
Right now the python-crontab dependency is in the requirements.txt file but the user has to install it themselves, its not on the LNBits main poetry toml.

Also the user must set the username that has access to system /usr/bin/crontab
and they need to specify their LNBITS Install, as the crontab script needs to call the API and does not inherit the LNBits environment. I've put these two variables in a .env file, but there is no UI to edit this directly right now.

Implemented as you suggested using a run_cron_job.py script.

Screenshot 2023-10-09 at 1 33 41 PM Screenshot 2023-10-09 at 1 33 27 PM

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024

According to the docs, there are three ways to do it, with Linux.
One of the ways requires the username.

Do we want to enable the username? I know for OSX, I needed it.

Screenshot 2023-10-11 at 3 24 41 PM

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024
* if a relative path is used then the back-end must add `http://${HOST}/${PORT}`

Regarding - I have this script running when the cron job is triggered but is does not have the LNBits environment, I put it in as an env variable in .env but if you have a better way of accessing it, please suggest!

LNBITS_BASE_URL = os.environ.get('LNBITS_BASE_URL') or 'http://localhost:5000'

extension updated to allow for LNBits v0.11 but still need to do more testing.

from scheduler.

motorina0 avatar motorina0 commented on June 24, 2024

Regarding - I have this script running when the cron job is triggered but is does not have the LNBits environment, I put it in as an env variable in .env but if you have a better way of accessing it, please suggest!

  • .env file has these properties:
HOST=127.0.0.1
PORT=5000
  • data can also be passes to the job in the comment field (or something similar), right?

from scheduler.

bitkarrot avatar bitkarrot commented on June 24, 2024

OK I fixed the above, made a release. It should be working with basic functionality now, validation can improve but please have a look. https://github.com/bitkarrot/scheduler/releases/tag/v0.0.9, @motorina0

from scheduler.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.