Skip to content

Instantly share code, notes, and snippets.

@mfine
Last active July 19, 2017 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfine/b3dd21cfd03d1775084780f955cdc784 to your computer and use it in GitHub Desktop.
Save mfine/b3dd21cfd03d1775084780f955cdc784 to your computer and use it in GitHub Desktop.
Simple template for running a simple worker on Heroku
{-# START_FILE Procfile #-}
worker: worker
{-# START_FILE main.hs #-}
import Control.Concurrent
import Control.Monad
import System.IO
main :: IO ()
main = do
forever $ do
hPutStrLn stderr "Hello!"
threadDelay 1000000
{-# START_FILE worker.cabal #-}
name: worker
version: 0.1.0.0
build-type: Simple
cabal-version: >= 1.22
executable worker
main-is: main.hs
default-language: Haskell2010
build-depends: base >= 4.9 && < 5
{-# START_FILE .gitignore #-}
.stack-work/
@mfine
Copy link
Author

mfine commented Jul 19, 2017

#!/usr/bin/env bash

stack new worker https://gist.githubusercontent.com/mfine/b3dd21cfd03d1775084780f955cdc784/raw/4779a2ea55ac29b469a98eedfba35f74ba7785dc/worker.hsfiles
cd worker
git init .
git add .
git commit -m "initial"
heroku create --buildpack https://github.com/mfine/heroku-buildpack-stack.git
git push heroku master
heroku ps:scale worker+1

@mfine
Copy link
Author

mfine commented Jul 19, 2017

Example run:

~ $ stack new worker https://gist.githubusercontent.com/mfine/b3dd21cfd03d1775084780f955cdc784/raw/4779a2ea55ac29b469a98eedfba35f74ba7785dc/worker.hsfiles
Downloading template "https://gist.githubusercontent.com/mfine/b3dd21cfd03d1775084780f955cdc784/raw/522fc42d9c7a46e26673a73fae629c92c28da648/worker.hsfiles" to create project "worker" in worker/ ...
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- worker/worker.cabal

Selecting the best among 10 snapshots...

* Matches lts-8.23

Selected resolver: lts-8.23
Initialising configuration using resolver: lts-8.23
Total number of user packages considered: 1
Writing configuration to file: worker/stack.yaml
All done.
~ $
~ $ cd worker
~/worker $
~/worker $ git init .
Initialized empty Git repository in ~/worker/.git/
~/worker $
~/worker $ git add .
~/worker $
~/worker $ git commit -m "initial"
[master (root-commit) a19a152] initial
 4 files changed, 84 insertions(+)
 create mode 100644 Procfile
 create mode 100644 main.hs
 create mode 100644 stack.yaml
 create mode 100644 worker.cabal
~/worker $
~/worker $ heroku create --buildpack https://github.com/mfine/heroku-buildpack-stack.git                                                                         
Creating app... done, ⬢ serene-earth-29336
Setting buildpack to https://github.com/mfine/heroku-buildpack-stack.git... done
https://serene-earth-29336.herokuapp.com/ | https://git.heroku.com/serene-earth-29336.git
~/worker $
~/worker $ git push heroku master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 1.61 KiB | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Haskell app detected
remote: -----> 2017-07-19_02:58:20 Starting...
remote: -----> 2017-07-19_02:58:20 Exporting config vars
remote: -----> 2017-07-19_02:58:20 Installing libgmp-6.0.0a into cache
remote: ######################################################################## 100.0%
remote: -----> 2017-07-19_02:58:20 Restoring 6.0.0a files from cache
remote: -----> 2017-07-19_02:58:20 Downloading stack-1.4.0
remote: ######################################################################## 100.0%
remote: -----> 2017-07-19_02:58:21 Restoring stack-1.4.0
remote: -----> 2017-07-19_02:58:21 Substituting stack vars
remote: -----> 2017-07-19_02:58:21 Running stack
remote: Downloading lts-8.23 build plan ...
remote: Downloaded lts-8.23 build plan.
remote: Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpcomplete.com/) ...
remote: Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/
remote: Downloading root
remote: Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/
remote: Downloading timestamp
remote: Downloading snapshot
remote: Downloading mirrors
remote: Cannot update index (no local copy)
remote: Downloading index
remote: Updated package list downloaded
remote: Populating index cache ...
remote: Populated index cache.
remote: Preparing to install GHC to an isolated location.
remote: This will not interfere with any system-level installation.
remote: Preparing to download ghc-8.0.2 ...
remote: ghc-8.0.2: download has begun
remote: ghc-8.0.2:   27.84 MiB / 107.55 MiB ( 25.89%) downloaded...
remote: ghc-8.0.2:   54.10 MiB / 107.55 MiB ( 50.31%) downloaded...
remote: ghc-8.0.2:   77.99 MiB / 107.55 MiB ( 72.52%) downloaded...
remote: ghc-8.0.2:  101.87 MiB / 107.55 MiB ( 94.72%) downloaded...
remote: ghc-8.0.2:  107.55 MiB / 107.55 MiB (100.00%) downloaded...
remote: Downloaded ghc-8.0.2.
remote: Unpacking GHC into /app/tmp/cache/.stack/programs/x86_64-linux/ghc-8.0.2.temp/ ...
remote: Configuring GHC ...
remote: Installing GHC ...
remote: Installed GHC.
remote: stack will use a sandboxed GHC it installed
remote: For more information on paths, see 'stack path' and 'stack exec env'
remote: To use this GHC and packages outside of a project, consider using:
remote: stack ghc, stack ghci, stack runghc, or stack exec
remote: [1 of 2] Compiling Main             ( /app/tmp/cache/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /app/tmp/cache/.stack/setup-exe-src/setup-mPHDZzAJ.o )
remote: [2 of 2] Compiling StackSetupShim   ( /app/tmp/cache/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /app/tmp/cache/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
remote: Linking /app/tmp/cache/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 ...
remote: worker-0.1.0.0: configure (exe)
remote: Configuring worker-0.1.0.0...
remote: worker-0.1.0.0: build (exe)
remote: Preprocessing executable 'worker' for worker-0.1.0.0...
remote: [1 of 1] Compiling Main             ( main.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/worker/worker-tmp/Main.o )
remote: Linking .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/worker/worker ...
remote: worker-0.1.0.0: copy/register
remote: Installing executable(s) in
remote: /app/.stack-work/install/x86_64-linux/lts-8.23/8.0.2/bin
remote: Copying from /app/.stack-work/install/x86_64-linux/lts-8.23/8.0.2/bin/worker to /app/.local/bin/worker
remote: 
remote: Copied executables to /app/.local/bin:
remote: - worker
remote: -----> 2017-07-19_03:01:26 Making stack binaries available
remote: -----> 2017-07-19_03:01:26 Caching .stack-work
remote: -----> 2017-07-19_03:01:26 Finished!
remote: -----> Discovering process types
remote:        Procfile declares types -> worker
remote: 
remote: -----> Compressing...
remote:        Done: 1.5M
remote: -----> Launching...
remote:        Released v3
remote:        https://serene-earth-29336.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/serene-earth-29336.git
 * [new branch]      master -> master
~/worker $
~/worker $ heroku ps:scale worker+1
Scaling dynos... done, now running worker at 1:Free
~/worker $
~/worker $ heroku logs -t
2017-07-19T03:07:19.755903+00:00 heroku[worker.1]: Starting process with command `worker`
2017-07-19T03:07:20.553903+00:00 heroku[worker.1]: State changed from starting to up
2017-07-19T03:07:22.393957+00:00 app[worker.1]: Hello!
2017-07-19T03:07:23.397139+00:00 app[worker.1]: Hello!
2017-07-19T03:07:24.398803+00:00 app[worker.1]: Hello!
2017-07-19T03:07:25.400211+00:00 app[worker.1]: Hello!
2017-07-19T03:07:26.405199+00:00 app[worker.1]: Hello!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment