Need help with R/Python pandas job scheduling tools

Discussion

My team is working on R previously and they are using rshiny for dashboards and cron jobs for scheduling rscripts to run daily using bash scripts.

Now we have started using python and snowflake for data warehousing. So, we are now looking for an alternative to cron jobs where we can schedule all kind of scripts or notebook if possible. So that it can be managed and tracked easily.

Posted Dec 30, 2021, 3:32 AM UTC

1223
sysonic•

Airflow

17
powerkerb•

have you looked at dagster?

7
py_rootOP•

Recently heard about it from one of the candidate during interview and I am exploring it currently.

2
kharising•

Apache Airflow is an option for you

5

I have actually open-sourced a framework that might suit your needs: https://red-engine.readthedocs.io/en/stable/. It is a scheduling library with a focus on readability and extendability. Looks like this:

@FuncTask(start_cond="daily")
def do_once_a_day():
    ... # This function runs once a day

@FuncTask(start_cond="daily after 10:00")
def do_once_a_day_2(): 
    ... # This function runs once a day after 10 AM

Or do something more complex:

@FuncTask(start_cond="after task 'my_task'")
def do_after_another(): 
    ... # This function runs when another task has succeeded

@FuncTask(start_cond="""after tasks 'my_task' 
                        & time of day between 10:00 and 15:00 
                        & time of week between Mon and Fri""") 
def do_complex(): 
    # This function runs when another task has succeeded 
    # but only if it's between 10 AM and 3 PM # and a week day 
    ...

There is also CommandTask which you can use to run the R scripts and notebooks, or you could subclass and make your own. I have plans to include a notebook runner one day.

Don't worry, it's well tested (Windows & Linux) and requires no configuration (if you don't want to). I personally found Airflow a bit too complex to configure.

There are a bunch of other features as well: parallelization, parametrization, return value pipelining, timeouts, custom conditions (super easy to do), Rest API for runtime communication, customizable logging, built-in dependency graph for checking task links etc.

Source code: https://github.com/Miksus/red-engine

EDIT: Seems something broke the formatting.

4

I found it great. How this framework differs from Airflow? The snippet you wrote is the same as using the TaskFlow API in Airflow.

2

Thanks! Airflow works somewhat differently as I'm aware. The focus of Airflow (in my understanding) is in data processes in enterprise setting but my focus is more widespread in terms of use case and this is more focused on small to mid sized projects. In short, (IMO) this framework is more like Flask: it's easy to get started with and it's highly customizable and doesn't tell you how you should do things while Airflow is more perhaps enterprise friendly and says how you should do things, and provides you more things straight away.

What comes to scheduling, Airflow works via triggers but this framework work with conditions. The difference is that conditions are simply lazily evaluated boolean statements: the string syntax allows you to include AND (&), OR (|), NOT (~) operations and nesting them. It's also trivial to create your own conditions (also support regex and parameterized conditions). I guess you could create your own trigger rules in Airflow but triggers are mostly made in mind of traditional ETL pipelines. This framework lets you do arbitrary scheduling and just provides you tools for dependency and time related problems.

Also, Airflow works well with Docker and it focuses more as being just the scheduler while Red Engine is the scheduler and the executor. The benefit of this is that passing data to and from tasks is well supported, but for running things in separate containers/envs not that much. Of course the tasks can be anything thus you can make a task that starts a script in another env/container.

I don't think it's necessarily better than Airflow. But it works on different set of principles which might be more optimal for some cases. I made it in mind of my data processes but also to power my IOT applications. I wanted something readable in which I think I succeeded.

3

Hey, you really did a great job. I was just a bit confused with the Readme. But your thoughts (as you put here in the comments) are clear as your code. It's a nice purpose to small projects, I was wondering about using in some IoT applications with Node Red.

3

Thanks a lot! And I probably should state these also in the Readme.

Means a lot that you are also interested. I find it very useful for my stuff and was slightly worried that people (like perhaps you) who also could find it useful might not come across it. If you find bugs or have any suggestions, just put a message.

3
py_rootOP•

I also found airflow complex to configure and handle as you progress and you have a many jobs schedule.

Then, it becomes some time hard to explain these complexity to a team member who are good in data analytics but don't want much complex scheduling process to run their task after successful etl.

I will look into this as well and share my experience later.

1
Luxi36•

Prefect or Airflow both do this job very well.

3
BJJaddicy•

Airflow

2
unfuckdiewelt•

Try Apache Airflow. We even run R and python regular jobs with Airflow.

2
webster__•

Is the hurdle to get setup with on premise airflow significant? When I’ve started looking into it I get daunted by what seems like a lot of infrastructure setup and whatnot needed to get going. I’m looking for something relatively light weight to orchestrate jobs running on a VM.

2
unfuckdiewelt•

It is actually not that daunting atleast the setup is not but the learning curve can be steep since the community is very vibrant and new connectors and releases happens pretty frequently. To just started there is ready production grade docker images available, plus if you want to install directly it pretty easy using pip since the whole package is in python and on top of that if you use gcp they have manged airflow. And if none of the above satisfies your requirements the checkout Astronomer, they are enterprise style consultants for airflow orchestration. But I doubt that is too much focused on one component itself as your platform grows Airflow wont work and at that point you have to move to k8 based data pipeline orchestrators auch as Argo pipelines which powers the part of kubeflow pipelines for mlops solutions. Plus down the line, it is going to be a very daunting task to maintain probably thousand pipelines running on multiple Airflow nodes. Hope I haven't make thing too complicated. I am in the process of the same so I am looking at it from different usecases.

1
rtmymynbklmn•

"Celery" might be another option for pure python

2
ronald_r3•

This is a good suggestion because its not as complicated as airflow and can appeal to analysts for that reason. Especially if they know python lol

1
DesiDarshan•

We access snowflake through Databricks notebooks and orchestrate those jobs with Azure Data Factory's scheduled Trigger.

1
py_rootOP•

As per current data volume and workflow we found that databricks will be costly in current situation. So we wanted to go with open source tools as of now.

Our lead is also in discussion with various partners and also thinking about using rstudio professional.

I am looking at dagster to see if it helps for current problem statement.

0
No_Substance_9411•

Try AWS lambda.

1
saipardhu•

Airflow FTW, I worked on the exact use cases and I can say with confidence that Airflow is the tool for you

1
yiyux•

Kubeflow would do the work if you use Jupiter Notebooks and Kubernetes

1

Use APScheduler, its a library in python. You can use it to schedule python scripts to run as per required intervals

1