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

ImportError: No module named corescheduler #72

Open
pavelsr opened this issue Nov 26, 2019 · 2 comments
Open

ImportError: No module named corescheduler #72

pavelsr opened this issue Nov 26, 2019 · 2 comments

Comments

@pavelsr
Copy link

pavelsr commented Nov 26, 2019

I'd like to implement custom job class (same as ShellJob but which run only once)

I made a class:

"""A job to run executable programs ONLY ONCE."""

from subprocess import call

from ndscheduler.corescheduler import job

class ShellJobOnce(job.JobBase):

    @classmethod
    def meta_info(cls):
        return {
            'job_class_string': '%s.%s' % (cls.__module__, cls.__name__),
            'notes': ('This will run an executable program ONLY ONCE. You can specify as many '
                      'arguments as you want. This job will pass these arguments to the '
                      'program in order.'),
            'arguments': [
                {'type': 'string', 'description': 'Executable path'}
            ],
            'example_arguments': '["/usr/local/telegram_notify.pl", "user_id", "arg2"]'
        }

    def run(self, *args, **kwargs):
        code = call(args)
        self.scheduler_manager.pause_job(self.job_id);
        #self.scheduler_manager.remove_job(self.job_id);
        return {'returncode': code}


if __name__ == "__main__":
    # You can easily test this job here
    job = ShellJobOnce.create_test_instance()
    job.run('at', '-h')

and run NDScheduler using docker-compose like:

version: '2'

services:
    scheduler:
        image: wenbinf/ndscheduler
        volumes:
        - "${PWD}/python/shell_job.py:/mnt/scheduler/src/ndscheduler/simple_scheduler/jobs/shell_job.py"
        ports:
        - "8888:8888"

After that I get at http://localhost:8888/

Traceback (most recent call last):
  File "/mnt/scheduler/local/lib/python2.7/site-packages/tornado/web.py", line 1443, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "/mnt/scheduler/src/ndscheduler/ndscheduler/server/handlers/index.py", line 16, in get
    meta_info = utils.get_all_available_jobs()
  File "/mnt/scheduler/src/ndscheduler/ndscheduler/utils.py", line 155, in get_all_available_jobs
    job_module = importlib.import_module('%s.%s' % (job_class_package, module_name))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/mnt/scheduler/src/ndscheduler/simple_scheduler/jobs/shell_job_once.py", line 5, in <module>
    from ndscheduler.corescheduler import job
ImportError: No module named corescheduler

Could you please explain me why such happened?

My module has same import from ndscheduler.corescheduler import job sting as original ShellJob

P.S. Even if I mount same ShellJob module with same content inside wenbinf/ndscheduler container I got same error.

@tvoikoteika228
Copy link

tvoikoteika228 commented Dec 9, 2019

It's problem in docker image

If you try to download latest version of wenbinf/ndscheduler, somehow you get not the same as you see in this git.

I've re-downloaded image 3 times and all 3 times I got same string in original shell_job.py:

from ndscheduler import job

instead of

from ndscheduler.corescheduler import job

All of 5 classes have this import:

apns_job.py: from ndscheduler import job
curl_job.py: from ndscheduler import job
sample_job.py: from ndscheduler import job
shell_job.py: from ndscheduler import job
slack_job.py: from ndscheduler import job

Thus, your solution is simple: Replace from ndscheduler.coresheduler import job to from ndscheduler import job in your shell_job.py

@pavelsr
Copy link
Author

pavelsr commented Dec 11, 2019

@tvoikoteika228 you are absolutely right

$ docker run -it wenbinf/ndscheduler bash -c "cd /mnt/scheduler/src/ndscheduler/.git && git log -1"
commit 5b1f5bf62c5cb6e247ad45a5b2acd50723fd87c3
Author: Aaron Webber <[email protected]>
Date:   Fri Dec 14 15:42:07 2018 -0800

    Remove reference to LLVM.
    
    It's not like LLVM.

So docker version is corresponding to commit 5b1f5bf62c5cb6e247ad45a5b2acd50723fd87c3, made 15 Dec 2018

And latest commit in master branch is c7100c02a8df3998ca882865b1b902d8951b764b ( Aug 23, 2019 )

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

No branches or pull requests

2 participants