Code Monkey home page Code Monkey logo

sample-event-processor's Introduction

Sample Event Processor

As it stands today, Bacalhau doesn't support daemon like jobs, and every job is expected to complete within a defined timeout window. We are planning to support daemon like jobs natively in the future, but for now, this sample application demonstrates how to implement a long running job that can be restarted from the last checkpointed event.

This is a sample Bacalhau application that demonstrates executing long running jobs that process events or logs from a local file, checkpoints its progress as of the last processed event, and then resumes processing from the last checkpointed event when the application is restarted.

The sample application assumes a local Bacalhau instance that is tailing and consuming events from a local file, and checkpoints its progress on another local file. When submitting another instance of the job, it aborts if there is an already running instance of the job, which can be useful to run the job as a cron job.

Running the sample application

Run Bacalhau Server

./script.sh run-bacalhau

This command will create events and checkpoint files under var directory, and run a Bacalhau server that allow-list those local files to be accessed by Bacalhau jobs. events will only be exposed as read-only, while checkpoint as read-write since the job must be able to update the checkpoint offset.

Publish Events

./script.sh publish-events

Publish a new entry to events file every second until it is stopped.

Run the sample application

./script.sh submit-job

Will check if there is an already running instance of the job, and abort if there is one. Otherwise, it will submit a new instance of the job that will process events from events file, and checkpoint its progress on checkpoint file. It has a default timeout of 5 minutes. You can try submitting the job after it is completed, and it will resume from the last checkpointed event.

Updating the sample application

Update the code

The sample application is written in Go and can be found under app directory. You can update the code by providing your own implementation of EventProcessor to process the individual events, and your own implementation of checkpointer to checkpoint the progress.

Build a new docker image

export IMAGE_REPOSITORY=<your-image-repository>
export IMAGE_NAME=<your-image-name>
exoort IMAGE_TAG=<your-image-tag>
./script push-image

Re-Synthesize your job definition

export IMAGE_REPOSITORY=<your-image-repository>
export IMAGE_NAME=<your-image-name>
exoort IMAGE_TAG=<your-image-tag>
./script.sh synthesize-job

Re-Run the job

./script.sh submit-job

Limitations and Future Work

  • This is just a sample application and not meant to be used in production. It is not tested for performance and scalability.
  • Checkpoints are persisted after each event, which can be expensive.
  • The sample application depends on this PR to support writable volumes.
  • Future work is to support long running daemon like jobs natively in Bacalhau, such that users only need to submit the job once, and Bacalhau will take care of restarting the job if it fails or crashes.
  • Future work is to support functions that scale from zero, reduce cold startup latency and support multiple invocations of the same function using the same container instance.
  • Future work is to support functions that can be invoked on a schedule, and functions that can be invoked in response to events from other services.

sample-event-processor's People

Contributors

wdbaruni avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sample-event-processor's Issues

JACoB Installed

JACoB here...
I can now access this repo, but ran into trouble during my installation checks.

Here is some additional info on the error(s) I saw:

ENOSPC: no space left on device, mkdir '/mnt/tmp/tmp-98-sJx15OUDRqit'

You may need to add or edit a jacob.json file in the root of your repository to help me better understand how to build your project.

Please visit the JACoB documentation for more information on how to resolve this issue.

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.