Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 19 2018 23:23
    kiddrew commented #14160
  • Nov 19 2018 23:23
    gmcgibbon synchronize #34468
  • Nov 19 2018 23:23
    kiddrew commented #14160
  • Nov 19 2018 23:12
    kamipo commented #34316
  • Nov 19 2018 23:10
    oniofchaos commented #34218
  • Nov 19 2018 23:09
    rafaelfranca synchronize #30320
  • Nov 19 2018 23:08
    oniofchaos commented #34236
  • Nov 19 2018 23:07
    rafaelfranca closed #34487
  • Nov 19 2018 23:07

    rafaelfranca on master

    Prevent TextHelper#word_wrap fr… Merge pull request #34488 from … (compare)

  • Nov 19 2018 23:07
    rafaelfranca closed #34488
  • Nov 19 2018 23:06
    rafaelfranca review_requested #34308
  • Nov 19 2018 23:05
    oniofchaos commented #34280
  • Nov 19 2018 23:01
    oniofchaos commented #34308
  • Nov 19 2018 22:52
    rafaelfranca synchronize #30320
  • Nov 19 2018 22:51

    rafaelfranca on master

    Indent guides as rails help com… Homogenize rails help output I… Merge pull request #34085 from … (compare)

  • Nov 19 2018 22:51
    rafaelfranca closed #34085
  • Nov 19 2018 22:51
    rafaelfranca commented #33643
  • Nov 19 2018 22:51
    rafaelfranca closed #33643
  • Nov 19 2018 22:50

    rafaelfranca on 5-2-stable

    Merge pull request #34106 from … (compare)

  • Nov 19 2018 22:49
    rafaelfranca synchronize #30320
Sourav Goswami
@Souravgoswami
But the app generates the SVG, which reads the data using IO.read:
        @@data = if File.readable?(DATA_FILE)
            IO.read(DATA_FILE)
        else
            ''
        end
But it doesn't generate an updated svg
Kaia Leahy
@tenebrousedge
heroku apps are read-only
Sourav Goswami
@Souravgoswami
Nope
Kaia Leahy
@tenebrousedge
yes
Sourav Goswami
@Souravgoswami
I can update data.txt, but IO.read reads the old data somehow...
Well, the rake task is:
desc "Updates data from codetabs"
task :update_data do
    require 'net/https'
    require 'json'

    data_file = File.join(Rails.root, 'data.txt'.freeze).freeze

    begin
        data = Net::HTTP.get(URI("https://api.codetabs.com/v1/loc/?github=souravgoswami/linux_stat".freeze))
        data_minified = data.lines.map!(&:strip).join

        # Check if it's a vaild JSON data
        JSON.parse!(data_minified, max_nexting: 3)
        IO.write(data_file, data_minified)
    rescue Exception
        sleep 1
        puts "Caught Exception: #{$!}"
        retry
    end
end
If I run the heroku console...
Well give me a moment so I can do that now
See, the data is updated now
image.png
Kaia Leahy
@tenebrousedge
don't paste large files here
use a pastebin service
Sourav Goswami
@Souravgoswami
oops wait
image.png
You can see, the genrated svg has still 4876 lines counted, but the data should be up to date by now
I have disable caching, but...
Kaia Leahy
@tenebrousedge
you should probably think about what exactly happens when you start up a dyno. It's probably best to store your JSON in a database rather than persisting your state to a file
Sourav Goswami
@Souravgoswami
Ummm that's interesting...
Kaia Leahy
@tenebrousedge
see also, btw, why you can't use sqlite on heroku https://devcenter.heroku.com/articles/sqlite3
Sourav Goswami
@Souravgoswami
I have deliberately removed database thinking I can update it like that... I don't need a lot of security here TBH
Is there a way to disable the cache that heroku is doing with my file?
Kaia Leahy
@tenebrousedge
no
Sourav Goswami
@Souravgoswami
Got it...
Kaia Leahy
@tenebrousedge
but, for your purposes, you could probably also use like a digitalocean server or something
Sourav Goswami
@Souravgoswami

I have yet another app that calculates system usage of heroku:

https://picalculator.herokuapp.com/system_stats

It works just fine
Kaia Leahy
@tenebrousedge
okay?
Sourav Goswami
@Souravgoswami
Yup, sure...
But you can read stuff from /proc/ or /sys/ on heroku
why not the data.txt?

But you can read stuff from /proc/ or /sys/ on heroku

And show that live with ajax

Kaia Leahy
@tenebrousedge
you can read from data.txt
you can't write to it
or at least, you can't expect that to be persistent
Sourav Goswami
@Souravgoswami
Got it
I think the method just caches it. It generates random coloured svgs, but it doesn't update the data read from data file... So it's mysteriously caching IO.read() only...

you can't write to it

But actually there's my confusion. Cat shows the data is updated.

image.png

Here

IO.read() doesn't read the data, it's kind of cached
I am using a class variable there though...
Kaia Leahy
@tenebrousedge
and you're entirely sure that cat is reading from the same dyno?
Sourav Goswami
@Souravgoswami
Sure
The reason is that the dyno is a container
What does it show? Look at the process start time, it's like 1 hour or so
Because you are running the same container as I am
No matter where you are, my heroku account is free