SourceLair Blog

  • Develop your Flask applications - One drop at a time

    Today, we're glad to introduce the addition of one more framework to the SourceLair family, Flask. Flask is the continuation of our love for Python web frameworks. From now on, you can select the new Flask project type when you create or clone a new project in SourceLair and you'll be able to play with it within seconds.

    Flask Logo

    What is Flask?

    Copying from the official website, Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.

    Flask can do a lot of things for a microframework. In SourceLair, we've coded a couple of internal services in Flask - making this our second favorite framework after Django. It gives simplicity and versatility, by defining a very nice routing and request/response handling mechanism, while leaving it up to you to select anything, from which ORM you'll use for your database, to the way your URLs will be constructed.

    Why Flask?

    Flask has been one of the most wanted frameworks by you, our users, and one that we use a lot internally at SourceLair. This made it our number one choice to be supported in our platform - we hope you'll love the support as much as we do!

    Starting your Flask application in no time

    To start your Flask application in SourceLair, simple create a new project from the "+" icon of the sidebar, choose Flask and your server will be up and running within seconds

    So, can I just clone my application in SourceLair and it'll work?

    The simple answer is yes. All you have to do is clone your project and it'll work! There are some things that we can't always do for you automatically though, so you have to make sure the following preconditions exist:

    1. Your application binds to 0.0.0.0
      • If not, just run your application with: app.run(debug=True, host='0.0.0.0')
    2. Your application is listening to port 5000, which is the default one
      • If you've changed the default port, you can switch back to the default one by just omitting the port from the run command
    3. your application's server file is called server.py
      • If you've named it anything else, you can update it from your project’s settings, accessible from the gear icon next to your project's name
    4. you're awesome - we know you are :)

    Also, if you need any libraries, you can easily install them using using pip.

    Why don't you support all frameworks?

    This is an interesting question and while it has nothing to do with Flask, I'd like to shed some light in here. Supporting multiple frameworks in SourceLair is extremely easy, the hard thing is to make them play nicely and provide first class support. That's why we make sure that both of these are true before adding any more frameworks.

    If you'd like to see another framework added in SourceLair though, don't hesitate to drop us a line at support@sourcelair.com and we'll be more than happy for it to be the next one we'll add!

  • Heroku toolbelt and mercurial deployment

    As you may have noticed, Heroku toolbelt is pre-installed in our images and you can use the Heroku commands from your SourceLair terminal.

    To further facilitate your flow, we added some of the basic Heroku commands into the Command Palette. The commands added are the following:

    heroku commands

    A typical workflow would be like this:

    • Start with Heroku: Login. You'll have to do this just once, to connect your SourceLair account to your Heroku account.
    • Next add your SSH keys to Heroku with Heroku: Add SSH keys. This has to be done, in order to be able to deploy. You can also add your SourceLair SSH keys manually from the Heroku UI.
    • Create a new Heroku application with Heroku:Create or add in your repo the Heroku remote of an existing application by using Heroku: Add remote.

    You are now ready to work on your heroku application. Anytime you want, you can deploy your application with Heroku: Deploy.

    As an added bonus, the commands of the Command Palette will also work for Mercurial projects! By utilizing the hg-git mercurial plugin, SourceLair let's you push your hg repository to a git server (like heroku in this case). Specifically, the Heroku: Create and the Heroku: Add remote commands add the Heroku remote after converting it into an hg-git plugin compatible form that enables mercurial to push into a git server.

    Go to www.sourcelair.com to try out the flow of developing and deploying your Heroku application in SourceLair.

  • Post-mortem: Why several users got spammed with emails

    Recently, we switched our Celery broker to Redis. This was a great improvement in the way we handle tasks, but there was a caveat which we did not forecast.

    This caveat of the Redis broker led to the follow up emails we send to our users 4 days after their subscription being sent multiple times.

    We have tracked down the issue and changed the way we send emails, but this does not minimize the number of emails several users received.
    We are deeply sorry about this incident and we have taken measures so that it does not happen again.

    The issue

    When using the Redis Celery broker, tasks that do not get executed some time after they are received, they are rescheduled - reference.

    Copying from the Redis documentation:

    If a task is not acknowledged within the Visibility Timeout the task will be redelivered to another worker and executed.

    Since tasks were being scheduled 96 hours after a user was created, there was a theoretical limit of 95 emails being sent to a user, since the email was being rescheduled every one hour.

    The good fact is that we deploy new code several times a week and the duplicate tasks were being rescheduled only once after each deployment, crucially reducing the actual amount of emails that were delivered to a user. The most emails sent to one user were 87, which was during the weekend.

    How we solved the issue

    When we became aware of the issue, we immediately canceled pending emails and started working on an alternative way to tackle the issue.

    We have created a daily cron task that collects all users that were created 4 days ago and dispatches the emails, all done using Celery beat.
    This improves performance and makes sure duplicate emails will not be sent again.

    Thoughts for future improvements

    We have solved the case for now, but spamming is one of our worst nightmares and definitely something we don't want to come from our service. Thus, we have started working on some thoughts on how to effectively rate limit emails to users, so that incidents like this one never happen again.
    The first thought is limiting the amount of emails we can send to a user during a specific period of time and add alerts to our administration team when this limit is reached.

    We are constantly doing our best to create an awesome service for you and we give our word that we'll continue to do so.

    Be creative and enjoy coding in your browser.

  • The colours of productivity

    Here at SourceLair we are striving to make our users' lives easier and we are always trying to find ways to enable their productivity.

    For these reasons, we have been doing some internal research and testing for some time now, and one of the things we found out, is that the human brain responds very well to vibrant stimuli, in a way that promotes productivity and relaxation.

    Today we are happy to introduce the result of our research efforts.

    Hot Dog Stand is here

    Inspired by the all time classic Hot Dog Stand theme of Windows 3.1 this is a very minimal theme, easy to the eye, that is sure to boost your productivity and make you reach your true potential.

    So, head over to www.sourcelair.com open your editor settings, or go instantly to the Theme selection by opening the Command Palette (Ctrl/Cmd + Shift + P) and entering the command "Quicksettings", and try it out for yourself, today!

  • Read between the words

    Today we are happy to announce a new little convenience feature for our editor that allows you to view whitespaces in your code.

    To enable the feature just go into your editor settings and toggle the switch.

    Whitespace settings

    When you return to your code you should now notice that every whitespace such as spaces, tab characters and line breaks are appropriately marked and displayed to you.

    Visible whitespace

    So, go to www.sourcelair.com and check it out yourself in seconds.